specialist, subscpecialist, specialist-position, subspecialist-position ids into codes

This commit is contained in:
dpurbosakti
2025-11-06 14:23:51 +07:00
parent 7423621a30
commit 4aabf4ad52
26 changed files with 201 additions and 143 deletions
@@ -40,3 +40,37 @@ func RegCrud(r *http.ServeMux, path string, mwAndRouter ...any) {
"DELETE /{id}": c.Delete,
})
}
func RegCrudByCode(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,
"GET /": c.GetList,
"GET /{code}": c.GetDetail,
"PATCH /{code}": c.Update,
"DELETE /{code}": c.Delete,
})
}