-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (48 loc) · 1.39 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
package main
//go:generate npm install
//go:generate gulp scripts
//go:generate go-bindata -ignore=\\.DS_Store -ignore=\\.#.* -o asset/asset.go -pkg asset -prefix front front/...
import (
"io/ioutil"
"os"
"time"
kingpin "github.com/alecthomas/kingpin/v2"
"github.com/sirupsen/logrus"
"github.com/skratchdot/open-golang/open"
"github.com/wacul/ichigo/proxy"
yaml "gopkg.in/yaml.v2"
)
const (
// ConfigFile : 設定ファイル名
ConfigFile = "ichigo.yaml"
)
var version = "snapshot"
func main() {
app := kingpin.New("Ichigo", "Reverse proxy for development")
app.Version(version)
configFile := app.Flag("config", "A file contains configurations (YAML)").Short('c').Default(ConfigFile).ExistingFile()
dontOpen := app.Flag("no-browser", "Supresss to open browser automatically").Short('n').Default("false").Bool()
_, err := app.Parse(os.Args[1:])
if err != nil {
logrus.Fatalln(err.Error())
}
logrus.SetLevel(logrus.DebugLevel)
confBytes, err := ioutil.ReadFile(*configFile)
if err != nil {
logrus.Fatalln(err.Error())
}
var handler proxy.Handler
err = yaml.Unmarshal(confBytes, &handler)
if err != nil {
logrus.Fatalln(err.Error())
}
if dontOpen == nil || !*dontOpen {
go func() {
time.Sleep(1 * time.Second)
if err := open.Start("http://localhost" + handler.Addr + handler.StartPath); err != nil {
panic(err)
}
}()
}
logrus.Println(handler.ListenAndServe())
}