ignore options.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Midou36O 2022-09-17 22:18:21 +01:00
parent 977136d9c2
commit 41209f3ee3
Signed by: midou
GPG Key ID: 08063D5407090BC2
3 changed files with 25 additions and 1 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
data/config.toml data/config.toml
data/options.json

View File

@ -1,9 +1,12 @@
package api package api
import ( import (
"io/ioutil"
"log" "log"
"net/http" "net/http"
"os"
"github.com/goccy/go-json"
"github.com/kataras/hcaptcha" "github.com/kataras/hcaptcha"
"fmt" "fmt"
@ -22,6 +25,26 @@ var (
client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */ client = hcaptcha.New(secretKey) /* See `Client.FailureHandler` too. */
) )
func FormCheck() {
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["Form"]
if res == "true" {
Form()
} else {
log.Println("Forms disabled")
http.HandleFunc("/api/form", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Disabled")
})
}
}
func Form() { func Form() {
http.HandleFunc("/api/form", client.HandlerFunc(theActualFormCode)) http.HandleFunc("/api/form", client.HandlerFunc(theActualFormCode))
} }

View File

@ -47,7 +47,7 @@ func main() {
http.ServeFile(w, r, "static/announcements.html") http.ServeFile(w, r, "static/announcements.html")
}) })
api.Settings() api.Settings()
api.Form() api.FormCheck()
api.CheckAnn() 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))