-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (46 loc) · 1.09 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
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"github.com/kteru/scaffold-echo/api"
"github.com/kteru/scaffold-echo/db/dummy"
)
func main() {
if err := realMain(); err != nil {
fmt.Fprintf(os.Stderr, "[ERR] %v\n", err)
os.Exit(1)
}
os.Exit(0)
}
func realMain() error {
listenHost := "127.0.0.1"
listenPort := 8080
secret := "secret"
flagSet := flag.NewFlagSet(filepath.Base(os.Args[0]), flag.ExitOnError)
flagSet.StringVar(&listenHost, "h", listenHost, "IP Address to listen on")
flagSet.IntVar(&listenPort, "p", listenPort, "Port number to listen on")
flagSet.StringVar(&secret, "s", secret, "Secret to encrypt session")
flagSet.Parse(os.Args[1:])
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lmicroseconds)
hdl, err := dummy.NewHandler()
if err != nil {
return err
}
server, err := api.NewServer(&api.ServerConfig{
ListenHost: listenHost,
ListenPort: listenPort,
Logger: logger,
Secret: []byte(secret),
DBHandler: hdl,
})
if err != nil {
return err
}
if err := server.Serve(); err != nil {
return err
}
return nil
}