formidable/internal/server/route/handler.go

24 lines
575 B
Go
Raw Normal View History

2022-03-22 09:21:55 +01:00
package route
import (
"net/http"
2022-03-22 09:21:55 +01:00
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/santhosh-tekuri/jsonschema/v5"
)
func NewHandler(schema *jsonschema.Schema, defaults, values interface{}, assetsHandler http.Handler) (*chi.Mux, error) {
2022-03-22 09:21:55 +01:00
router := chi.NewRouter()
router.Use(middleware.RequestID)
// router.Use(middleware.Logger)
router.Get("/", createRenderFormHandlerFunc(schema, defaults, values))
router.Post("/", createHandleFormHandlerFunc(schema, defaults, values))
router.Handle("/assets/*", assetsHandler)
2022-03-22 09:21:55 +01:00
return router, nil
}