Small naming change
This commit is contained in:
parent
989dd67030
commit
766be03907
6
main.go
6
main.go
|
|
@ -48,7 +48,7 @@ type http_status_code int; const (
|
|||
type empty_request_body struct {}
|
||||
/* T Representing any request body struct
|
||||
S Representing any response body struct */
|
||||
func http_new_route[T any, S any](method http_method, route string, handle_func func(body T, raw_request *http.Request) (S, http_status_code)) {
|
||||
func json_new_route[T any, S any](method http_method, route string, handle_func func(body T, raw_request *http.Request) (S, http_status_code)) {
|
||||
http.HandleFunc(method.to_string() + " /" + route, func(response http.ResponseWriter, request *http.Request) {
|
||||
request_body_bytes, err := io.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
|
|
@ -99,7 +99,7 @@ func main() {
|
|||
Field2: body.Arg1 + body.Arg2,
|
||||
}, OK
|
||||
}
|
||||
http_new_route(GET, "foo", foo_route_handler)
|
||||
json_new_route(GET, "foo", foo_route_handler)
|
||||
|
||||
type bar_response_body struct {
|
||||
Response int
|
||||
|
|
@ -111,7 +111,7 @@ func main() {
|
|||
Message: "hi there on bar!",
|
||||
}, INTERNAL_SERVER_ERROR
|
||||
}
|
||||
http_new_route(GET, "bar", bar_route_handler)
|
||||
json_new_route(GET, "bar", bar_route_handler)
|
||||
|
||||
http_server := &http.Server{
|
||||
Addr: ":8080",
|
||||
|
|
|
|||
Loading…
Reference in New Issue