From cdbfe64f5c04ac7d19ae14ca9ff826d2990dc065 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Mon, 11 Mar 2024 15:07:00 +1100 Subject: [PATCH] fix: Register type with gob interface --- pkg/spamasaurusrex/main.go | 60 +++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/pkg/spamasaurusrex/main.go b/pkg/spamasaurusrex/main.go index 9cad36a..e1b7373 100644 --- a/pkg/spamasaurusrex/main.go +++ b/pkg/spamasaurusrex/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "encoding/gob" "log" "net/http" "os" @@ -29,6 +30,38 @@ var config = oauth2.Config{ var sessionStore = sessions.NewCookieStore([]byte("xDDBjhYwyndZty3exGNq2ahE8wHRCR4DfdCJCSoWXAYncfWw2UQDH63QcJ9CkrGx")) +func init() { + // Register the oauth2.Token type with gob + gob.Register(&oauth2.Token{}) +} + +func main() { + r := mux.NewRouter() + + r.HandleFunc("/", rootHandler) + r.HandleFunc("/health", healthHandler) + r.HandleFunc("/callback", callbackHandler) + r.HandleFunc("/readiness", readinessHandler) + + srv := &http.Server{ + Handler: r, + Addr: ":8080", + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + } + + // Start Server + go func() { + log.Println("Starting Server") + if err := srv.ListenAndServe(); err != nil { + log.Fatal(err) + } + }() + + // Graceful Shutdown + waitForShutdown(srv) +} + func rootHandler(w http.ResponseWriter, r *http.Request) { session, err := sessionStore.Get(r, "spamasaurusRex") if err != nil { @@ -87,33 +120,6 @@ func readinessHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } -func main() { - r := mux.NewRouter() - - r.HandleFunc("/", rootHandler) - r.HandleFunc("/health", healthHandler) - r.HandleFunc("/callback", callbackHandler) - r.HandleFunc("/readiness", readinessHandler) - - srv := &http.Server{ - Handler: r, - Addr: ":8080", - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, - } - - // Start Server - go func() { - log.Println("Starting Server") - if err := srv.ListenAndServe(); err != nil { - log.Fatal(err) - } - }() - - // Graceful Shutdown - waitForShutdown(srv) -} - func waitForShutdown(srv *http.Server) { interruptChan := make(chan os.Signal, 1) signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)