-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
75 lines (65 loc) · 1.72 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
package main
import (
"fmt"
"os"
"time"
"github.com/darklab8/fl-darkstat/darkstat/builder"
"github.com/darklab8/fl-darkstat/darkstat/linker"
"github.com/darklab8/fl-darkstat/darkstat/settings"
"github.com/darklab8/fl-darkstat/darkstat/settings/logus"
"github.com/darklab8/fl-darkstat/darkstat/web"
"github.com/darklab8/go-typelog/typelog"
"github.com/darklab8/go-utils/utils/timeit"
)
type Action string
func (a Action) ToStr() string { return string(a) }
const (
Build Action = "build"
Web Action = "web"
Version Action = "version"
)
func main() {
fmt.Println("freelancer folder=", settings.Env.FreelancerFolder, settings.Env)
defer func() {
if r := recover(); r != nil {
logus.Log.Error("Program crashed. Sleeping 10 seconds before exit", typelog.Any("recover", r))
if !settings.Env.IsDevEnv {
fmt.Println("going to sleeping")
time.Sleep(10 * time.Second)
}
panic(r)
}
}()
var action string
argsWithoutProg := os.Args[1:]
if len(argsWithoutProg) == 1 {
action = argsWithoutProg[0]
}
fmt.Println("act:", action)
web := func() {
var fs *builder.Filesystem
timeit.NewTimerMF("total time for web web := func()",
func(m *timeit.Timer) {
var linked_build *builder.Builder
timeit.NewTimerMF("linking stuff linker.NewLinker().Link()",
func(m *timeit.Timer) {
linked_build = linker.NewLinker().Link()
})
timeit.NewTimerMF("building stuff linked_build.BuildAll()",
func(m *timeit.Timer) {
fs = linked_build.BuildAll()
})
})
web.NewWeb(fs).Serve()
}
switch Action(action) {
case Build:
linker.NewLinker().Link().BuildAll().RenderToLocal()
case Web:
web()
case Version:
fmt.Println("version=", settings.Env.AppVersion)
default:
web()
}
}