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) } defer db.Close() 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") 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"}`)) }) log.Fatal(http.ListenAndServe("0.0.0.0:8080", mux)) }