Richard Lavoie 10897caf37
[go-server] fix imports with go generation (#18514)
* fix imports with go generation

* Wrong copy over

* Missing new line

* tab vs space

* Fix new line between router and std go libs

* Add both use case, add samples to CI validation

* Update samples
2024-05-01 18:13:03 +08:00

70 lines
1.7 KiB
Go

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
/*
* Simple no path and body param spec
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 1.0.0
*/
package petstoreserver
import (
"net/http"
"strings"
)
// NoneAPIController binds http requests to an api service and writes the service results to the http response
type NoneAPIController struct {
service NoneAPIServicer
errorHandler ErrorHandler
}
// NoneAPIOption for how the controller is set up.
type NoneAPIOption func(*NoneAPIController)
// WithNoneAPIErrorHandler inject ErrorHandler into controller
func WithNoneAPIErrorHandler(h ErrorHandler) NoneAPIOption {
return func(c *NoneAPIController) {
c.errorHandler = h
}
}
// NewNoneAPIController creates a default api controller
func NewNoneAPIController(s NoneAPIServicer, opts ...NoneAPIOption) Router {
controller := &NoneAPIController{
service: s,
errorHandler: DefaultErrorHandler,
}
for _, opt := range opts {
opt(controller)
}
return controller
}
// Routes returns all the api routes for the NoneAPIController
func (c *NoneAPIController) Routes() Routes {
return Routes{
"One": Route{
strings.ToUpper("Get"),
"/none/endpoint",
c.One,
},
}
}
// One - summary
func (c *NoneAPIController) One(w http.ResponseWriter, r *http.Request) {
result, err := c.service.One(r.Context())
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
}