-
Notifications
You must be signed in to change notification settings - Fork 100
/
main.go
38 lines (34 loc) · 910 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
package main
import (
"log"
"os"
"github.com/jpillora/opts"
"github.com/jpillora/webproc/agent"
)
var version = "0.0.0-src"
func main() {
//prepare config!
c := agent.Config{}
//parse cli
opts.New(&c).Name("webproc").PkgRepo().Version(version).Parse()
//if args contains has one non-executable file, treat as webproc file
//TODO: allow cli to override config file
args := c.ProgramArgs
if len(args) == 1 {
path := args[0]
if info, err := os.Stat(path); err == nil && info.Mode()&0111 == 0 {
c.ProgramArgs = nil
if err := agent.LoadConfig(path, &c); err != nil {
log.Fatalf("[webproc] load config error: %s", err)
}
}
}
//validate and apply defaults
if err := agent.ValidateConfig(&c); err != nil {
log.Fatalf("[webproc] load config error: %s", err)
}
//server listener
if err := agent.Run(version, c); err != nil {
log.Fatalf("[webproc] agent error: %s", err)
}
}