forked from Ilyes512/satis-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (71 loc) · 1.62 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
79
80
81
82
83
84
85
86
87
package main
import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/Ilyes512/satis-go/satis"
yaml "gopkg.in/yaml.v2"
)
// Config struct used by satis-go
type Config struct {
Bind string
Dbpath string
RepoUIPath string
AdminUIPath string
Reponame string
Repohost string
Username string
APIToken string
}
func getConfig(path string) (Config, error) {
config := Config{}
if path == "" {
return config, errors.New("-config flag needs to be set")
}
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() {
cfgPath := flag.String("config", "", "Path to Config File")
generateSatisWeb := flag.Bool("generate", false, "Generate Satis Web")
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,
Username: cfg.Username,
APIToken: cfg.APIToken,
}
log.Println("Satis is starting on " + cfg.Bind)
// Start Server
if err := s.Run(*generateSatisWeb); err != nil {
log.Fatal(err)
}
}