Created
September 25, 2022 11:48
-
-
Save percybolmer/aa8705ea80ec104bb75eaae0dfc31879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func main() { | |
// Create a root ctx and a CancelFunc which can be used to cancel retentionMap goroutine | |
rootCtx := context.Background() | |
ctx, cancel := context.WithCancel(rootCtx) | |
defer cancel() | |
setupAPI(ctx) | |
// Serve on port :8080, fudge yeah hardcoded port | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} | |
// setupAPI will start all Routes and their Handlers | |
func setupAPI(ctx context.Context) { | |
// Create a Manager instance used to handle WebSocket Connections | |
manager := NewManager(ctx) | |
// Serve the ./frontend directory at Route / | |
http.Handle("/", http.FileServer(http.Dir("./frontend"))) | |
http.HandleFunc("/login", manager.loginHandler) | |
http.HandleFunc("/ws", manager.serveWS) | |
http.HandleFunc("/debug", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, len(manager.clients)) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment