This commit is contained in:
parent
c5b3c2bd98
commit
dc69cc447d
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -17,6 +18,23 @@ var (
|
|||||||
authToken = config.AuthToken()
|
authToken = config.AuthToken()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func CheckAnn() {
|
||||||
|
jsonFile, err := os.Open("./data/options.json")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
defer jsonFile.Close()
|
||||||
|
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||||
|
var result map[string]interface{}
|
||||||
|
json.Unmarshal([]byte(byteValue), &result)
|
||||||
|
res := result["Announcements"]
|
||||||
|
if res == "true" {
|
||||||
|
Announcements()
|
||||||
|
} else {
|
||||||
|
log.Println("Announcements disabled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Announcements() {
|
func Announcements() {
|
||||||
http.HandleFunc("/api/announcements", getAnnouncements)
|
http.HandleFunc("/api/announcements", getAnnouncements)
|
||||||
http.HandleFunc("/api/announcements/post", handleAnnouncements)
|
http.HandleFunc("/api/announcements/post", handleAnnouncements)
|
||||||
|
18
config/optionannounce.go
Normal file
18
config/optionannounce.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func OptForm() string {
|
||||||
|
viper.SetConfigName("config")
|
||||||
|
viper.AddConfigPath("./data")
|
||||||
|
err := viper.ReadInConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error reading config for getting options.form", err.Error())
|
||||||
|
}
|
||||||
|
result := viper.GetString("options.form")
|
||||||
|
return result
|
||||||
|
}
|
18
config/optionform.go
Normal file
18
config/optionform.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func OptAnn() string {
|
||||||
|
viper.SetConfigName("config")
|
||||||
|
viper.AddConfigPath("./data")
|
||||||
|
err := viper.ReadInConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error reading config for getting options.announce", err.Error())
|
||||||
|
}
|
||||||
|
result := viper.GetString("options.announce")
|
||||||
|
return result
|
||||||
|
}
|
@ -5,4 +5,8 @@ auth_token = "YOURAUTHTOKEN"
|
|||||||
|
|
||||||
[hcaptcha]
|
[hcaptcha]
|
||||||
site_key = "YOURSITEKEY"
|
site_key = "YOURSITEKEY"
|
||||||
secret_key = "YOURSECRETKEY"
|
secret_key = "YOURSECRETKEY"
|
||||||
|
|
||||||
|
[options]
|
||||||
|
announce = true
|
||||||
|
form = false
|
1
data/options.json
Executable file
1
data/options.json
Executable file
@ -0,0 +1 @@
|
|||||||
|
{"Announcements":"false","Form":"true"}
|
3
main.go
3
main.go
@ -46,8 +46,9 @@ func main() {
|
|||||||
http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "static/announcements.html")
|
http.ServeFile(w, r, "static/announcements.html")
|
||||||
})
|
})
|
||||||
|
api.Settings()
|
||||||
api.Form()
|
api.Form()
|
||||||
api.Announcements()
|
api.CheckAnn()
|
||||||
log.Println("[HTTP] HTTP server is now running at " + config.Port() + "!")
|
log.Println("[HTTP] HTTP server is now running at " + config.Port() + "!")
|
||||||
log.Println(http.ListenAndServe(":"+config.Port(), nil))
|
log.Println(http.ListenAndServe(":"+config.Port(), nil))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user