-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
64 lines (52 loc) · 1.61 KB
/
config.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
/*
WebChunk, web server for block game maps
Copyright (C) 2022 Maxim Zhuchkov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Contact me via mail: [email protected] or Discord: MaX#6717
*/
package main
import (
"net/http"
"os"
"github.com/maxsupermanhd/lac"
)
var cfg = lac.NewConf()
//lint:ignore U1000 for future use
func saveConfig() error {
path := os.Getenv("WEBCHUNK_CONFIG")
if path == "" {
path = "config.json"
}
return cfg.ToFileIndentJSON(path, 0644)
}
func loadConfig() error {
path := os.Getenv("WEBCHUNK_CONFIG")
if path == "" {
path = "config.json"
}
return cfg.SetFromFileJSON(path)
}
func cfgHandler(w http.ResponseWriter, r *http.Request) {
b, err := cfg.ToBytesIndentJSON()
if err != nil {
templateRespond("plainmsg", w, r, map[string]any{"msg": err.Error()})
return
}
templateRespond("cfg", w, r, map[string]any{"cfg": string(b)})
}
func apiSaveConfig(_ http.ResponseWriter, _ *http.Request) (int, string) {
err := saveConfig()
if err != nil {
return 500, err.Error()
}
return 200, ""
}