-
Notifications
You must be signed in to change notification settings - Fork 3
/
preset.go
54 lines (47 loc) · 1.17 KB
/
preset.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
package main
import (
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
)
const (
defaultPresetPath = "csgo-default.json"
)
var (
// path of the preset file to be served
usePresetPath = defaultPresetPath
// load from fs.FS if true, from disk otherwise
usePresetEmbedFS = true
)
func checkPreset() {
if len(*flags.Preset) > 0 {
if _, err := presets.Open(*flags.Preset); err == nil {
usePresetPath = *flags.Preset
usePresetEmbedFS = true
log.Println("Use built-in preset", usePresetPath)
return
}
if _, err := os.Open(*flags.Preset); err == nil {
usePresetPath = *flags.Preset
usePresetEmbedFS = false
log.Println("Use custom preset", *flags.Preset)
return
}
log.Println("Error: load config preset", *flags.Preset, "failed, try default preset")
}
if _, err := presets.Open(defaultPresetPath); err == nil {
usePresetPath = defaultPresetPath
usePresetEmbedFS = true
log.Println("Use default built-in preset", defaultPresetPath)
} else {
panic("Load default built-in preset failed: " + err.Error())
}
}
func getPreset(c *gin.Context) {
if usePresetEmbedFS {
c.FileFromFS(usePresetPath, http.FS(presets))
return
}
c.File(usePresetPath)
}