From d1b930a4a98bb4b05dc61be7d0c478c01ce2ead2 Mon Sep 17 00:00:00 2001 From: kenneth Date: Mon, 25 Dec 2023 11:51:41 +0800 Subject: [PATCH] optimize --- main.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 3910d75..1c514e9 100644 --- a/main.go +++ b/main.go @@ -27,15 +27,6 @@ func main() { } } - router := mux.NewRouter() - router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - w.Write([]byte("Wecome to the URL Shortener API")) - }).Methods(http.MethodGet) - - router.HandleFunc("/create-short-url", handler.CreateShortUrl).Methods(http.MethodPost) - router.HandleFunc("/{shortUrl}", handler.HandleShortUrlRedirect).Methods(http.MethodGet) - addr := os.Getenv("REDIS_ADDR") password := os.Getenv("REDIS_PASSWORD") db, err := strconv.Atoi(os.Getenv("REDIS_DB")) @@ -44,6 +35,14 @@ func main() { } store.InitializeStore(addr, password, db) + router := mux.NewRouter() + router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("Wecome to the URL Shortener API")) + }).Methods(http.MethodGet) + router.HandleFunc("/create-short-url", handler.CreateShortUrl).Methods(http.MethodPost) + router.HandleFunc("/{shortUrl}", handler.HandleShortUrlRedirect).Methods(http.MethodGet) + srv := &http.Server{ Addr: "0.0.0.0:" + os.Getenv("SERVER_PORT"), Handler: router,