the shrimplest admin api you've ever seen

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-04-16 22:58:39 +01:00
parent 1cbcece3d2
commit c5a2491627
5 changed files with 266 additions and 12 deletions

43
api/v1/admin/admin.go Normal file
View file

@ -0,0 +1,43 @@
package admin
import (
"fmt"
"html/template"
"io"
"net/http"
)
type (
State struct {
Token string
}
)
func CreateState() *State {
return &State{
Token: "you are the WINRAR!!",
}
}
func HandleLogin(writer http.ResponseWriter, req *http.Request, root *template.Template) int {
if req.Method != "POST" {
return 404;
}
body, err := io.ReadAll(req.Body)
if err != nil {
fmt.Printf("failed to parse request body!\n");
return 500;
}
if string(body) != "super epic mega gaming password" {
return 400;
}
state := CreateState();
writer.WriteHeader(200);
writer.Write([]byte(state.Token))
return 200;
}