casaos_api.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // Package codegen provides primitives to interact with the openapi HTTP API.
  2. //
  3. // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.
  4. package codegen
  5. import (
  6. "bytes"
  7. "compress/gzip"
  8. "encoding/base64"
  9. "fmt"
  10. "net/url"
  11. "path"
  12. "strings"
  13. "github.com/getkin/kin-openapi/openapi3"
  14. "github.com/labstack/echo/v4"
  15. )
  16. const (
  17. Access_tokenScopes = "access_token.Scopes"
  18. )
  19. // BaseResponse defines model for BaseResponse.
  20. type BaseResponse struct {
  21. // Message message returned by server side if there is any
  22. Message *string `json:"message,omitempty"`
  23. }
  24. // HealthPorts defines model for HealthPorts.
  25. type HealthPorts struct {
  26. TCP *[]int `json:"tcp,omitempty"`
  27. UDP *[]int `json:"udp,omitempty"`
  28. }
  29. // HealthServices defines model for HealthServices.
  30. type HealthServices struct {
  31. NotRunning *[]string `json:"not_running,omitempty"`
  32. Running *[]string `json:"running,omitempty"`
  33. }
  34. // GetHealthPortsOK defines model for GetHealthPortsOK.
  35. type GetHealthPortsOK struct {
  36. Data *HealthPorts `json:"data,omitempty"`
  37. // Message message returned by server side if there is any
  38. Message *string `json:"message,omitempty"`
  39. }
  40. // GetHealthServicesOK defines model for GetHealthServicesOK.
  41. type GetHealthServicesOK struct {
  42. Data *HealthServices `json:"data,omitempty"`
  43. // Message message returned by server side if there is any
  44. Message *string `json:"message,omitempty"`
  45. }
  46. // ResponseInternalServerError defines model for ResponseInternalServerError.
  47. type ResponseInternalServerError = BaseResponse
  48. // ResponseOK defines model for ResponseOK.
  49. type ResponseOK = BaseResponse
  50. // ServerInterface represents all server handlers.
  51. type ServerInterface interface {
  52. // Test file methods
  53. // (GET /file/test)
  54. GetFileTest(ctx echo.Context) error
  55. // Get port in use
  56. // (GET /health/ports)
  57. GetHealthPorts(ctx echo.Context) error
  58. // Get service status
  59. // (GET /health/services)
  60. GetHealthServices(ctx echo.Context) error
  61. }
  62. // ServerInterfaceWrapper converts echo contexts to parameters.
  63. type ServerInterfaceWrapper struct {
  64. Handler ServerInterface
  65. }
  66. // GetFileTest converts echo context to params.
  67. func (w *ServerInterfaceWrapper) GetFileTest(ctx echo.Context) error {
  68. var err error
  69. ctx.Set(Access_tokenScopes, []string{""})
  70. // Invoke the callback with all the unmarshalled arguments
  71. err = w.Handler.GetFileTest(ctx)
  72. return err
  73. }
  74. // GetHealthPorts converts echo context to params.
  75. func (w *ServerInterfaceWrapper) GetHealthPorts(ctx echo.Context) error {
  76. var err error
  77. ctx.Set(Access_tokenScopes, []string{""})
  78. // Invoke the callback with all the unmarshalled arguments
  79. err = w.Handler.GetHealthPorts(ctx)
  80. return err
  81. }
  82. // GetHealthServices converts echo context to params.
  83. func (w *ServerInterfaceWrapper) GetHealthServices(ctx echo.Context) error {
  84. var err error
  85. ctx.Set(Access_tokenScopes, []string{""})
  86. // Invoke the callback with all the unmarshalled arguments
  87. err = w.Handler.GetHealthServices(ctx)
  88. return err
  89. }
  90. // This is a simple interface which specifies echo.Route addition functions which
  91. // are present on both echo.Echo and echo.Group, since we want to allow using
  92. // either of them for path registration
  93. type EchoRouter interface {
  94. CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  95. DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  96. GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  97. HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  98. OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  99. PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  100. POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  101. PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  102. TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  103. }
  104. // RegisterHandlers adds each server route to the EchoRouter.
  105. func RegisterHandlers(router EchoRouter, si ServerInterface) {
  106. RegisterHandlersWithBaseURL(router, si, "")
  107. }
  108. // Registers handlers, and prepends BaseURL to the paths, so that the paths
  109. // can be served under a prefix.
  110. func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
  111. wrapper := ServerInterfaceWrapper{
  112. Handler: si,
  113. }
  114. router.GET(baseURL+"/file/test", wrapper.GetFileTest)
  115. router.GET(baseURL+"/health/ports", wrapper.GetHealthPorts)
  116. router.GET(baseURL+"/health/services", wrapper.GetHealthServices)
  117. }
  118. // Base64 encoded, gzipped, json marshaled Swagger object
  119. var swaggerSpec = []string{
  120. "H4sIAAAAAAAC/8xW4W/bthP9Vwj+fh+aQbaMBAUKAf2QNksaBIODJcMGxIZLU2eJjURyd6QTL9D/PpCS",
  121. "Y8V2g6Rdh31yRB7fvfdyx+MDl6a2RoN2xLMHjkDWaIL4cQbuE4jKlZcGHY0vwpo02oF24U9hbaWkcMro",
  122. "9AsZHdZIllCLuFtV4wXPbh74/xEWPOP/Szep0jaO0g+C4NcuJ2+SB27RWECnWga5cBHsOYgeRd40zbRp",
  123. "moTnQBKVDdx4xscXvEk2cq4Al0rCf1zRmuXzotapzrUD1KIKpwB/RjT4KnEvl7TLZJ2btclZm71H7pVG",
  124. "fw+X4EqTdGDR8Scnsu3/Rw1EoogbT4G6DYbgPGrI2XzFqNVHKgemFsyVgMAUMaFXPOFwL2pbAc84TziC",
  125. "yMe6WvHMoYeEu5UNO+RQ6aIl3i/cHV5O2vCjHNTx+xH83egRTGkHBUSnuxWBKAKV+0FhBlrUYe3642WI",
  126. "8PlXAN8evRLwt5PLvoDHOt3RoI2bodc6KN6bmktBwtCQWgi+Y9MWjybhL8EbFMLBnVi9HDfKIZAelVtd",
  127. "hdppFQgpgWjmzC3EGlWhMkoQOSBPeOfHsXelQfVXLOdNLmHVBaxap5RemN0Sm/jR6EhaJZ1HiB8w0Ywx",
  128. "1m6Q8SiB1ZAr8X7C31iEBSANpKkMDmKFQ8ZygbcHE84IJYF7P+Glc5ayNEVxNyyUK/3cE2DXfENp6vRc",
  129. "wu+lqOAaZJlWpjBpLZROW/O6n9lcaA04C/AzrYrSzd6NRvZ+aHUx4d9KtgpAP5Ctu1MxxWxeeXiesKoL",
  130. "JqpA4aMgMb5qSf37jFo26VYVTHTLih1fnjOLZqlyIFYrklBVQoPxxGpwpcmJLQyyXC0WgKAdIwlaoDI0",
  131. "DCinBpki8hAuqZzliqQnUkZTwmwFgoAtFSkX7jJ2c6bcJz9nCNaQcgZX0zdrN1onduW3NA+YQfbFKM1u",
  132. "jEd2okgazDen83ZhWBTprf7zeD7/MIc/DoaT2C7Kxd7dCOYJXwJS2yTLw9CuxoIWVvGMHw1HwyOecCtc",
  133. "GXs0XagKUgcUJ0sBbrfRroEcC2Frz4Y8QmJs2fOcZ+FxcKqCJnLx9u49gw5Ho69Npce4tDfqmoS/fc2R",
  134. "faM73ke+rgWu9vEPtomCeHbDT/vL03AuLeO9nNr1ZOk82RHcH0DfonnnffjPKz8Dx4IOpjTzBD3dbeb9",
  135. "yqk3kvYWRIDtJgkjJ5wnZhYMhCzZ526G/PSZdTB7i2Vr9n2Xfb336I9xsBPSSX3WxN4cjE/dpxPwZtpM",
  136. "Q0BIRnHfY8Uzni4Pu3uPh4AOftv1N9fjk/HBZnBuZQ+P5ecPPKn1kOh+4ERxhsbbNl8X98tOl+wInTZ/",
  137. "BwAA///xoj5w+wwAAA==",
  138. }
  139. // GetSwagger returns the content of the embedded swagger specification file
  140. // or error if failed to decode
  141. func decodeSpec() ([]byte, error) {
  142. zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
  143. if err != nil {
  144. return nil, fmt.Errorf("error base64 decoding spec: %s", err)
  145. }
  146. zr, err := gzip.NewReader(bytes.NewReader(zipped))
  147. if err != nil {
  148. return nil, fmt.Errorf("error decompressing spec: %s", err)
  149. }
  150. var buf bytes.Buffer
  151. _, err = buf.ReadFrom(zr)
  152. if err != nil {
  153. return nil, fmt.Errorf("error decompressing spec: %s", err)
  154. }
  155. return buf.Bytes(), nil
  156. }
  157. var rawSpec = decodeSpecCached()
  158. // a naive cached of a decoded swagger spec
  159. func decodeSpecCached() func() ([]byte, error) {
  160. data, err := decodeSpec()
  161. return func() ([]byte, error) {
  162. return data, err
  163. }
  164. }
  165. // Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
  166. func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
  167. var res = make(map[string]func() ([]byte, error))
  168. if len(pathToFile) > 0 {
  169. res[pathToFile] = rawSpec
  170. }
  171. return res
  172. }
  173. // GetSwagger returns the Swagger specification corresponding to the generated code
  174. // in this file. The external references of Swagger specification are resolved.
  175. // The logic of resolving external references is tightly connected to "import-mapping" feature.
  176. // Externally referenced files must be embedded in the corresponding golang packages.
  177. // Urls can be supported but this task was out of the scope.
  178. func GetSwagger() (swagger *openapi3.T, err error) {
  179. var resolvePath = PathToRawSpec("")
  180. loader := openapi3.NewLoader()
  181. loader.IsExternalRefsAllowed = true
  182. loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
  183. var pathToFile = url.String()
  184. pathToFile = path.Clean(pathToFile)
  185. getSpec, ok := resolvePath[pathToFile]
  186. if !ok {
  187. err1 := fmt.Errorf("path not found: %s", pathToFile)
  188. return nil, err1
  189. }
  190. return getSpec()
  191. }
  192. var specData []byte
  193. specData, err = rawSpec()
  194. if err != nil {
  195. return
  196. }
  197. swagger, err = loader.LoadFromData(specData)
  198. if err != nil {
  199. return
  200. }
  201. return
  202. }