...

Source file src/go.formulabun.club/replays/ingest/server/go/api_default.go

Documentation: go.formulabun.club/replays/ingest/server/go

     1  /*
     2   * GoBun File Store
     3   *
     4   * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
     5   *
     6   * API version: 0.0.1
     7   * Generated by: OpenAPI Generator (https://openapi-generator.tech)
     8   */
     9  
    10  package openapi
    11  
    12  import (
    13  	"net/http"
    14  	"strings"
    15  )
    16  
    17  // DefaultApiController binds http requests to an api service and writes the service results to the http response
    18  type DefaultApiController struct {
    19  	service      DefaultApiServicer
    20  	errorHandler ErrorHandler
    21  }
    22  
    23  // DefaultApiOption for how the controller is set up.
    24  type DefaultApiOption func(*DefaultApiController)
    25  
    26  // WithDefaultApiErrorHandler inject ErrorHandler into controller
    27  func WithDefaultApiErrorHandler(h ErrorHandler) DefaultApiOption {
    28  	return func(c *DefaultApiController) {
    29  		c.errorHandler = h
    30  	}
    31  }
    32  
    33  // NewDefaultApiController creates a default api controller
    34  func NewDefaultApiController(s DefaultApiServicer, opts ...DefaultApiOption) Router {
    35  	controller := &DefaultApiController{
    36  		service:      s,
    37  		errorHandler: DefaultErrorHandler,
    38  	}
    39  
    40  	for _, opt := range opts {
    41  		opt(controller)
    42  	}
    43  
    44  	return controller
    45  }
    46  
    47  // Routes returns all the api routes for the DefaultApiController
    48  func (c *DefaultApiController) Routes() Routes {
    49  	return Routes{
    50  		{
    51  			"ListGet",
    52  			strings.ToUpper("Get"),
    53  			"/list",
    54  			c.ListGet,
    55  		},
    56  		{
    57  			"RootPost",
    58  			strings.ToUpper("Post"),
    59  			"/",
    60  			c.RootPost,
    61  		},
    62  	}
    63  }
    64  
    65  // ListGet - Get the list of replay files
    66  func (c *DefaultApiController) ListGet(w http.ResponseWriter, r *http.Request) {
    67  	result, err := c.service.ListGet(r.Context())
    68  	// If an error occurred, encode the error with the status code
    69  	if err != nil {
    70  		c.errorHandler(w, r, err, &result)
    71  		return
    72  	}
    73  	// If no error, encode the body and the result code
    74  	EncodeJSONResponse(result.Body, &result.Code, w)
    75  
    76  }
    77  
    78  // RootPost - Upload a new replay file
    79  func (c *DefaultApiController) RootPost(w http.ResponseWriter, r *http.Request) {
    80  	result, err := c.service.RootPost(r.Context(), r.Body)
    81  	// If an error occurred, encode the error with the status code
    82  	if err != nil {
    83  		c.errorHandler(w, r, err, &result)
    84  		return
    85  	}
    86  	// If no error, encode the body and the result code
    87  	EncodeJSONResponse(result.Body, &result.Code, w)
    88  
    89  }
    90  

View as plain text