feat: go-chi and first routes setup

This commit is contained in:
Florian Sylvain
2023-08-06 05:00:15 +02:00
parent 5b4b5a8622
commit 195c247235
9 changed files with 189 additions and 38 deletions
+20 -2
View File
@@ -2,12 +2,30 @@ package main
import (
"GohCMS2/api"
"encoding/json"
"fmt"
"github.com/go-chi/chi/v5"
"github.com/go-chi/httplog"
"net/http"
)
func main() {
api.InitContainer()
fmt.Println(api.CreateArticle("Title", "Content"))
fmt.Println(api.GetArticle(1))
r := chi.NewRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
msg, _ := json.Marshal(map[string]string{"message": "Hello World"})
_, _ = w.Write(msg)
})
r.Mount("/article", api.NewArticleRouter())
apiRouter := chi.NewRouter()
apiRouter.Use(httplog.RequestLogger(httplog.NewLogger("GohCMS2")))
apiRouter.Mount("/v1", r)
fmt.Println("Server starting on port 8080")
err := http.ListenAndServe(":8080", apiRouter)
if err != nil {
panic(err)
}
}