-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
72 lines (62 loc) · 1.83 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
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/goutils/utils/time_measure"
)
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.GetFreelancerFolder())
defer func() {
if r := recover(); r != nil {
logus.Log.Error("Program crashed. Sleeping 10 seconds before exit", typelog.Any("recover", r))
if !(os.Getenv("DEV") == "true") {
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
time_measure.TimeMeasure(func(m *time_measure.TimeMeasurer) {
var linked_build *builder.Builder
time_measure.TimeMeasure(func(m *time_measure.TimeMeasurer) {
linked_build = linker.NewLinker().Link()
}, time_measure.WithMsg("linking stuff linker.NewLinker().Link()"))
time_measure.TimeMeasure(func(m *time_measure.TimeMeasurer) {
fs = linked_build.BuildAll()
}, time_measure.WithMsg("building stuff linked_build.BuildAll()"))
}, time_measure.WithMsg("total time for web web := func()"))
web.NewWeb(fs).Serve()
}
switch Action(action) {
case Build:
linker.NewLinker().Link().BuildAll().RenderToLocal()
case Web:
web()
case Version:
fmt.Println("version=", settings.GetVersion())
default:
web()
}
}