This repository has been archived on 2022-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
Segfautils/main.go
Odyssey346 16983594f4 Gone with Rng, in comes a WIP form
Signed-off-by: Odyssey346 <odyssey346@disroot.org>
2022-07-26 12:57:30 +02:00

38 lines
1000 B
Go

package main
import (
"net/http"
"html/template"
"io"
"log"
"github.com/ProjectSegfault/segfautilities/otherthings"
"os"
"github.com/ProjectSegfault/segfautilities/api"
)
type StaticThingy struct {
Port string
}
var pieceof string
var shit bool
func main() {
log.Println("[Segfautilities] Starting")
otherthings.CheckEnv()
log.Println("[HTTP] Starting server")
pieceof := os.Getenv("SEGFAUTILITIES_PORT") // I hate this
tmpl := template.Must(template.ParseFiles("static/index.html"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := StaticThingy{
Port: pieceof,
}
tmpl.Execute(w, data)
})
http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "welcome to hell")
})
api.Form()
log.Println("[HTTP] HTTP server is now running at " + pieceof + "!")
log.Println(http.ListenAndServe(":" + pieceof, nil))
}