This commit is contained in:
kenneth 2023-12-25 11:51:41 +08:00
parent 2119199368
commit d1b930a4a9

17
main.go
View File

@ -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") addr := os.Getenv("REDIS_ADDR")
password := os.Getenv("REDIS_PASSWORD") password := os.Getenv("REDIS_PASSWORD")
db, err := strconv.Atoi(os.Getenv("REDIS_DB")) db, err := strconv.Atoi(os.Getenv("REDIS_DB"))
@ -44,6 +35,14 @@ func main() {
} }
store.InitializeStore(addr, password, db) 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{ srv := &http.Server{
Addr: "0.0.0.0:" + os.Getenv("SERVER_PORT"), Addr: "0.0.0.0:" + os.Getenv("SERVER_PORT"),
Handler: router, Handler: router,