-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (74 loc) · 2.38 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
package main
import (
"fmt"
"os"
"github.com/privacy-scaling-explorations/maci-coordinator/src"
)
func main() {
// These functions demonstrate two separate checks to detect if the code is being
// run inside a docker container in debug mode, or production mode!
//
// Note: Valid only for docker containers generated using the Makefile command
firstCheck()
secondCheck()
prover := src.Prover{
ProcessMessagesCircuit: src.Circuit{
Result: src.Result{},
Status: src.WaitingForRequest,
},
TallyVotesCircuit: src.Circuit{
Result: src.Result{},
Status: src.WaitingForRequest,
},
}
r := src.NewRouter(prover)
r.LoadHTMLFiles("demo/api_demo.html")
// listen and serve on localhost:8080
if err := r.Run(); err != nil {
panic("Failed to run API server")
}
}
func firstCheck() bool {
/*
* The `debug_mode` environment variable exists only in debug builds, likewise,
* `production_mode` variable exists selectively in production builds - use the
* existence of these variables to detect container build type (and not values)
*
* Exactly one of these - `production_mode` or `debug_mode` - is **guaranteed** to
* exist for docker builds generated using the Makefile commands!
*/
if _, ok := os.LookupEnv("production_mode"); ok {
fmt.Println("(Check 01): Running in `production` mode!")
return true
} else if _, ok := os.LookupEnv("debug_mode"); ok {
// Could also use a simple `else` statement (above) for docker builds!
fmt.Println("(Check 01): Running in `debug` mode!")
return true
} else {
fmt.Println("\nP.S. Try running a build generated with the Makefile :)")
return false
}
}
func secondCheck() bool {
/*
* There's also a central `__BUILD_MODE__` variable for a dirty checks -- guaranteed
* to exist for docker containers generated by the Makefile commands!
* The variable will have a value of `production` or `debug` (no capitalization)
*
* Note: Relates to docker builds generated using the Makefile
*/
value := os.Getenv("__BUILD_MODE__")
// Yes, this if/else could have been written better
switch value {
case "production":
fmt.Println("(Check 02): Running in `production` mode!")
return true
case "debug":
fmt.Println("(Check 02): Running in `debug` mode!")
return true
default:
// Flow ends up here for non-docker builds, or docker builds generated directly
fmt.Println("Non-makefile build detected :(")
return false
}
}