-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
96 lines (78 loc) · 1.75 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"embed"
"fmt"
"log"
"os"
"path"
"github.com/joho/godotenv"
configuration "github.com/oktalz/present/config"
"github.com/oktalz/present/version"
)
//go:embed ui/static
var dist embed.FS
//go:embed ui/login.html
var loginPage []byte
func main() { //nolint:funlen
_ = godotenv.Load("present.env")
_ = godotenv.Overload(".env")
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
globalENV := path.Join(homeDir, ".present", "present.env")
_ = godotenv.Overload(globalENV)
_ = version.Set()
// f, err := os.Create("cpu.pprof")
// if err != nil {
// log.Fatal(err)
// }
// defer f.Close()
// _ = pprof.StartCPUProfile(f)
// defer pprof.StopCPUProfile()
// f, err := os.Create("mem.pprof")
// if err != nil {
// log.Fatal("could not create memory profile: ", err)
// }
// defer f.Close()
// defer pprof.WriteHeapProfile(f)
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.SetOutput(os.Stderr) // why do packages feel the need to change this in init()? :(
config := configuration.Get()
if config.Version {
fmt.Println("present", version.Version)
fmt.Println("built-from", version.Repo)
if version.CommitDate != "" {
fmt.Println("commit-date", version.CommitDate)
}
os.Exit(0)
}
if config.Tag {
fmt.Println(version.Tag)
os.Exit(0)
}
if config.Update.Latest {
if config.Update.UpdateToLatest() {
os.Exit(0)
}
os.Exit(1)
}
fmt.Println("present", version.Version)
if config.Compress != "" {
config.CompressPresentation()
}
if config.File != "" {
config.DecompressPresentation()
}
if config.GIT != "" {
config.Git()
}
if config.Dir != "" { //nolint:nestif
err := os.Chdir(config.Dir)
if err != nil {
panic(err)
}
}
config.CheckPasswords()
startServer(config)
}