minecraft-server-invites/main.go

57 lines
1.6 KiB
Go
Raw Normal View History

package main
import (
"log"
"net/http"
2022-07-16 02:44:32 +01:00
"github.com/alexedwards/flow"
2022-07-16 02:00:55 +01:00
"whitelistmanager/invite"
2022-07-16 02:16:14 +01:00
"whitelistmanager/minecraft"
"whitelistmanager/store"
"whitelistmanager/transport"
)
func main() {
mux := flow.New()
db, err := store.Open()
if err != nil {
panic(err)
}
2022-07-06 11:39:41 +01:00
defer db.Close()
2022-07-16 02:00:55 +01:00
im := invite.NewManager(db)
2022-07-16 02:16:14 +01:00
mc := minecraft.NewCom()
handlers := transport.New(db, im, mc)
// 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")
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/invite/:id/log", handlers.InviteLog, "GET")
mux.HandleFunc("/api/v1/invite/:id", handlers.DeleteInvite, "DELETE")
mux.HandleFunc("/api/v1/servers", handlers.Servers, "GET", "POST")
mux.HandleFunc("/api/v1/server/:id", handlers.Server, "GET", "DELETE")
mux.HandleFunc("/api/v1/server/:id/invites", handlers.ServerInvites, "GET")
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
r.Header.Set("Content-Type", "application/json")
w.Write([]byte(`{"duck": "quacks"}`))
})
2022-07-16 12:26:36 +01:00
log.Println("Http listening on 0.0.0.0:8080")
log.Fatal(http.ListenAndServe("0.0.0.0:8080", mux))
}