set infra

This commit is contained in:
vanilia
2025-11-13 09:57:10 +07:00
parent 94ce6bd5ee
commit ebc2ca5659
24 changed files with 843 additions and 105 deletions
@@ -74,3 +74,67 @@ func RegCrudByCode(r *http.ServeMux, path string, mwAndRouter ...any) {
"DELETE /{code}": c.Delete,
})
}
func RegCrudSimgosSync(r *http.ServeMux, path string, mwAndRouter ...any) {
sLength := len(mwAndRouter)
mwCandidates := mwAndRouter[:sLength-1]
mwList := []hk.HandlerMw{}
for i := range mwCandidates {
// have to do it manually, since casting directly results unexpected result
myType := reflect.TypeOf(mwCandidates[i])
if myType.String() != "func(http.Handler) http.Handler" {
panic("non middleware included as middleware")
}
mwList = append(mwList, mwCandidates[i].(func(http.Handler) http.Handler))
// if g, okHandler := mwCandidates[i].(func(http.Handler) http.Handler); !okHandler {
// panic("non middleware included")
// } else {
// mwList = append(mwList, g)
// }
}
c, ok := mwAndRouter[sLength-1].(CrudBase)
if !ok {
panic("non CrudBase used in the last paramter")
}
hk.GroupRoutes(path, r, mwList, hk.MapHandlerFunc{
"POST /": c.Create,
"PATCH /{id}": c.Update,
"DELETE /{id}": c.Delete,
})
}
func RegCrudByCodeSimgosSync(r *http.ServeMux, path string, mwAndRouter ...any) {
sLength := len(mwAndRouter)
mwCandidates := mwAndRouter[:sLength-1]
mwList := []hk.HandlerMw{}
for i := range mwCandidates {
// have to do it manually, since casting directly results unexpected result
myType := reflect.TypeOf(mwCandidates[i])
if myType.String() != "func(http.Handler) http.Handler" {
panic("non middleware included as middleware")
}
mwList = append(mwList, mwCandidates[i].(func(http.Handler) http.Handler))
// if g, okHandler := mwCandidates[i].(func(http.Handler) http.Handler); !okHandler {
// panic("non middleware included")
// } else {
// mwList = append(mwList, g)
// }
}
c, ok := mwAndRouter[sLength-1].(CrudBase)
if !ok {
panic("non CrudBase used in the last paramter")
}
hk.GroupRoutes(path, r, mwList, hk.MapHandlerFunc{
"POST /": c.Create,
"PATCH /{code}": c.Update,
"DELETE /{code}": c.Delete,
})
}