Created
December 5, 2024 03:53
-
-
Save ssoroka/50630ae9ad83055fd37b58b693fee6db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func get[I, O any](api huma.API, path string, handler func(context.Context, *I) (*O, error), roles ...models.Role) { | |
huma.Register(api, huma.Operation{ | |
DefaultStatus: http.StatusOK, | |
Method: http.MethodGet, | |
Path: path, | |
Security: []map[string][]string{ | |
{ | |
"bearer": {"jwt"}, | |
"roles": rolesToStrings(roles...), | |
}, | |
}, | |
}, handler) | |
} | |
func post[I, O any](api huma.API, path string, handler func(context.Context, *I) (*O, error), roles ...models.Role) { | |
huma.Register(api, huma.Operation{ | |
DefaultStatus: http.StatusCreated, | |
Method: http.MethodPost, | |
Path: path, | |
Security: []map[string][]string{ | |
{ | |
"bearer": {"jwt"}, | |
"roles": rolesToStrings(roles...), | |
}, | |
}, | |
}, handler) | |
} | |
func unauthenticatedPost[I, O any](api huma.API, path string, handler func(context.Context, *I) (*O, error)) { | |
huma.Register(api, huma.Operation{ | |
DefaultStatus: http.StatusCreated, | |
Method: http.MethodPost, | |
Path: path, | |
}, handler) | |
} | |
func put[I, O any](api huma.API, path string, handler func(context.Context, *I) (*O, error), roles ...models.Role) { | |
huma.Register(api, huma.Operation{ | |
DefaultStatus: http.StatusOK, | |
Method: http.MethodPut, | |
Path: path, | |
Security: []map[string][]string{ | |
{ | |
"bearer": {"jwt"}, | |
"roles": rolesToStrings(roles...), | |
}, | |
}, | |
}, handler) | |
} | |
func delete[I, O any](api huma.API, path string, handler func(context.Context, *I) (*O, error), roles ...models.Role) { | |
huma.Register(api, huma.Operation{ | |
DefaultStatus: http.StatusNoContent, | |
Method: http.MethodDelete, | |
Path: path, | |
Security: []map[string][]string{ | |
{ | |
"bearer": {"jwt"}, | |
"roles": rolesToStrings(roles...), | |
}, | |
}, | |
}, handler) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment