Adjusted API to v0.0.4

This commit is contained in:
diamondburned (Forefront) 2020-05-20 14:23:44 -07:00
parent fcba545af1
commit 66db865abc
5 changed files with 28 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package mock
import (
"errors"
"math/rand"
"strconv"
"sync/atomic"
"time"
@ -12,6 +13,7 @@ import (
type Channel struct {
session *Service
id uint32
name string
done chan struct{}
send chan Message // ideally this should be another type
@ -23,6 +25,10 @@ var (
_ cchat.ServerMessage = (*Channel)(nil)
)
func (ch *Channel) ID() string {
return strconv.Itoa(int(ch.id))
}
func (ch *Channel) Name() (string, error) {
return ch.name, nil
}
@ -72,7 +78,11 @@ func (ch *Channel) SendMessage(msg cchat.SendableMessage) error {
func generateChannels(s *Service, amount int) []cchat.Server {
var channels = make([]cchat.Server, amount)
for i := range channels {
channels[i] = &Channel{session: s, name: "#" + randomdata.Noun()}
channels[i] = &Channel{
session: s,
id: atomic.AddUint32(&s.lastid, 1),
name: "#" + randomdata.Noun(),
}
}
return channels
}

4
go.mod
View File

@ -3,6 +3,6 @@ module github.com/diamondburned/cchat-mock
go 1.14
require (
github.com/Pallinder/go-randomdata v1.2.0 // indirect
github.com/diamondburned/cchat v0.0.2 // indirect
github.com/Pallinder/go-randomdata v1.2.0
github.com/diamondburned/cchat v0.0.4
)

4
go.sum
View File

@ -4,3 +4,7 @@ github.com/diamondburned/cchat v0.0.1 h1:ABoYPQ+uhsUopdDDw62jFsEjvsz6dlOttL/xIeU
github.com/diamondburned/cchat v0.0.1/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08=
github.com/diamondburned/cchat v0.0.2 h1:WfynDllfkUeTWKGwNWz5AWEXL88rl+6FO/uSfMdNiss=
github.com/diamondburned/cchat v0.0.2/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08=
github.com/diamondburned/cchat v0.0.3 h1:XpuRcs+RhdFOGfsD3uCporEhVo8HQ5s95Qlj+4U2Xno=
github.com/diamondburned/cchat v0.0.3/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08=
github.com/diamondburned/cchat v0.0.4 h1:RSuAX3T4PsPOPBDNZMTt6Mr+g1UZQ3A7vSBf9QPS7uQ=
github.com/diamondburned/cchat v0.0.4/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08=

View File

@ -2,6 +2,8 @@ package mock
import (
"math/rand"
"strconv"
"sync/atomic"
"github.com/Pallinder/go-randomdata"
"github.com/diamondburned/cchat"
@ -9,6 +11,7 @@ import (
type Server struct {
session *Service
id uint32
name string
children []cchat.Server
}
@ -18,6 +21,10 @@ var (
_ cchat.ServerList = (*Server)(nil)
)
func (sv *Server) ID() string {
return strconv.Itoa(int(sv.id))
}
func (sv *Server) Name() (string, error) {
return sv.name, nil
}
@ -36,6 +43,7 @@ func generateServers(s *Service, amount int) []cchat.Server {
for i := range channels {
channels[i] = &Server{
session: s,
id: atomic.AddUint32(&s.lastid, 1),
name: randomdata.Noun(),
children: generateChannels(s, rand.Intn(12)),
}

View File

@ -11,6 +11,7 @@ import (
type Service struct {
username string
servers []cchat.Server
lastid uint32
}
var (
@ -36,8 +37,8 @@ func (s *Service) Authenticate(form []string) error {
return nil
}
func (s *Service) Name() (string, error) {
return "Mock backend", nil
func (s *Service) Name() string {
return "Mock backend"
}
func (s *Service) Servers(container cchat.ServersContainer) error {