-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
93 lines (79 loc) · 1.74 KB
/
main.go
File metadata and controls
93 lines (79 loc) · 1.74 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"docugraphy/api"
"docugraphy/config"
"docugraphy/repository"
"flag"
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
"os"
)
var applicationName = os.Args[0]
const (
installCommand string = "install"
runCommand = "run"
)
func main() {
var err error = nil
/* PASS ARGV */
if len(os.Args) < 2 {
usage()
log.Fatalf("Command missing\n")
}
switch command := os.Args[1]; command {
case installCommand:
handleConfigFile()
log.Println("Installing db schema")
err = install()
case runCommand:
handleConfigFile()
startService()
default:
usage()
log.Fatalf("Unknown command %s\n", command)
}
if nil != err {
log.Fatalf("Problems while processing: %s\n", err.Error())
}
os.Exit(0)
}
func install() error {
err := repository.Connect()
if nil != err {
return err
}
err = repository.Create()
if nil != err {
return err
}
return nil
}
func usage() {
usage := "Usage: " + applicationName + " <command>; " +
fmt.Sprintf("Possible commands: %s, %s", installCommand, runCommand)
log.Println(usage)
}
func handleConfigFile() {
flagSet := flag.NewFlagSet("installFlags", flag.ExitOnError)
configFileLocation := flagSet.String("configFile", "config.json", "Path to json config file")
err := flagSet.Parse(os.Args[2:])
if nil != err {
log.Fatalln("Command line flags processing error: " + err.Error())
}
err = config.Load(*configFileLocation)
if nil != err {
log.Fatalln("Config problem: " + err.Error())
}
}
func startService() {
err := repository.Connect()
if nil != err {
//TODO
}
router := httprouter.New()
router.POST("/source_system", api.AddSourceSystem)
router.GET("/source_systems", api.GetSourceSystems)
log.Fatal(http.ListenAndServe(":8080", router))
}