2022-03-22 09:21:55 +01:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
2022-05-04 12:23:53 +02:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2022-05-04 12:23:53 +02:00
|
|
|
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))
|
|
|
|
|
2022-05-04 12:23:53 +02:00
|
|
|
router.Handle("/assets/*", assetsHandler)
|
|
|
|
|
2022-03-22 09:21:55 +01:00
|
|
|
return router, nil
|
|
|
|
}
|