diff --git a/api/http_handler.go b/api/http_handler.go new file mode 100644 index 0000000..c348bdc --- /dev/null +++ b/api/http_handler.go @@ -0,0 +1,27 @@ +package api + +import ( + "fmt" + "log" + "net/http" + + "github.com/gorilla/mux" +) + +func ping(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, "pong") +} + +func BuildRouter(listenAddress string) { + mainRouter := mux.NewRouter() + + mainRouter.HandleFunc("/ping", ping) + + // api_router := base_router.PathPrefix("/api").Subrouter() + + err := http.ListenAndServe(listenAddress, mainRouter) + + if err != nil { + log.Fatalf("Error running the web server %s", err) + } +} diff --git a/go.mod b/go.mod index a251ea0..2113e65 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module echo go 1.22.2 + +require github.com/gorilla/mux v1.8.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7128337 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= diff --git a/main.go b/main.go index 300c7c2..ad14952 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,12 @@ package main -import "fmt" +import ( + "echo/api" + "fmt" +) func main() { fmt.Println("Hello from echo-echo-cho-o") + + api.BuildRouter(":8080") }