/
app.go
41 lines (34 loc) · 1 KB
/
app.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
package main
import (
"fmt"
"log"
"github.com/fvbock/endless"
flag "github.com/spf13/pflag"
)
const (
defaultConfigFile = "scg.yaml"
defaultGoogleAPIKey = ""
defaultLineBotAccessToken = ""
defaultLineBotSecret = ""
defaultServerAddress = "0.0.0.0"
defaultServergPort = 8080
)
func init() {
flag.String("google.apikey", "", "Google API key")
flag.String("linebot.accesstoken", "", "Access token of Line Bot")
flag.String("linebot.secret", "", "Secret of Line Bot")
flag.String("server.address", defaultServerAddress, "Listening address")
flag.Int("server.port", defaultServergPort, "Listening port")
}
func main() {
const appName = "scg"
log.Println("Load configuration")
config := setupConfig(appName)
address := config.GetString("server.address")
port := config.GetInt("server.port")
listen := fmt.Sprintf("%v:%v\n", address, port)
router := setupRouter(config)
log.Println(fmt.Sprintf("Listen %v\n", listen))
router.Run()
endless.ListenAndServe(listen, router)
}