sticky sessions
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 27s

This commit is contained in:
matst80
2024-11-09 01:26:46 +01:00
parent 0c58b3fdbf
commit 82dcd7871c
3 changed files with 17 additions and 9 deletions

16
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"net/http"
"os"
@@ -110,18 +111,21 @@ func main() {
storage: storage,
}
rpcHandler, err := NewGrainHandler(app.pool, "localhost:1337")
syncedPool := NewSyncedPool(app.pool)
rpcHandler, err := NewGrainHandler(app.pool, ":1337")
if err != nil {
log.Fatalf("Error creating handler: %v\n", err)
}
go rpcHandler.Serve()
remotePool := NewRemoteGrainPool("localhost:1337")
remoteServer := NewPoolServer(remotePool)
localServer := NewPoolServer(app.pool)
syncedServer := NewPoolServer(syncedPool)
mux := http.NewServeMux()
mux.Handle("/remote/", http.StripPrefix("/remote", remoteServer.Serve()))
mux.Handle("/local/", http.StripPrefix("/local", localServer.Serve()))
mux.Handle("/api/", http.StripPrefix("/api", syncedServer.Serve()))
mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) {
remotePool := NewRemoteGrainPool(fmt.Sprintf("%s:1337", r.PathValue("host")))
syncedPool.AddRemote(remotePool)
})
mux.HandleFunc("GET /save", app.HandleSave)
http.ListenAndServe(":8080", mux)