-
Notifications
You must be signed in to change notification settings - Fork 386
/
main.go
56 lines (45 loc) · 949 Bytes
/
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
package main
import (
"log"
"os"
"time"
"github.com/TechBowl-japan/go-stations/db"
"github.com/TechBowl-japan/go-stations/handler/router"
)
func main() {
err := realMain()
if err != nil {
log.Fatalln("main: failed to exit successfully, err =", err)
}
}
func realMain() error {
// config values
const (
defaultPort = ":8080"
defaultDBPath = ".sqlite3/todo.db"
)
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
dbPath := os.Getenv("DB_PATH")
if dbPath == "" {
dbPath = defaultDBPath
}
// set time zone
var err error
time.Local, err = time.LoadLocation("Asia/Tokyo")
if err != nil {
return err
}
// set up sqlite3
todoDB, err := db.NewDB(dbPath)
if err != nil {
return err
}
defer todoDB.Close()
// NOTE: 新しいエンドポイントの登録はrouter.NewRouterの内部で行うようにする
mux := router.NewRouter(todoDB)
// TODO: サーバーをlistenする
return nil
}