This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmain.go
85 lines (70 loc) · 1.57 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
package main
import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/lunny/log"
"github.com/go-xorm/dbweb/models"
"github.com/go-xorm/dbweb/modules/setting"
)
var (
isDebug *bool = flag.Bool("debug", false, "enable debug mode")
port *int = flag.Int("port", 8989, "listen port")
https *bool = flag.Bool("https", false, "enable https")
isHelp *bool = flag.Bool("help", false, "show help")
homeDir *string = flag.String("home", defaultHome, "set the home dir which contain templates,static,langs,certs")
)
var (
defaultHome string
Version = "0.2.0329"
Tags string
)
func help() {
fmt.Println("dbweb version", Version)
fmt.Println()
flag.PrintDefaults()
}
func exePath() (string, error) {
file, err := exec.LookPath(os.Args[0])
if err != nil {
return "", err
}
return filepath.Abs(file)
}
func main() {
flag.Parse()
setting.StaticRootPath = *homeDir
if setting.StaticRootPath == "" {
ePath, err := exePath()
if err != nil {
panic(err)
}
setting.StaticRootPath = filepath.Dir(ePath)
}
log.Info("dbweb version", Version)
log.Info("home dir is", setting.StaticRootPath)
if len(Tags) > 0 {
log.Info("build with", Tags)
}
if *isHelp {
help()
return
}
err := models.Init()
if err != nil {
panic(err)
}
err = InitI18n([]string{"en-US", "zh-CN"})
if err != nil {
panic(err)
}
t := InitTango(*isDebug)
listen := fmt.Sprintf(":%d", *port)
if *https {
t.RunTLS(filepath.Join(setting.StaticRootPath, "cert.pem"), filepath.Join(setting.StaticRootPath, "key.pem"), listen)
} else {
t.Run(listen)
}
}