mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
feat: go-chi and first routes setup
This commit is contained in:
+20
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user