Skip to content

Commit 8145fe7

Browse files
committed
[doc] Fix golint issues in more files
1 parent b7f6a94 commit 8145fe7

File tree

4 files changed

+135
-76
lines changed

4 files changed

+135
-76
lines changed

internal/app/controller/apiServer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func listenForNewEvents(conn *websocket.Conn) {
6161
}
6262

6363
func handleNewEventMessage(b []byte) {
64-
event := RefBoxEvent{}
64+
event := Event{}
6565
err := json.Unmarshal(b, &event)
6666
if err != nil {
6767
log.Println("Could not read event:", string(b), err)

internal/app/controller/publisher.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func initTeamInfo(t *sslproto.SSL_Referee_TeamInfo) {
6363
}
6464

6565
// Publish the state and command
66-
func (p *Publisher) Publish(state *State, command *RefBoxEventCommand) {
66+
func (p *Publisher) Publish(state *State, command *EventCommand) {
6767

6868
if p.conn == nil {
6969
return
@@ -81,7 +81,7 @@ func (p *Publisher) Publish(state *State, command *RefBoxEventCommand) {
8181
}
8282
}
8383

84-
func updateMessage(r *sslproto.SSL_Referee, state *State, command *RefBoxEventCommand) {
84+
func updateMessage(r *sslproto.SSL_Referee, state *State, command *EventCommand) {
8585

8686
*r.PacketTimestamp = uint64(time.Now().UnixNano() / 1000)
8787
*r.Stage = mapStage(state.Stage)
@@ -97,7 +97,7 @@ func updateMessage(r *sslproto.SSL_Referee, state *State, command *RefBoxEventCo
9797
}
9898
}
9999

100-
func mapCommand(c *RefBoxEventCommand) sslproto.SSL_Referee_Command {
100+
func mapCommand(c *EventCommand) sslproto.SSL_Referee_Command {
101101
switch c.Type {
102102
case CommandHalt:
103103
return sslproto.SSL_Referee_HALT
@@ -125,7 +125,7 @@ func mapCommand(c *RefBoxEventCommand) sslproto.SSL_Referee_Command {
125125
return -1
126126
}
127127

128-
func commandByTeam(command *RefBoxEventCommand, blueCommand sslproto.SSL_Referee_Command, yellowCommand sslproto.SSL_Referee_Command) sslproto.SSL_Referee_Command {
128+
func commandByTeam(command *EventCommand, blueCommand sslproto.SSL_Referee_Command, yellowCommand sslproto.SSL_Referee_Command) sslproto.SSL_Referee_Command {
129129
if *command.ForTeam == TeamBlue {
130130
return blueCommand
131131
}

internal/app/controller/refBox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (r *RefBox) Tick() {
132132
}
133133

134134
// Update publishes the state to the UI and the teams
135-
func (r *RefBox) Update(command *RefBoxEventCommand) {
135+
func (r *RefBox) Update(command *EventCommand) {
136136
r.notifyUpdateState <- struct{}{}
137137
refBox.Publisher.Publish(refBox.State, command)
138138
}

internal/app/controller/refBoxEvents.go

Lines changed: 129 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,93 +9,151 @@ import (
99
"time"
1010
)
1111

12+
// CardType is one of yellow or red
1213
type CardType string
13-
type CardOperation string
14-
type RefCommand string
15-
type ModifyType string
16-
type StageOperation string
17-
type TriggerType string
1814

1915
const (
16+
// CardTypeYellow yellow card
2017
CardTypeYellow CardType = "yellow"
21-
CardTypeRed CardType = "red"
18+
// CardTypeRed red card
19+
CardTypeRed CardType = "red"
20+
)
21+
22+
// CardOperation on a card
23+
type CardOperation string
2224

23-
CardOperationAdd CardOperation = "add"
25+
const (
26+
// CardOperationAdd add a card
27+
CardOperationAdd CardOperation = "add"
28+
// CardOperationRevoke revoke a card
2429
CardOperationRevoke CardOperation = "revoke"
30+
// CardOperationModify modify a card
2531
CardOperationModify CardOperation = "modify"
32+
)
2633

27-
CommandHalt RefCommand = "halt"
28-
CommandStop RefCommand = "stop"
29-
CommandNormalStart RefCommand = "normalStart"
30-
CommandForceStart RefCommand = "forceStart"
31-
CommandDirect RefCommand = "direct"
32-
CommandIndirect RefCommand = "indirect"
33-
CommandKickoff RefCommand = "kickoff"
34-
CommandPenalty RefCommand = "penalty"
35-
CommandTimeout RefCommand = "timeout"
34+
// RefCommand is a command to be send to the teams
35+
type RefCommand string
36+
37+
const (
38+
// CommandHalt HALT
39+
CommandHalt RefCommand = "halt"
40+
// CommandStop STOP
41+
CommandStop RefCommand = "stop"
42+
// CommandNormalStart NORMAL_START
43+
CommandNormalStart RefCommand = "normalStart"
44+
// CommandForceStart FORCE_START
45+
CommandForceStart RefCommand = "forceStart"
46+
// CommandDirect DIRECT
47+
CommandDirect RefCommand = "direct"
48+
// CommandIndirect INDIRECT
49+
CommandIndirect RefCommand = "indirect"
50+
// CommandKickoff KICKOFF
51+
CommandKickoff RefCommand = "kickoff"
52+
// CommandPenalty PENALTY
53+
CommandPenalty RefCommand = "penalty"
54+
// CommandTimeout TIMEOUT
55+
CommandTimeout RefCommand = "timeout"
56+
// CommandBallPlacement BALL_PLACEMENT
3657
CommandBallPlacement RefCommand = "ballPlacement"
37-
CommandGoal RefCommand = "goal"
38-
39-
ModifyGoals ModifyType = "goals"
40-
ModifyGoalie ModifyType = "goalie"
41-
ModifyYellowCards ModifyType = "yellowCards"
42-
ModifyYellowCardTime ModifyType = "yellowCardTime"
43-
ModifyRedCards ModifyType = "redCards"
44-
ModifyTimeoutsLeft ModifyType = "timeoutsLeft"
58+
// CommandGoal GOAL
59+
CommandGoal RefCommand = "goal"
60+
)
61+
62+
// ModifyType is something to be modified
63+
type ModifyType string
64+
65+
const (
66+
// ModifyGoals goals
67+
ModifyGoals ModifyType = "goals"
68+
// ModifyGoalie goalie
69+
ModifyGoalie ModifyType = "goalie"
70+
// ModifyYellowCards yellow cards
71+
ModifyYellowCards ModifyType = "yellowCards"
72+
// ModifyYellowCardTime yellow card time
73+
ModifyYellowCardTime ModifyType = "yellowCardTime"
74+
// ModifyRedCards red cards
75+
ModifyRedCards ModifyType = "redCards"
76+
// ModifyTimeoutsLeft number of timeouts left
77+
ModifyTimeoutsLeft ModifyType = "timeoutsLeft"
78+
// ModifyTimeoutTimeLeft timeout time left
4579
ModifyTimeoutTimeLeft ModifyType = "timeoutTimeLeft"
46-
ModifyOnPositiveHalf ModifyType = "onPositiveHalf"
47-
ModifyTeamName ModifyType = "teamName"
80+
// ModifyOnPositiveHalf on positive half?
81+
ModifyOnPositiveHalf ModifyType = "onPositiveHalf"
82+
// ModifyTeamName name of the team
83+
ModifyTeamName ModifyType = "teamName"
84+
)
4885

49-
TriggerResetMatch TriggerType = "resetMatch"
50-
TriggerSwitchColor TriggerType = "switchColor"
51-
TriggerUndo TriggerType = "undo"
86+
// StageOperation to apply on the current stage
87+
type StageOperation string
5288

53-
StageNext StageOperation = "next"
89+
const (
90+
// StageNext next stage
91+
StageNext StageOperation = "next"
92+
// StagePrevious previous stage
5493
StagePrevious StageOperation = "previous"
5594
)
5695

96+
// TriggerType is something that can be triggered
97+
type TriggerType string
98+
99+
const (
100+
// TriggerResetMatch reset match
101+
TriggerResetMatch TriggerType = "resetMatch"
102+
// TriggerSwitchColor switch color
103+
TriggerSwitchColor TriggerType = "switchColor"
104+
// TriggerUndo undo last action
105+
TriggerUndo TriggerType = "undo"
106+
)
107+
108+
// CardModification to apply to a card
57109
type CardModification struct {
58-
CardId int `json:"cardId"`
110+
CardID int `json:"cardId"`
59111
TimeLeft time.Duration `json:"timeLeft"`
60112
}
61113

62-
type RefBoxEventCard struct {
114+
// EventCard is an event that can be applied
115+
type EventCard struct {
63116
ForTeam Team `json:"forTeam"`
64117
Type CardType `json:"cardType"`
65118
Operation CardOperation `json:"operation"`
66119
Modification CardModification `json:"modification"`
67120
}
68121

69-
type RefBoxEventCommand struct {
122+
// EventCommand is an event that can be applied
123+
type EventCommand struct {
70124
ForTeam *Team `json:"forTeam"`
71125
Type RefCommand `json:"commandType"`
72126
}
73127

74-
type RefBoxEventModifyValue struct {
128+
// EventModifyValue is an event that can be applied
129+
type EventModifyValue struct {
75130
Type ModifyType `json:"modifyType"`
76131
ForTeam Team `json:"forTeam"`
77132
ValueStr *string `json:"valueStr"`
78133
ValueInt *int `json:"valueInt"`
79134
ValueBool *bool `json:"valueBool"`
80135
}
81136

82-
type RefBoxEventTrigger struct {
137+
// EventTrigger is an event that can be applied
138+
type EventTrigger struct {
83139
Type TriggerType `json:"triggerType"`
84140
}
85141

86-
type RefBoxEventStage struct {
142+
// EventStage is an event that can be applied
143+
type EventStage struct {
87144
StageOperation StageOperation `json:"stageOperation"`
88145
}
89146

90-
type RefBoxEvent struct {
91-
Card *RefBoxEventCard `json:"card"`
92-
Command *RefBoxEventCommand `json:"command"`
93-
Modify *RefBoxEventModifyValue `json:"modify"`
94-
Stage *RefBoxEventStage `json:"stage"`
95-
Trigger *RefBoxEventTrigger `json:"trigger"`
147+
// Event holds all possible events. Only one at a time can be applied
148+
type Event struct {
149+
Card *EventCard `json:"card"`
150+
Command *EventCommand `json:"command"`
151+
Modify *EventModifyValue `json:"modify"`
152+
Stage *EventStage `json:"stage"`
153+
Trigger *EventTrigger `json:"trigger"`
96154
}
97155

98-
func processEvent(event *RefBoxEvent) error {
156+
func processEvent(event *Event) error {
99157
if event.Card != nil {
100158
return processCard(event.Card)
101159
} else if event.Command != nil {
@@ -107,10 +165,10 @@ func processEvent(event *RefBoxEvent) error {
107165
} else if event.Trigger != nil {
108166
return processTrigger(event.Trigger)
109167
}
110-
return errors.New("Unknown event.")
168+
return errors.New("unknown event")
111169
}
112170

113-
func processTrigger(t *RefBoxEventTrigger) error {
171+
func processTrigger(t *EventTrigger) error {
114172
if t.Type == TriggerResetMatch {
115173
refBox.State = NewState(refBox.Config)
116174
refBox.MatchTimeStart = time.Unix(0, 0)
@@ -127,12 +185,12 @@ func processTrigger(t *RefBoxEventTrigger) error {
127185
return nil
128186
}
129187

130-
func processStage(s *RefBoxEventStage) error {
188+
func processStage(s *EventStage) error {
131189
if refBox.State.GameState != GameStateHalted && refBox.State.GameState != GameStateStopped {
132190
return errors.New("The game state must be halted or stopped to change the stage")
133191
}
134192

135-
index, err := indexOfStage(refBox.State.Stage)
193+
index, err := refBox.State.Stage.index()
136194
if err != nil {
137195
return err
138196
}
@@ -170,17 +228,8 @@ func processStage(s *RefBoxEventStage) error {
170228
return nil
171229
}
172230

173-
func indexOfStage(stage Stage) (int, error) {
174-
for i, v := range Stages {
175-
if v == stage {
176-
return i, nil
177-
}
178-
}
179-
return 0, errors.Errorf("unknown stage: %v", stage)
180-
}
181-
182-
func processModify(m *RefBoxEventModifyValue) error {
183-
if unknownTeam(m.ForTeam) {
231+
func processModify(m *EventModifyValue) error {
232+
if m.ForTeam.Unknown() {
184233
return errors.Errorf("Unknown team: %v", m.ForTeam)
185234
}
186235
teamState := refBox.State.TeamState[m.ForTeam]
@@ -238,7 +287,7 @@ func processModify(m *RefBoxEventModifyValue) error {
238287
return nil
239288
}
240289

241-
func processCommand(c *RefBoxEventCommand) error {
290+
func processCommand(c *EventCommand) error {
242291
switch c.Type {
243292
case CommandHalt:
244293
refBox.State.GameState = GameStateHalted
@@ -287,7 +336,7 @@ func processCommand(c *RefBoxEventCommand) error {
287336
return nil
288337
}
289338

290-
func processCard(card *RefBoxEventCard) error {
339+
func processCard(card *EventCard) error {
291340
if card.ForTeam != TeamYellow && card.ForTeam != TeamBlue {
292341
return errors.Errorf("Unknown team: %v", card.ForTeam)
293342
}
@@ -305,19 +354,19 @@ func processCard(card *RefBoxEventCard) error {
305354
return errors.Errorf("Unknown operation: %v", card.Operation)
306355
}
307356

308-
func modifyCard(card *RefBoxEventCard, teamState *TeamInfo) error {
357+
func modifyCard(card *EventCard, teamState *TeamInfo) error {
309358
if card.Type == CardTypeRed {
310359
return errors.New("Red cards can not be modified")
311360
}
312361
nCardTimes := len(teamState.YellowCardTimes)
313-
if card.Modification.CardId >= nCardTimes {
314-
return errors.Errorf("Invalid card id %v. Only %v card times available", card.Modification.CardId, nCardTimes)
362+
if card.Modification.CardID >= nCardTimes {
363+
return errors.Errorf("Invalid card id %v. Only %v card times available", card.Modification.CardID, nCardTimes)
315364
}
316-
teamState.YellowCardTimes[card.Modification.CardId] = card.Modification.TimeLeft
365+
teamState.YellowCardTimes[card.Modification.CardID] = card.Modification.TimeLeft
317366
return nil
318367
}
319368

320-
func addCard(card *RefBoxEventCard, teamState *TeamInfo) error {
369+
func addCard(card *EventCard, teamState *TeamInfo) error {
321370
if card.Type == CardTypeYellow {
322371
log.Printf("Add yellow card for team %v", card.ForTeam)
323372
teamState.YellowCards++
@@ -329,7 +378,7 @@ func addCard(card *RefBoxEventCard, teamState *TeamInfo) error {
329378
return nil
330379
}
331380

332-
func revokeCard(card *RefBoxEventCard, teamState *TeamInfo) error {
381+
func revokeCard(card *EventCard, teamState *TeamInfo) error {
333382
if card.Type == CardTypeYellow {
334383
if teamState.YellowCards > 0 {
335384
log.Printf("Revoke yellow card for team %v", card.ForTeam)
@@ -353,8 +402,9 @@ func revokeCard(card *RefBoxEventCard, teamState *TeamInfo) error {
353402
return nil
354403
}
355404

356-
func unknownTeam(team Team) bool {
357-
return team != "Yellow" && team != "Blue"
405+
// Unknown returns true if the team is not blue or yellow
406+
func (t Team) Unknown() bool {
407+
return t != "Yellow" && t != "Blue"
358408
}
359409

360410
func strToDuration(s string) (duration time.Duration, err error) {
@@ -389,14 +439,14 @@ func strToDuration(s string) (duration time.Duration, err error) {
389439
return
390440
}
391441

392-
func (c RefBoxEventCommand) String() string {
442+
func (c EventCommand) String() string {
393443
if c.ForTeam == nil {
394444
return string(c.Type)
395445
}
396446
return fmt.Sprintf("%v for %v", c.Type, *c.ForTeam)
397447
}
398448

399-
func (m RefBoxEventModifyValue) String() string {
449+
func (m EventModifyValue) String() string {
400450
str := fmt.Sprintf("%v for %v", m.Type, m.ForTeam)
401451
if m.ValueBool != nil {
402452
if *m.ValueBool {
@@ -413,3 +463,12 @@ func (m RefBoxEventModifyValue) String() string {
413463
}
414464
return str
415465
}
466+
467+
func (s Stage) index() (int, error) {
468+
for i, v := range Stages {
469+
if v == s {
470+
return i, nil
471+
}
472+
}
473+
return 0, errors.Errorf("unknown stage: %v", s)
474+
}

0 commit comments

Comments
 (0)