forked from ostrost/ostent
/
main.dev.go
86 lines (75 loc) · 1.81 KB
/
main.dev.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
86
// +build !bin
package main
import (
"flag"
"go/build"
"log"
"net/http/pprof"
"os"
"os/signal"
"syscall"
"github.com/ostrost/ostent/commands"
_ "github.com/ostrost/ostent/commands/ostent"
"github.com/ostrost/ostent/ostent"
"github.com/ostrost/ostent/share/assets"
"github.com/ostrost/ostent/share/templates"
)
var (
// AssetInfoFunc is for wrapping bindata's AssetInfo func.
AssetInfoFunc = ostent.AssetInfoFunc
// AssetReadFunc is for wrapping bindata's Asset func.
AssetReadFunc = ostent.AssetReadFunc
)
func main() {
flag.Usage = commands.UsageFunc(flag.CommandLine)
webserver := commands.NewWebserver(8050).AddCommandLine()
flag.Parse()
errd, atexit := commands.ArgCommands()
defer atexit()
if errd {
return
}
// RootDir's of packages having dev bindata
for _, binPkg := range []struct {
pkgPath string
RootDir func(string)
}{
{"github.com/ostrost/ostent/share/assets", assets.RootDir},
{"github.com/ostrost/ostent/share/templates", templates.RootDir},
} {
pkg, err := build.Import(binPkg.pkgPath, "", build.FindOnly)
if err != nil {
log.Fatal(err)
}
binPkg.RootDir(pkg.Dir)
}
ostent.RunBackground(PeriodFlag)
templatesLoaded := make(chan struct{}, 1)
go templates.InitTemplates(templatesLoaded) // NB after templates.RootDir
listen := webserver.NetListen()
errch := make(chan error, 2)
go func(ch chan<- error) {
<-templatesLoaded
ch <- Serve(listen, false, ostent.Muxmap{
"/debug/pprof/{name}": pprof.Index,
"/debug/pprof/cmdline": pprof.Cmdline,
"/debug/pprof/profile": pprof.Profile,
"/debug/pprof/symbol": pprof.Symbol,
})
}(errch)
sigch := make(chan os.Signal, 2)
signal.Notify(sigch,
syscall.SIGINT,
syscall.SIGQUIT,
syscall.SIGTERM,
)
wait:
for {
select {
case _ = <-sigch:
break wait
case err := <-errch:
log.Fatal(err)
}
}
}