-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (56 loc) · 1.35 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
package main
import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/golang-rennes/livecoding/config"
"github.com/golang-rennes/livecoding/models"
"github.com/golang-rennes/livecoding/server"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var mainCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version.",
Long: "The version of user-list.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version 0.0.1")
},
}
func init() {
mainCmd.AddCommand(versionCmd)
mainCmd.AddCommand(serverCmd)
flags := mainCmd.Flags()
flags.String("db-host", "localhost", "DB Host")
viper.BindPFlag("db_host", flags.Lookup("db-host"))
}
func main() {
mainCmd.Execute()
}
var serverCmd = &cobra.Command{
Use: "server",
Short: "Run Server",
Run: func(cmd *cobra.Command, args []string) {
// EXPORT USERLIST_DB_HOST=hop
viper.SetEnvPrefix("userlist")
viper.AutomaticEnv()
log.SetLevel(log.DebugLevel)
log.Info("Starting...")
c := &config.ServerConfig{
DBHost: viper.GetString("db_host"),
DBUser: "postgres",
DBPassword: "postgres",
DBName: "postgres",
DBSSLMode: "disable",
HTTPPort: 8080,
AdminList: []string{"fsamin"},
}
models.DBConfig(c)
e := server.New(c)
e.Start()
},
}