mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* Do not regenerate apiserver-gen/go/routers.go * Regenerate after changes done in pr#6989 * Do not regenerate apiserver-gen/go/logger.go * Change logs * Fix comments
208 lines
5.3 KiB
Go
Generated
208 lines
5.3 KiB
Go
Generated
/*
|
|
* odo dev
|
|
*
|
|
* API interface for 'odo dev'
|
|
*
|
|
* API version: 0.1
|
|
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
|
|
*/
|
|
|
|
package openapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// DefaultApiController binds http requests to an api service and writes the service results to the http response
|
|
type DefaultApiController struct {
|
|
service DefaultApiServicer
|
|
errorHandler ErrorHandler
|
|
}
|
|
|
|
// DefaultApiOption for how the controller is set up.
|
|
type DefaultApiOption func(*DefaultApiController)
|
|
|
|
// WithDefaultApiErrorHandler inject ErrorHandler into controller
|
|
func WithDefaultApiErrorHandler(h ErrorHandler) DefaultApiOption {
|
|
return func(c *DefaultApiController) {
|
|
c.errorHandler = h
|
|
}
|
|
}
|
|
|
|
// NewDefaultApiController creates a default api controller
|
|
func NewDefaultApiController(s DefaultApiServicer, opts ...DefaultApiOption) Router {
|
|
controller := &DefaultApiController{
|
|
service: s,
|
|
errorHandler: DefaultErrorHandler,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
opt(controller)
|
|
}
|
|
|
|
return controller
|
|
}
|
|
|
|
// Routes returns all the api routes for the DefaultApiController
|
|
func (c *DefaultApiController) Routes() Routes {
|
|
return Routes{
|
|
{
|
|
"ComponentCommandPost",
|
|
strings.ToUpper("Post"),
|
|
"/api/v1/component/command",
|
|
c.ComponentCommandPost,
|
|
},
|
|
{
|
|
"ComponentGet",
|
|
strings.ToUpper("Get"),
|
|
"/api/v1/component",
|
|
c.ComponentGet,
|
|
},
|
|
{
|
|
"DevfileGet",
|
|
strings.ToUpper("Get"),
|
|
"/api/v1/devfile",
|
|
c.DevfileGet,
|
|
},
|
|
{
|
|
"DevfilePut",
|
|
strings.ToUpper("Put"),
|
|
"/api/v1/devfile",
|
|
c.DevfilePut,
|
|
},
|
|
{
|
|
"InstanceDelete",
|
|
strings.ToUpper("Delete"),
|
|
"/api/v1/instance",
|
|
c.InstanceDelete,
|
|
},
|
|
{
|
|
"InstanceGet",
|
|
strings.ToUpper("Get"),
|
|
"/api/v1/instance",
|
|
c.InstanceGet,
|
|
},
|
|
{
|
|
"TelemetryGet",
|
|
strings.ToUpper("Get"),
|
|
"/api/v1/telemetry",
|
|
c.TelemetryGet,
|
|
},
|
|
}
|
|
}
|
|
|
|
// ComponentCommandPost -
|
|
func (c *DefaultApiController) ComponentCommandPost(w http.ResponseWriter, r *http.Request) {
|
|
componentCommandPostRequestParam := ComponentCommandPostRequest{}
|
|
d := json.NewDecoder(r.Body)
|
|
d.DisallowUnknownFields()
|
|
if err := d.Decode(&componentCommandPostRequestParam); err != nil {
|
|
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
|
return
|
|
}
|
|
if err := AssertComponentCommandPostRequestRequired(componentCommandPostRequestParam); err != nil {
|
|
c.errorHandler(w, r, err, nil)
|
|
return
|
|
}
|
|
result, err := c.service.ComponentCommandPost(r.Context(), componentCommandPostRequestParam)
|
|
// 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, w)
|
|
|
|
}
|
|
|
|
// ComponentGet -
|
|
func (c *DefaultApiController) ComponentGet(w http.ResponseWriter, r *http.Request) {
|
|
result, err := c.service.ComponentGet(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, w)
|
|
|
|
}
|
|
|
|
// DevfileGet -
|
|
func (c *DefaultApiController) DevfileGet(w http.ResponseWriter, r *http.Request) {
|
|
result, err := c.service.DevfileGet(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, w)
|
|
|
|
}
|
|
|
|
// DevfilePut -
|
|
func (c *DefaultApiController) DevfilePut(w http.ResponseWriter, r *http.Request) {
|
|
devfilePutRequestParam := DevfilePutRequest{}
|
|
d := json.NewDecoder(r.Body)
|
|
d.DisallowUnknownFields()
|
|
if err := d.Decode(&devfilePutRequestParam); err != nil {
|
|
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
|
return
|
|
}
|
|
if err := AssertDevfilePutRequestRequired(devfilePutRequestParam); err != nil {
|
|
c.errorHandler(w, r, err, nil)
|
|
return
|
|
}
|
|
result, err := c.service.DevfilePut(r.Context(), devfilePutRequestParam)
|
|
// 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, w)
|
|
|
|
}
|
|
|
|
// InstanceDelete -
|
|
func (c *DefaultApiController) InstanceDelete(w http.ResponseWriter, r *http.Request) {
|
|
result, err := c.service.InstanceDelete(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, w)
|
|
|
|
}
|
|
|
|
// InstanceGet -
|
|
func (c *DefaultApiController) InstanceGet(w http.ResponseWriter, r *http.Request) {
|
|
result, err := c.service.InstanceGet(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, w)
|
|
|
|
}
|
|
|
|
// TelemetryGet -
|
|
func (c *DefaultApiController) TelemetryGet(w http.ResponseWriter, r *http.Request) {
|
|
result, err := c.service.TelemetryGet(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, w)
|
|
|
|
}
|