Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (45 loc) · 1.89 KB
/
Copy pathmain.go
File metadata and controls
51 lines (45 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// +build !tinygo
package main
import (
"flag"
"fmt"
"net/http"
)
var (
flagVersion = flag.Bool("version", false, "Print version and exit.")
flagServe = flag.Int("serve", 0, "Start a server on the specified port.")
flagDefaultGame = flag.Bool("defaultGame", false, "Default API call. Returns a default game.")
flagParseGame = flag.String("parseGame", "", "ParseGame API call. Requires a JSON string with arguments. Please review spec.")
flagDoAction = flag.String("doAction", "", "DoAction API call. Requires a JSON string with arguments. Please review spec.")
flagParseNotation = flag.String("parseNotation", "", "ParseNotation API call. Requires a JSON string with arguments. Please review spec.")
flagConvertNotation = flag.String("convertNotation", "", "ConvertNotation API call. Requires a JSON string with arguments. Please review spec.")
flagAIMove = flag.String("aiMove", "", "AIMove API call. Requires a JSON string with arguments. Please review spec.")
)
func main() {
flag.Parse()
http.HandleFunc("/parseGame", handleServerParseGame)
http.HandleFunc("/defaultGame", handleServerDefaultGame)
http.HandleFunc("/doAction", handleServerDoAction)
http.HandleFunc("/parseNotation", handleServerParseNotation)
http.HandleFunc("/convertNotation", handleServerConvertNotation)
http.HandleFunc("/aiMove", handleServerAIMove)
switch {
case *flagVersion:
fmt.Println(Version)
return
case *flagServe != 0:
http.ListenAndServe(fmt.Sprintf(":%v", *flagServe), nil)
case *flagDefaultGame:
handleCliDefaultGame()
case *flagParseGame != "":
handleCliParseGame(flagParseGame)
case *flagDoAction != "":
handleCliDoAction(flagDoAction)
case *flagParseNotation != "":
handleCliParseNotation(flagParseNotation)
case *flagConvertNotation != "":
handleCliConvertNotation(flagConvertNotation)
case *flagAIMove != "":
handleCliAIMove(flagAIMove)
}
}