...

Source file src/go.formulabun.club/translator/server/go/api_default.go

Documentation: go.formulabun.club/translator/server/go

     1  /*
     2   * Translator service between a srb2kart server and json
     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  			"FilesGet",
    52  			strings.ToUpper("Get"),
    53  			"/files",
    54  			c.FilesGet,
    55  		},
    56  		{
    57  			"PlayerinfoGet",
    58  			strings.ToUpper("Get"),
    59  			"/playerinfo",
    60  			c.PlayerinfoGet,
    61  		},
    62  		{
    63  			"ServerinfoGet",
    64  			strings.ToUpper("Get"),
    65  			"/serverinfo",
    66  			c.ServerinfoGet,
    67  		},
    68  	}
    69  }
    70  
    71  // FilesGet - get the installed files
    72  func (c *DefaultApiController) FilesGet(w http.ResponseWriter, r *http.Request) {
    73  	result, err := c.service.FilesGet(r.Context())
    74  	// If an error occurred, encode the error with the status code
    75  	if err != nil {
    76  		c.errorHandler(w, r, err, &result)
    77  		return
    78  	}
    79  	// If no error, encode the body and the result code
    80  	EncodeJSONResponse(result.Body, &result.Code, w)
    81  
    82  }
    83  
    84  // PlayerinfoGet - get the player infomation
    85  func (c *DefaultApiController) PlayerinfoGet(w http.ResponseWriter, r *http.Request) {
    86  	result, err := c.service.PlayerinfoGet(r.Context())
    87  	// If an error occurred, encode the error with the status code
    88  	if err != nil {
    89  		c.errorHandler(w, r, err, &result)
    90  		return
    91  	}
    92  	// If no error, encode the body and the result code
    93  	EncodeJSONResponse(result.Body, &result.Code, w)
    94  
    95  }
    96  
    97  // ServerinfoGet - get the server information
    98  func (c *DefaultApiController) ServerinfoGet(w http.ResponseWriter, r *http.Request) {
    99  	result, err := c.service.ServerinfoGet(r.Context())
   100  	// If an error occurred, encode the error with the status code
   101  	if err != nil {
   102  		c.errorHandler(w, r, err, &result)
   103  		return
   104  	}
   105  	// If no error, encode the body and the result code
   106  	EncodeJSONResponse(result.Body, &result.Code, w)
   107  
   108  }
   109  

View as plain text