-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
46 lines (36 loc) · 1020 Bytes
/
server.go
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
package main
import (
"flag"
"io/ioutil"
"log"
"net/http"
"gopkg.in/yaml.v2"
"github.com/gorilla/mux"
"github.com/slimjim777/factorysign/service"
)
var settingsFile string
var config service.ConfigSettings
func parseArgs() {
flag.StringVar(&settingsFile, "config", "./settings.yaml", "Path to the config file")
flag.Parse()
}
func readConfig() {
source, err := ioutil.ReadFile(settingsFile)
if err != nil {
log.Fatalf("Error opening the config file: %v", err)
}
err = yaml.Unmarshal(source, &config)
if err != nil {
log.Fatalf("Error parsing the config file: %v", err)
}
}
func main() {
// Parse the command line arguments
parseArgs()
readConfig()
// Start the web service router
router := mux.NewRouter()
router.Handle("/1.0/version", service.Middleware(http.HandlerFunc(service.VersionHandler), &config)).Methods("GET")
router.Handle("/1.0/sign", service.Middleware(http.HandlerFunc(service.SignHandler), &config)).Methods("POST")
log.Fatal(http.ListenAndServe(":8080", router))
}