Initial work
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Midou36O 2022-09-17 21:50:55 +01:00
parent c5b3c2bd98
commit dc69cc447d
Signed by: midou
GPG Key ID: 08063D5407090BC2
6 changed files with 62 additions and 2 deletions

View File

@ -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
View 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
View 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
}

View File

@ -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
View File

@ -0,0 +1 @@
{"Announcements":"false","Form":"true"}

View File

@ -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))
} }