minecraft-server-invites/main.go
Gabriel Simmer 7f1ba6222d Initial commit of MVP API
Includes Microsoft->Minecraft OAuth, simple server adding and invite
generation, and invite acceptance/RCON whitelisting.
2022-07-05 11:10:18 +01:00

44 lines
1.1 KiB
Go

package main
import (
"github.com/alexedwards/flow"
"log"
"net/http"
"whitelistmanager/store"
"whitelistmanager/transport"
)
func main() {
mux := flow.New()
db, err := store.Open()
if err != nil {
panic(err)
}
handlers := transport.New(db)
// Auth endpoints
mux.Group(func(mux *flow.Mux) {
mux.HandleFunc("/api/v1/auth/redirect", handlers.AuthRedirect)
mux.HandleFunc("/api/v1/auth/callback", handlers.AuthCallback)
})
// API endpoints
mux.Group(func(mux *flow.Mux) {
mux.Use(handlers.Cors)
mux.Use(handlers.SessionAuth)
mux.HandleFunc("/api/v1/me", handlers.CurrentUser, "GET")
mux.HandleFunc("/api/v1/invites", handlers.CreateInvite, "POST")
mux.HandleFunc("/api/v1/invite/:id", handlers.GetInvite, "GET", "DELETE")
mux.HandleFunc("/api/v1/invite/:id/accept", handlers.AcceptInvite, "POST")
mux.HandleFunc("/api/v1/servers", handlers.Server, "GET", "POST")
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
r.Header.Set("Content-Type", "application/json")
w.Write([]byte(`{"duck": "quacks"}`))
})
log.Fatal(http.ListenAndServe("0.0.0.0:8080", mux))
}