Updated API to v0.0.8
This commit is contained in:
parent
ddd646da32
commit
45333c71c2
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
session *Service
|
session *Session
|
||||||
id uint32
|
id uint32
|
||||||
name string
|
name string
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
|
@ -90,7 +90,7 @@ func (ch *Channel) CompleteMessage(words []string, i int) []string {
|
||||||
return words
|
return words
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateChannels(s *Service, amount int) []cchat.Server {
|
func generateChannels(s *Session, amount int) []cchat.Server {
|
||||||
var channels = make([]cchat.Server, amount)
|
var channels = make([]cchat.Server, amount)
|
||||||
for i := range channels {
|
for i := range channels {
|
||||||
channels[i] = &Channel{
|
channels[i] = &Channel{
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,5 +4,5 @@ go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Pallinder/go-randomdata v1.2.0
|
github.com/Pallinder/go-randomdata v1.2.0
|
||||||
github.com/diamondburned/cchat v0.0.7
|
github.com/diamondburned/cchat v0.0.8
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -14,4 +14,6 @@ github.com/diamondburned/cchat v0.0.6 h1:lSIgbxT7C8uSka0wqLl/5kc/8rgsYDfZGxaU346
|
||||||
github.com/diamondburned/cchat v0.0.6/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
github.com/diamondburned/cchat v0.0.6/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||||
github.com/diamondburned/cchat v0.0.7 h1:y5zbEoD6L8YHuN/yclqjokF0lPkRj5tYWOuJe0bBldI=
|
github.com/diamondburned/cchat v0.0.7 h1:y5zbEoD6L8YHuN/yclqjokF0lPkRj5tYWOuJe0bBldI=
|
||||||
github.com/diamondburned/cchat v0.0.7/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
github.com/diamondburned/cchat v0.0.7/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||||
|
github.com/diamondburned/cchat v0.0.8 h1:/PmI23SFHJcjYBWNBwQbp36n7fDvDu+NMnQuhM5FM2E=
|
||||||
|
github.com/diamondburned/cchat v0.0.8/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
session *Service
|
session *Session
|
||||||
id uint32
|
id uint32
|
||||||
name string
|
name string
|
||||||
children []cchat.Server
|
children []cchat.Server
|
||||||
|
@ -34,11 +34,11 @@ func (sv *Server) Servers(container cchat.ServersContainer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateServers(s *Service) []cchat.Server {
|
func GenerateServers(s *Session) []cchat.Server {
|
||||||
return generateServers(s, rand.Intn(45))
|
return generateServers(s, rand.Intn(45))
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServers(s *Service, amount int) []cchat.Server {
|
func generateServers(s *Session, amount int) []cchat.Server {
|
||||||
var channels = make([]cchat.Server, amount)
|
var channels = make([]cchat.Server, amount)
|
||||||
for i := range channels {
|
for i := range channels {
|
||||||
channels[i] = &Server{
|
channels[i] = &Server{
|
||||||
|
|
59
service.go
59
service.go
|
@ -6,44 +6,34 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/diamondburned/cchat"
|
"github.com/diamondburned/cchat"
|
||||||
|
"github.com/diamondburned/cchat/services"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
func init() {
|
||||||
username string
|
services.RegisterService(&Service{})
|
||||||
servers []cchat.Server
|
|
||||||
lastid uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Service struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ cchat.Service = (*Service)(nil)
|
_ cchat.Service = (*Service)(nil)
|
||||||
_ cchat.Authenticator = (*Service)(nil)
|
_ cchat.Configurator = (*Service)(nil)
|
||||||
_ cchat.Configurator = (*Service)(nil)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewService() cchat.Service {
|
func (s Service) Name() string {
|
||||||
return &Service{}
|
return "Mock"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) AuthenticateForm() []cchat.AuthenticateEntry {
|
func (s Service) AuthenticateForm() []cchat.AuthenticateEntry {
|
||||||
return []cchat.AuthenticateEntry{{
|
return []cchat.AuthenticateEntry{{
|
||||||
Name: "Username",
|
Name: "Username",
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Authenticate(form []string) error {
|
func (s Service) Authenticate(form []string) (cchat.Session, error) {
|
||||||
s.username = form[0]
|
ses := &Session{username: form[0]}
|
||||||
s.servers = GenerateServers(s)
|
ses.servers = GenerateServers(ses)
|
||||||
|
return ses, nil
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) Name() string {
|
|
||||||
return "Mock backend"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) Servers(container cchat.ServersContainer) error {
|
|
||||||
container.SetServers(s.servers)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -54,7 +44,7 @@ var (
|
||||||
internetMaxLatency = 2500
|
internetMaxLatency = 2500
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) Configuration() (map[string]string, error) {
|
func (s Service) Configuration() (map[string]string, error) {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"internet.canFail": strconv.FormatBool(internetCanFail),
|
"internet.canFail": strconv.FormatBool(internetCanFail),
|
||||||
"internet.minLatency": strconv.Itoa(internetMinLatency),
|
"internet.minLatency": strconv.Itoa(internetMinLatency),
|
||||||
|
@ -62,7 +52,7 @@ func (s *Service) Configuration() (map[string]string, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) SetConfiguration(config map[string]string) error {
|
func (s Service) SetConfiguration(config map[string]string) error {
|
||||||
for _, err := range []error{
|
for _, err := range []error{
|
||||||
// shit code, would not recommend. It's only an ok-ish idea here because
|
// shit code, would not recommend. It's only an ok-ish idea here because
|
||||||
// unmarshalConfig() returns ErrInvalidConfigAtField.
|
// unmarshalConfig() returns ErrInvalidConfigAtField.
|
||||||
|
@ -85,3 +75,20 @@ func unmarshalConfig(config map[string]string, key string, value interface{}) er
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Session struct {
|
||||||
|
username string
|
||||||
|
servers []cchat.Server
|
||||||
|
lastid uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ cchat.Session = (*Session)(nil)
|
||||||
|
|
||||||
|
func (s *Session) Name() (string, error) {
|
||||||
|
return s.username, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Session) Servers(container cchat.ServersContainer) error {
|
||||||
|
container.SetServers(s.servers)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue