minecraft-server-invites/main.go

45 lines
1.1 KiB
Go
Raw Normal View History

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.HandleFunc("/api/v1/invite/:id", handlers.GetInvite, "GET", "DELETE")
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/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))
}