Skip to content

Commit 97547bc

Browse files
committed
feature: Replace config file with cli args
1 parent 81c8b04 commit 97547bc

File tree

6 files changed

+8
-77
lines changed

6 files changed

+8
-77
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ yarn-error.log*
1919
*.njsproj
2020
*.sln
2121
*.sw?
22-
23-
# application specific
24-
/config

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ RUN GOOS=linux GOARCH=amd64 packr build -o ../../release/ssl-status-board_linux_
1717
FROM alpine:3.9
1818
COPY --from=build_go /go/src/github.com/RoboCup-SSL/ssl-status-board/release/ssl-status-board_linux_amd64 /app/ssl-status-board
1919
EXPOSE 8082
20-
WORKDIR "/"
2120
ENTRYPOINT ["/app/ssl-status-board"]
2221
CMD ["/app/ssl-status-board"]

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ You can also use pre-build docker images:
1616
```shell script
1717
docker pull robocupssl/ssl-status-board
1818
docker run -p 8082:8082 robocupssl/ssl-status-board
19-
# if you want to pass in the config file:
20-
docker run -p 8082:8082 -v "$(pwd)/config:/config" ssl-status-board
2119
```
2220

2321
By default, the UI is available at http://localhost:8082

cmd/ssl-status-board/main.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,33 @@ import (
88
"net/http"
99
)
1010

11-
var address = flag.String("address", ":8082", "The address on which the UI and API is served")
12-
var configFile = flag.String("c", "config/board-config.yaml", "The config file to use")
13-
1411
func main() {
12+
var config = board.DefaultConfig()
13+
var address = flag.String("address", config.ListenAddress, "The address on which the UI and API is served")
14+
var refereeAddress = flag.String("refereeAddress", config.RefereeConnection.MulticastAddress, "The multicast address of ssl-game-controller")
1515
flag.Parse()
1616

17-
config := loadConfig(*configFile)
17+
config.ListenAddress = *address
18+
config.RefereeConnection.MulticastAddress = *refereeAddress
1819

1920
refereeBoard := board.NewBoard(config.RefereeConnection)
2021
go refereeBoard.HandleIncomingMessages()
2122
http.HandleFunc(config.RefereeConnection.SubscribePath, refereeBoard.WsHandler)
2223

23-
setupUi()
24+
setupUi(config.ListenAddress)
2425

2526
err := http.ListenAndServe(config.ListenAddress, nil)
2627
if err != nil {
2728
log.Fatal(err)
2829
}
2930
}
3031

31-
func setupUi() {
32+
func setupUi(listenAddress string) {
3233
box := packr.NewBox("../../dist")
3334
http.Handle("/", http.FileServer(box))
3435
if box.Has("index.html") {
35-
log.Printf("UI is available at http://%v", *address)
36+
log.Printf("UI is available at http://%v", listenAddress)
3637
} else {
3738
log.Print("Backend-only version started. Run the UI separately or get a binary that has the UI included")
3839
}
3940
}
40-
41-
// loadConfig loads the config
42-
func loadConfig(configFileName string) board.Config {
43-
cfg, err := board.ReadConfig(configFileName)
44-
if err != nil {
45-
log.Printf("Could not load config: %v", err)
46-
err = cfg.WriteTo(configFileName)
47-
if err != nil {
48-
log.Printf("Failed to write a default config file to %v: %v", configFileName, err)
49-
} else {
50-
log.Println("New default config has been written to", configFileName)
51-
}
52-
}
53-
return cfg
54-
}

docker-compose.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

pkg/board/serverConfig.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ package board
22

33
import (
44
"encoding/json"
5-
"github.com/pkg/errors"
6-
"gopkg.in/yaml.v2"
7-
"io/ioutil"
8-
"log"
9-
"os"
10-
"path/filepath"
115
"time"
126
)
137

@@ -38,40 +32,6 @@ func (c Config) String() string {
3832
return string(str)
3933
}
4034

41-
// ReadConfig reads the server config from a yaml file
42-
func ReadConfig(fileName string) (config Config, err error) {
43-
config = DefaultConfig()
44-
f, err := os.Open(fileName)
45-
if err != nil {
46-
return
47-
}
48-
d, err := ioutil.ReadAll(f)
49-
if err != nil {
50-
log.Fatalln("Could not read config file: ", err)
51-
}
52-
err = yaml.Unmarshal(d, &config)
53-
if err != nil {
54-
log.Fatalln("Could not unmarshal config file: ", err)
55-
}
56-
return
57-
}
58-
59-
// WriteTo writes the config to the specified file
60-
func (c *Config) WriteTo(fileName string) (err error) {
61-
b, err := yaml.Marshal(c)
62-
if err != nil {
63-
err = errors.Wrapf(err, "Could not marshal config %v", c)
64-
return
65-
}
66-
err = os.MkdirAll(filepath.Dir(fileName), 0755)
67-
if err != nil {
68-
err = errors.Wrapf(err, "Could not create directory for config file: %v", fileName)
69-
return
70-
}
71-
err = ioutil.WriteFile(fileName, b, 0600)
72-
return
73-
}
74-
7535
// DefaultConfig creates a config instance filled with default values
7636
func DefaultConfig() Config {
7737
return Config{

0 commit comments

Comments
 (0)