Skip to content

Commit

Permalink
fix static check warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
PapePathe committed Oct 22, 2023
1 parent edbe098 commit 21df94a
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 25 deletions.
4 changes: 1 addition & 3 deletions cmd/training/training.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ func playerTakes(g *game.Game) (takes []constrainedTake) {
_kakfa_messages = append(_kakfa_messages, msg)

fmt.Println(ctk)
for _, t := range _ptk {
ctk.Takes = append(ctk.Takes, t)
}
ctk.Takes = append(ctk.Takes, _ptk...)
_ptk = append(_ptk, *playerObj.Take)
takes = append(takes, ctk)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/websocket/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func main() {
pid, _ := strconv.Atoi(obj["player_id"])
err := g.AddTake(pid, gametake.AllTakesByName[obj["gametake"]])
if err != nil {
log.Printf(err.Error())
log.Println(err.Error())
}
log.Printf(g.GetTake().Name())
log.Println(g.GetTake().Name())

b := game.BroadcastPlayerTakeMsg(obj["gametake"], id, g.AvailableTakes())
for _, p := range g.GetPlayers() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/broker/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

type KafkaPublisher struct {
autocreateTopics bool
writer *kafka.Writer
writer *kafka.Writer
}

func NewPublisher(addr []string, autocreateTopics bool) *KafkaPublisher {
Expand Down
2 changes: 1 addition & 1 deletion pkg/game/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func SetTakeMsg(gt string, pid int) setTake {

type broadcastPlayerTakeMsg struct {
ID messageID `json:"id"`
Take string `json: 'take'`
Take string `json:"take"`
PlayerId int `json:"player_id"`
AvailableTakes []gametake.GameTake `json:"available_takes"`
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"pathe.co/zinx/pkg/player"
)

var CardsAlreadyDispatchedError = errors.New("Cards already dispatched error")
var ErrCardsAlreadyDispatched = errors.New("cards already dispatched error")

type Game struct {
Cartes [32]cards.Card
Expand Down Expand Up @@ -129,7 +129,7 @@ func (g *Game) AvailableTakes() []gametake.GameTake {

func (g *Game) DispatchCards() error {
if g.CartesDistribuees == 32 {
return CardsAlreadyDispatchedError
return ErrCardsAlreadyDispatched
}

for _, p := range g.players {
Expand Down
2 changes: 1 addition & 1 deletion pkg/game/game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestDispatchCardsIsIdempotent(t *testing.T) {
g := setupGame(4)
g.DispatchCards()

assert.Error(t, g.DispatchCards(), CardsAlreadyDispatchedError)
assert.Error(t, g.DispatchCards(), ErrCardsAlreadyDispatched)
}

func TestNewGame(t *testing.T) {
Expand Down
8 changes: 2 additions & 6 deletions pkg/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ func (p *Player) OrderedCardsForTake(t gametake.GameTake) [5]cards.Card {
result := []cards.Card{}

for _, cards := range m {
for _, c := range cards {
result = append(result, c)
}
result = append(result, cards...)
}

return [5]cards.Card(result)

Check failure on line 89 in pkg/player/player.go

View workflow job for this annotation

GitHub Actions / build_baloot

cannot convert result (variable of type []cards.Card) to type [5]cards.Card

Check failure on line 89 in pkg/player/player.go

View workflow job for this annotation

GitHub Actions / build_baloot

cannot convert result (variable of type []cards.Card) to type [5]cards.Card
Expand All @@ -109,9 +107,7 @@ func (p *Player) OrderedCardsForPlaying(t gametake.GameTake) [8]cards.Card {
result := []cards.Card{}

for _, cards := range m {
for _, c := range cards {
result = append(result, c)
}
result = append(result, cards...)
}

return [8]cards.Card(result)

Check failure on line 113 in pkg/player/player.go

View workflow job for this annotation

GitHub Actions / build_baloot

cannot convert result (variable of type []cards.Card) to type [8]cards.Card

Check failure on line 113 in pkg/player/player.go

View workflow job for this annotation

GitHub Actions / build_baloot

cannot convert result (variable of type []cards.Card) to type [8]cards.Card
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/set_player_take_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type PlayerTakeRouter struct {
}

// PlayerTake Handle
func (this *PlayerTakeRouter) Handle(request ziface.IRequest) {
func (ptr *PlayerTakeRouter) Handle(request ziface.IRequest) {
fmt.Println("Call PlayerTakeRouter Handle")
fmt.Println("recv from client: msgId=", request.GetMsgID(), ", data=")

Expand Down
4 changes: 2 additions & 2 deletions utils/globalobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"encoding/json"
"io/ioutil"
"os"

"pathe.co/zinx/ziface"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ Define a global object
var GlobalObject *GlobalObj

func (g *GlobalObj) Reload() error {
data, err := ioutil.ReadFile("conf/zinx.json")
data, err := os.ReadFile("conf/zinx.json")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion znet/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *Connection) StartWriter() {
}
} else {
fmt.Println("msgBuffChan is Closed")
break
return
}

case <-c.ExitBuffChan:
Expand Down
6 changes: 2 additions & 4 deletions znet/msghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ func (mh *MsgHandle) AddRouter(msgId uint32, router ziface.IRouter) {
func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan ziface.IRequest) {
fmt.Println("Worker ID =", workerID, "is started.")
for {
select {
case request := <-taskQueue:
mh.DoMsgHandler(request)
}
request := <-taskQueue
mh.DoMsgHandler(request)
}
}

Expand Down

0 comments on commit 21df94a

Please sign in to comment.