Skip to content

Commit

Permalink
add router
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed Apr 26, 2024
1 parent b440e63 commit 697e58a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 15 additions & 0 deletions internal/routers/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package routers

import (
"github.com/go-chi/chi/v5"
"net/http"
)

func GetRouter() *chi.Mux {
router := chi.NewRouter()
router.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("milwad"))
})

return router
}
9 changes: 3 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"do-it/internal/routers"
"fmt"
"github.com/go-chi/chi/v5"
"github.com/joho/godotenv"
"log"
"net/http"
Expand All @@ -20,14 +20,11 @@ func main() {
port := fmt.Sprintf(":%v", os.Getenv("APP_PORT"))

// Router
router := chi.NewRouter()
router.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("milwad"))
})
r := routers.GetRouter()

// Serve application
fmt.Printf("Your application run on %v", port)
err = http.ListenAndServe(port, router)
err = http.ListenAndServe(port, r)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 697e58a

Please sign in to comment.