...

Source file src/github.com/redhat-developer/odo/pkg/apiserver-gen/go/api_default.go

Documentation: github.com/redhat-developer/odo/pkg/apiserver-gen/go

     1  /*
     2   * odo dev
     3   *
     4   * API interface for 'odo dev'
     5   *
     6   * API version: 0.1
     7   * Generated by: OpenAPI Generator (https://openapi-generator.tech)
     8   */
     9  
    10  package openapi
    11  
    12  import (
    13  	"encoding/json"
    14  	"net/http"
    15  	"strings"
    16  )
    17  
    18  // DefaultApiController binds http requests to an api service and writes the service results to the http response
    19  type DefaultApiController struct {
    20  	service      DefaultApiServicer
    21  	errorHandler ErrorHandler
    22  }
    23  
    24  // DefaultApiOption for how the controller is set up.
    25  type DefaultApiOption func(*DefaultApiController)
    26  
    27  // WithDefaultApiErrorHandler inject ErrorHandler into controller
    28  func WithDefaultApiErrorHandler(h ErrorHandler) DefaultApiOption {
    29  	return func(c *DefaultApiController) {
    30  		c.errorHandler = h
    31  	}
    32  }
    33  
    34  // NewDefaultApiController creates a default api controller
    35  func NewDefaultApiController(s DefaultApiServicer, opts ...DefaultApiOption) Router {
    36  	controller := &DefaultApiController{
    37  		service:      s,
    38  		errorHandler: DefaultErrorHandler,
    39  	}
    40  
    41  	for _, opt := range opts {
    42  		opt(controller)
    43  	}
    44  
    45  	return controller
    46  }
    47  
    48  // Routes returns all the api routes for the DefaultApiController
    49  func (c *DefaultApiController) Routes() Routes {
    50  	return Routes{
    51  		{
    52  			"ComponentCommandPost",
    53  			strings.ToUpper("Post"),
    54  			"/api/v1/component/command",
    55  			c.ComponentCommandPost,
    56  		},
    57  		{
    58  			"ComponentGet",
    59  			strings.ToUpper("Get"),
    60  			"/api/v1/component",
    61  			c.ComponentGet,
    62  		},
    63  		{
    64  			"DevfileGet",
    65  			strings.ToUpper("Get"),
    66  			"/api/v1/devfile",
    67  			c.DevfileGet,
    68  		},
    69  		{
    70  			"DevfilePut",
    71  			strings.ToUpper("Put"),
    72  			"/api/v1/devfile",
    73  			c.DevfilePut,
    74  		},
    75  		{
    76  			"InstanceDelete",
    77  			strings.ToUpper("Delete"),
    78  			"/api/v1/instance",
    79  			c.InstanceDelete,
    80  		},
    81  		{
    82  			"InstanceGet",
    83  			strings.ToUpper("Get"),
    84  			"/api/v1/instance",
    85  			c.InstanceGet,
    86  		},
    87  		{
    88  			"TelemetryGet",
    89  			strings.ToUpper("Get"),
    90  			"/api/v1/telemetry",
    91  			c.TelemetryGet,
    92  		},
    93  	}
    94  }
    95  
    96  // ComponentCommandPost -
    97  func (c *DefaultApiController) ComponentCommandPost(w http.ResponseWriter, r *http.Request) {
    98  	componentCommandPostRequestParam := ComponentCommandPostRequest{}
    99  	d := json.NewDecoder(r.Body)
   100  	d.DisallowUnknownFields()
   101  	if err := d.Decode(&componentCommandPostRequestParam); err != nil {
   102  		c.errorHandler(w, r, &ParsingError{Err: err}, nil)
   103  		return
   104  	}
   105  	if err := AssertComponentCommandPostRequestRequired(componentCommandPostRequestParam); err != nil {
   106  		c.errorHandler(w, r, err, nil)
   107  		return
   108  	}
   109  	result, err := c.service.ComponentCommandPost(r.Context(), componentCommandPostRequestParam)
   110  	// If an error occurred, encode the error with the status code
   111  	if err != nil {
   112  		c.errorHandler(w, r, err, &result)
   113  		return
   114  	}
   115  	// If no error, encode the body and the result code
   116  	EncodeJSONResponse(result.Body, &result.Code, w)
   117  
   118  }
   119  
   120  // ComponentGet -
   121  func (c *DefaultApiController) ComponentGet(w http.ResponseWriter, r *http.Request) {
   122  	result, err := c.service.ComponentGet(r.Context())
   123  	// If an error occurred, encode the error with the status code
   124  	if err != nil {
   125  		c.errorHandler(w, r, err, &result)
   126  		return
   127  	}
   128  	// If no error, encode the body and the result code
   129  	EncodeJSONResponse(result.Body, &result.Code, w)
   130  
   131  }
   132  
   133  // DevfileGet -
   134  func (c *DefaultApiController) DevfileGet(w http.ResponseWriter, r *http.Request) {
   135  	result, err := c.service.DevfileGet(r.Context())
   136  	// If an error occurred, encode the error with the status code
   137  	if err != nil {
   138  		c.errorHandler(w, r, err, &result)
   139  		return
   140  	}
   141  	// If no error, encode the body and the result code
   142  	EncodeJSONResponse(result.Body, &result.Code, w)
   143  
   144  }
   145  
   146  // DevfilePut -
   147  func (c *DefaultApiController) DevfilePut(w http.ResponseWriter, r *http.Request) {
   148  	devfilePutRequestParam := DevfilePutRequest{}
   149  	d := json.NewDecoder(r.Body)
   150  	d.DisallowUnknownFields()
   151  	if err := d.Decode(&devfilePutRequestParam); err != nil {
   152  		c.errorHandler(w, r, &ParsingError{Err: err}, nil)
   153  		return
   154  	}
   155  	if err := AssertDevfilePutRequestRequired(devfilePutRequestParam); err != nil {
   156  		c.errorHandler(w, r, err, nil)
   157  		return
   158  	}
   159  	result, err := c.service.DevfilePut(r.Context(), devfilePutRequestParam)
   160  	// If an error occurred, encode the error with the status code
   161  	if err != nil {
   162  		c.errorHandler(w, r, err, &result)
   163  		return
   164  	}
   165  	// If no error, encode the body and the result code
   166  	EncodeJSONResponse(result.Body, &result.Code, w)
   167  
   168  }
   169  
   170  // InstanceDelete -
   171  func (c *DefaultApiController) InstanceDelete(w http.ResponseWriter, r *http.Request) {
   172  	result, err := c.service.InstanceDelete(r.Context())
   173  	// If an error occurred, encode the error with the status code
   174  	if err != nil {
   175  		c.errorHandler(w, r, err, &result)
   176  		return
   177  	}
   178  	// If no error, encode the body and the result code
   179  	EncodeJSONResponse(result.Body, &result.Code, w)
   180  
   181  }
   182  
   183  // InstanceGet -
   184  func (c *DefaultApiController) InstanceGet(w http.ResponseWriter, r *http.Request) {
   185  	result, err := c.service.InstanceGet(r.Context())
   186  	// If an error occurred, encode the error with the status code
   187  	if err != nil {
   188  		c.errorHandler(w, r, err, &result)
   189  		return
   190  	}
   191  	// If no error, encode the body and the result code
   192  	EncodeJSONResponse(result.Body, &result.Code, w)
   193  
   194  }
   195  
   196  // TelemetryGet -
   197  func (c *DefaultApiController) TelemetryGet(w http.ResponseWriter, r *http.Request) {
   198  	result, err := c.service.TelemetryGet(r.Context())
   199  	// If an error occurred, encode the error with the status code
   200  	if err != nil {
   201  		c.errorHandler(w, r, err, &result)
   202  		return
   203  	}
   204  	// If no error, encode the body and the result code
   205  	EncodeJSONResponse(result.Body, &result.Code, w)
   206  
   207  }
   208  

View as plain text