/
other.go
48 lines (42 loc) · 928 Bytes
/
other.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
// static.v1
// Copyright (c) 2019, HuguesGuilleus
// BSD 3-Clause License
// Create easily a http.Handler for CSS anf Js files to a Web server.
//
// Usage:
// http.Handle("/style", static.Css("style/"))
// http.Handle("/js", static.Js("js/"))
package static
import (
"log"
"time"
)
var (
// Dev disable the minifing and reduce the sleeping between two updates.
Dev bool = false
// The duration of sleeping in standard mode
SleepDev time.Duration = 200 * time.Millisecond
// The duration of sleeping in developpment mode
SleepProd time.Duration = 10 * time.Minute
)
// Sleep according to the mode.
func sleep() {
if Dev {
time.Sleep(SleepDev)
} else {
time.Sleep(SleepProd)
}
}
// Panic if the error is not nil.
func panicing(err error) {
if err != nil {
panic(err)
}
}
// Reco recover and print the error if no nil.
func reco() {
err := recover()
if err != nil {
log.Println("error:", err)
}
}