Skip to content

Commit cf1db49

Browse files
committed
Restructure Go code according to golang standards
see: https://github.com/golang-standards/project-layout
1 parent 69f0b6a commit cf1db49

File tree

12 files changed

+23
-18
lines changed

12 files changed

+23
-18
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
*.sw*
1111

1212
# ignore binary produced by go build
13-
ssl-game-controller
1413
logs

.idea/runConfigurations/Go_Dev_Server.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package main
22

33
import (
4+
"github.com/g3force/ssl-game-controller/internal/app/ssl-game-controller"
45
"net/http"
56
)
67

7-
var refBox = NewRefBox()
8-
98
func main() {
109

11-
refBox.Run()
10+
ssl_game_controller.RunRefBox()
1211

1312
// serve the static resource of UI (for production use only)
1413
http.Handle("/", http.FileServer(http.Dir(".")))
1514
// serve the bidirectional web socket
16-
http.HandleFunc("/ws", wsHandler)
15+
http.HandleFunc("/ws", ssl_game_controller.WsHandler)
1716
http.ListenAndServe(":8081", nil)
1817
}
File renamed without changes.

refBoxConfig.go renamed to internal/app/ssl-game-controller/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package ssl_game_controller
22

33
import (
44
"gopkg.in/yaml.v2"

refBoxPublisher.go renamed to internal/app/ssl-game-controller/publisher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package ssl_game_controller
22

33
import (
44
"github.com/RoboCup-SSL/ssl-go-tools/sslproto"

refBox.go renamed to internal/app/ssl-game-controller/refBox.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package main
1+
package ssl_game_controller
22

33
import (
44
"encoding/json"
5+
"github.com/g3force/ssl-game-controller/pkg/timer"
56
"io"
67
"log"
78
"os"
@@ -10,11 +11,13 @@ import (
1011

1112
const logDir = "logs"
1213
const lastStateFileName = logDir + "/lastState.json"
13-
const configFileName = "config.yaml"
14+
const configFileName = "config/ssl-game-controller.yaml"
15+
16+
var refBox = NewRefBox()
1417

1518
type RefBox struct {
1619
State *RefBoxState
17-
timer Timer
20+
timer timer.Timer
1821
MatchTimeStart time.Time
1922
notifyUpdateState chan struct{}
2023
StateHistory []RefBoxState
@@ -27,7 +30,7 @@ type RefBox struct {
2730

2831
func NewRefBox() (refBox *RefBox) {
2932
refBox = new(RefBox)
30-
refBox.timer = NewTimer()
33+
refBox.timer = timer.NewTimer()
3134
refBox.notifyUpdateState = make(chan struct{})
3235
refBox.MatchTimeStart = time.Unix(0, 0)
3336
refBox.Config = LoadRefBoxConfig(configFileName)
@@ -37,6 +40,10 @@ func NewRefBox() (refBox *RefBox) {
3740
return
3841
}
3942

43+
func RunRefBox() {
44+
refBox.Run()
45+
}
46+
4047
func (r *RefBox) Run() (err error) {
4148

4249
os.MkdirAll(logDir, os.ModePerm)

refBoxEvents.go renamed to internal/app/ssl-game-controller/refBoxEvents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package ssl_game_controller
22

33
import (
44
"fmt"

server.go renamed to internal/app/ssl-game-controller/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package ssl_game_controller
22

33
import (
44
"encoding/json"
@@ -7,7 +7,7 @@ import (
77
"net/http"
88
)
99

10-
func wsHandler(w http.ResponseWriter, r *http.Request) {
10+
func WsHandler(w http.ResponseWriter, r *http.Request) {
1111
upgrader := websocket.Upgrader{
1212
ReadBufferSize: 1024,
1313
WriteBufferSize: 1024,

refBoxState.go renamed to internal/app/ssl-game-controller/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package ssl_game_controller
22

33
import (
44
"time"

0 commit comments

Comments
 (0)