This commit is contained in:
parent
977136d9c2
commit
41209f3ee3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
data/config.toml
|
data/config.toml
|
||||||
|
data/options.json
|
23
api/form.go
23
api/form.go
@ -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))
|
||||||
}
|
}
|
||||||
|
2
main.go
2
main.go
@ -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))
|
||||||
|
Reference in New Issue
Block a user