create api skeleton.

This commit is contained in:
Miroslav Šedivý 2020-10-29 22:23:30 +01:00
parent fc3ee13f65
commit 5acd428dee
8 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1 @@
package member

View File

@ -0,0 +1 @@
package room

View File

@ -0,0 +1 @@
package room

View File

@ -0,0 +1 @@
package room

View File

@ -0,0 +1 @@
package room

View File

@ -0,0 +1 @@
package room

40
internal/api/router.go Normal file
View File

@ -0,0 +1,40 @@
package api
import (
"net/http"
"github.com/go-chi/chi"
// "demodesk/neko/internal/api/member"
// "demodesk/neko/internal/api/room"
)
func Mount(router *chi.Mux) {
// all member routes
router.Mount("/member", MemberRoutes())
// all room routes
router.Mount("/room", RoomRoutes())
}
func MemberRoutes() *chi.Mux {
router := chi.NewRouter()
router.Get("/test", func(w http.ResponseWriter, r *http.Request) {
//nolint
w.Write([]byte("hello world"))
})
return router
}
func RoomRoutes() *chi.Mux {
router := chi.NewRouter()
router.Get("/test", func(w http.ResponseWriter, r *http.Request) {
//nolint
w.Write([]byte("hello world"))
})
return router
}

View File

@ -11,6 +11,7 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"demodesk/neko/internal/api"
"demodesk/neko/internal/http/endpoint" "demodesk/neko/internal/http/endpoint"
"demodesk/neko/internal/types" "demodesk/neko/internal/types"
"demodesk/neko/internal/types/config" "demodesk/neko/internal/types/config"
@ -31,6 +32,9 @@ func New(conf *config.Server, webSocketHandler types.WebSocketHandler) *Server {
router.Use(middleware.RequestID) // Create a request ID for each request router.Use(middleware.RequestID) // Create a request ID for each request
router.Use(Logger) // Log API request calls using custom logger function router.Use(Logger) // Log API request calls using custom logger function
// Mount REST API
api.Mount(router)
router.Get("/ws", func(w http.ResponseWriter, r *http.Request) { router.Get("/ws", func(w http.ResponseWriter, r *http.Request) {
if webSocketHandler.Upgrade(w, r) != nil { if webSocketHandler.Upgrade(w, r) != nil {
//nolint //nolint