forked from benschw/satis-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (63 loc) · 1.34 KB
/
main.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
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
package main
import (
"errors"
"flag"
"fmt"
"github.com/benschw/satis-go/satis"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
)
type Config struct {
Dbpath string
Bind string
RepoUiPath string
AdminUiPath string
Reponame string
Repohost string
}
func getConfig(path string) (Config, error) {
config := Config{}
if _, err := os.Stat(path); err != nil {
return config, errors.New("config path not valid")
}
ymlData, err := ioutil.ReadFile(path)
if err != nil {
return config, err
}
err = yaml.Unmarshal([]byte(ymlData), &config)
return config, err
}
func main() {
// Get Arguments
var cfgPath string
flag.StringVar(&cfgPath, "config", "/opt/satis-go/config.yaml", "Path to Config File")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [arguments] \n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
// Load Config
cfg, err := getConfig(cfgPath)
if err != nil {
log.Fatal(err)
}
// Make Data Dir
if err := os.MkdirAll(cfg.Dbpath, 0744); err != nil {
log.Fatalf("Unable to create path: %v", err)
}
// Configure Server
s := &satis.Server{
DbPath: cfg.Dbpath,
AdminUiPath: cfg.AdminUiPath,
WebPath: cfg.RepoUiPath,
Bind: cfg.Bind,
Name: cfg.Reponame,
Homepage: cfg.Repohost,
}
// Start Server
if err := s.Run(); err != nil {
log.Fatal(err)
}
}