warehouse/api/server.gen.go

1035 lines
35 KiB
Go
Raw Normal View History

2024-11-12 22:12:41 +01:00
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT.
package api
import (
"bytes"
"compress/gzip"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"path"
"strings"
"time"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gorilla/mux"
"github.com/oapi-codegen/runtime"
strictnethttp "github.com/oapi-codegen/runtime/strictmiddleware/nethttp"
)
// Bucket defines model for Bucket.
type Bucket struct {
// CreatedAt Creation timestamp of the bucket
CreatedAt *time.Time `json:"created_at,omitempty"`
// Name The name of the bucket
Name *string `json:"name,omitempty"`
}
// Object defines model for Object.
type Object struct {
// Key The key (identifier) of the object
Key *string `json:"key,omitempty"`
// LastModified The last modified timestamp of the object
LastModified *time.Time `json:"last_modified,omitempty"`
// Size The size of the object in bytes
Size *int `json:"size,omitempty"`
}
// GetBucketsParams defines parameters for GetBuckets.
type GetBucketsParams struct {
// Limit The maximum number of items to return
Limit *int `form:"limit,omitempty" json:"limit,omitempty"`
// Offset The number of items to skip before starting to collect the result set
Offset *int `form:"offset,omitempty" json:"offset,omitempty"`
}
// PostBucketsJSONBody defines parameters for PostBuckets.
type PostBucketsJSONBody struct {
// Name Name of the bucket to be created
Name *string `json:"name,omitempty"`
}
// GetBucketsBucketNameObjectsParams defines parameters for GetBucketsBucketNameObjects.
type GetBucketsBucketNameObjectsParams struct {
// Limit The maximum number of items to return
Limit *int `form:"limit,omitempty" json:"limit,omitempty"`
// Offset The number of items to skip before starting to collect the result set
Offset *int `form:"offset,omitempty" json:"offset,omitempty"`
}
// PostBucketsJSONRequestBody defines body for PostBuckets for application/json ContentType.
type PostBucketsJSONRequestBody PostBucketsJSONBody
// ServerInterface represents all server handlers.
type ServerInterface interface {
// List all buckets
// (GET /buckets)
GetBuckets(w http.ResponseWriter, r *http.Request, params GetBucketsParams)
// Create a new bucket
// (POST /buckets)
PostBuckets(w http.ResponseWriter, r *http.Request)
// Delete a bucket
// (DELETE /buckets/{bucketName})
DeleteBucketsBucketName(w http.ResponseWriter, r *http.Request, bucketName string)
// List objects in a bucket
// (GET /buckets/{bucketName}/objects)
GetBucketsBucketNameObjects(w http.ResponseWriter, r *http.Request, bucketName string, params GetBucketsBucketNameObjectsParams)
// Delete an object
// (DELETE /buckets/{bucketName}/objects/{objectKey})
DeleteBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request, bucketName string, objectKey string)
// Get object
// (GET /buckets/{bucketName}/objects/{objectKey})
GetBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request, bucketName string, objectKey string)
// Upload an object
// (PUT /buckets/{bucketName}/objects/{objectKey})
PutBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request, bucketName string, objectKey string)
}
// ServerInterfaceWrapper converts contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
HandlerMiddlewares []MiddlewareFunc
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
type MiddlewareFunc func(http.Handler) http.Handler
// GetBuckets operation middleware
func (siw *ServerInterfaceWrapper) GetBuckets(w http.ResponseWriter, r *http.Request) {
var err error
// Parameter object where we will unmarshal all parameters from the context
var params GetBucketsParams
// ------------- Optional query parameter "limit" -------------
err = runtime.BindQueryParameter("form", true, false, "limit", r.URL.Query(), &params.Limit)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err})
return
}
// ------------- Optional query parameter "offset" -------------
err = runtime.BindQueryParameter("form", true, false, "offset", r.URL.Query(), &params.Offset)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "offset", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.GetBuckets(w, r, params)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// PostBuckets operation middleware
func (siw *ServerInterfaceWrapper) PostBuckets(w http.ResponseWriter, r *http.Request) {
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.PostBuckets(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// DeleteBucketsBucketName operation middleware
func (siw *ServerInterfaceWrapper) DeleteBucketsBucketName(w http.ResponseWriter, r *http.Request) {
var err error
// ------------- Path parameter "bucketName" -------------
var bucketName string
err = runtime.BindStyledParameterWithOptions("simple", "bucketName", mux.Vars(r)["bucketName"], &bucketName, runtime.BindStyledParameterOptions{Explode: false, Required: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "bucketName", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.DeleteBucketsBucketName(w, r, bucketName)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// GetBucketsBucketNameObjects operation middleware
func (siw *ServerInterfaceWrapper) GetBucketsBucketNameObjects(w http.ResponseWriter, r *http.Request) {
var err error
// ------------- Path parameter "bucketName" -------------
var bucketName string
err = runtime.BindStyledParameterWithOptions("simple", "bucketName", mux.Vars(r)["bucketName"], &bucketName, runtime.BindStyledParameterOptions{Explode: false, Required: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "bucketName", Err: err})
return
}
// Parameter object where we will unmarshal all parameters from the context
var params GetBucketsBucketNameObjectsParams
// ------------- Optional query parameter "limit" -------------
err = runtime.BindQueryParameter("form", true, false, "limit", r.URL.Query(), &params.Limit)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err})
return
}
// ------------- Optional query parameter "offset" -------------
err = runtime.BindQueryParameter("form", true, false, "offset", r.URL.Query(), &params.Offset)
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "offset", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.GetBucketsBucketNameObjects(w, r, bucketName, params)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// DeleteBucketsBucketNameObjectsObjectKey operation middleware
func (siw *ServerInterfaceWrapper) DeleteBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request) {
var err error
// ------------- Path parameter "bucketName" -------------
var bucketName string
err = runtime.BindStyledParameterWithOptions("simple", "bucketName", mux.Vars(r)["bucketName"], &bucketName, runtime.BindStyledParameterOptions{Explode: false, Required: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "bucketName", Err: err})
return
}
// ------------- Path parameter "objectKey" -------------
var objectKey string
err = runtime.BindStyledParameterWithOptions("simple", "objectKey", mux.Vars(r)["objectKey"], &objectKey, runtime.BindStyledParameterOptions{Explode: false, Required: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "objectKey", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.DeleteBucketsBucketNameObjectsObjectKey(w, r, bucketName, objectKey)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// GetBucketsBucketNameObjectsObjectKey operation middleware
func (siw *ServerInterfaceWrapper) GetBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request) {
var err error
// ------------- Path parameter "bucketName" -------------
var bucketName string
err = runtime.BindStyledParameterWithOptions("simple", "bucketName", mux.Vars(r)["bucketName"], &bucketName, runtime.BindStyledParameterOptions{Explode: false, Required: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "bucketName", Err: err})
return
}
// ------------- Path parameter "objectKey" -------------
var objectKey string
err = runtime.BindStyledParameterWithOptions("simple", "objectKey", mux.Vars(r)["objectKey"], &objectKey, runtime.BindStyledParameterOptions{Explode: false, Required: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "objectKey", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.GetBucketsBucketNameObjectsObjectKey(w, r, bucketName, objectKey)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// PutBucketsBucketNameObjectsObjectKey operation middleware
func (siw *ServerInterfaceWrapper) PutBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request) {
var err error
// ------------- Path parameter "bucketName" -------------
var bucketName string
err = runtime.BindStyledParameterWithOptions("simple", "bucketName", mux.Vars(r)["bucketName"], &bucketName, runtime.BindStyledParameterOptions{Explode: false, Required: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "bucketName", Err: err})
return
}
// ------------- Path parameter "objectKey" -------------
var objectKey string
err = runtime.BindStyledParameterWithOptions("simple", "objectKey", mux.Vars(r)["objectKey"], &objectKey, runtime.BindStyledParameterOptions{Explode: false, Required: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "objectKey", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.PutBucketsBucketNameObjectsObjectKey(w, r, bucketName, objectKey)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
type UnescapedCookieParamError struct {
ParamName string
Err error
}
func (e *UnescapedCookieParamError) Error() string {
return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
}
func (e *UnescapedCookieParamError) Unwrap() error {
return e.Err
}
type UnmarshalingParamError struct {
ParamName string
Err error
}
func (e *UnmarshalingParamError) Error() string {
return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
}
func (e *UnmarshalingParamError) Unwrap() error {
return e.Err
}
type RequiredParamError struct {
ParamName string
}
func (e *RequiredParamError) Error() string {
return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
}
type RequiredHeaderError struct {
ParamName string
Err error
}
func (e *RequiredHeaderError) Error() string {
return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
}
func (e *RequiredHeaderError) Unwrap() error {
return e.Err
}
type InvalidParamFormatError struct {
ParamName string
Err error
}
func (e *InvalidParamFormatError) Error() string {
return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
}
func (e *InvalidParamFormatError) Unwrap() error {
return e.Err
}
type TooManyValuesForParamError struct {
ParamName string
Count int
}
func (e *TooManyValuesForParamError) Error() string {
return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
}
// Handler creates http.Handler with routing matching OpenAPI spec.
func Handler(si ServerInterface) http.Handler {
return HandlerWithOptions(si, GorillaServerOptions{})
}
type GorillaServerOptions struct {
BaseURL string
BaseRouter *mux.Router
Middlewares []MiddlewareFunc
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
func HandlerFromMux(si ServerInterface, r *mux.Router) http.Handler {
return HandlerWithOptions(si, GorillaServerOptions{
BaseRouter: r,
})
}
func HandlerFromMuxWithBaseURL(si ServerInterface, r *mux.Router, baseURL string) http.Handler {
return HandlerWithOptions(si, GorillaServerOptions{
BaseURL: baseURL,
BaseRouter: r,
})
}
// HandlerWithOptions creates http.Handler with additional options
func HandlerWithOptions(si ServerInterface, options GorillaServerOptions) http.Handler {
r := options.BaseRouter
if r == nil {
r = mux.NewRouter()
}
if options.ErrorHandlerFunc == nil {
options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
wrapper := ServerInterfaceWrapper{
Handler: si,
HandlerMiddlewares: options.Middlewares,
ErrorHandlerFunc: options.ErrorHandlerFunc,
}
r.HandleFunc(options.BaseURL+"/buckets", wrapper.GetBuckets).Methods("GET")
r.HandleFunc(options.BaseURL+"/buckets", wrapper.PostBuckets).Methods("POST")
r.HandleFunc(options.BaseURL+"/buckets/{bucketName}", wrapper.DeleteBucketsBucketName).Methods("DELETE")
r.HandleFunc(options.BaseURL+"/buckets/{bucketName}/objects", wrapper.GetBucketsBucketNameObjects).Methods("GET")
r.HandleFunc(options.BaseURL+"/buckets/{bucketName}/objects/{objectKey}", wrapper.DeleteBucketsBucketNameObjectsObjectKey).Methods("DELETE")
r.HandleFunc(options.BaseURL+"/buckets/{bucketName}/objects/{objectKey}", wrapper.GetBucketsBucketNameObjectsObjectKey).Methods("GET")
r.HandleFunc(options.BaseURL+"/buckets/{bucketName}/objects/{objectKey}", wrapper.PutBucketsBucketNameObjectsObjectKey).Methods("PUT")
return r
}
type GetBucketsRequestObject struct {
Params GetBucketsParams
}
type GetBucketsResponseObject interface {
VisitGetBucketsResponse(w http.ResponseWriter) error
}
type GetBuckets200JSONResponse struct {
Items *[]Bucket `json:"items,omitempty"`
// Total Total number of buckets available
Total *int `json:"total,omitempty"`
}
func (response GetBuckets200JSONResponse) VisitGetBucketsResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
return json.NewEncoder(w).Encode(response)
}
type GetBuckets500Response struct {
}
func (response GetBuckets500Response) VisitGetBucketsResponse(w http.ResponseWriter) error {
w.WriteHeader(500)
return nil
}
type PostBucketsRequestObject struct {
Body *PostBucketsJSONRequestBody
}
type PostBucketsResponseObject interface {
VisitPostBucketsResponse(w http.ResponseWriter) error
}
type PostBuckets201Response struct {
}
func (response PostBuckets201Response) VisitPostBucketsResponse(w http.ResponseWriter) error {
w.WriteHeader(201)
return nil
}
type PostBuckets400Response struct {
}
func (response PostBuckets400Response) VisitPostBucketsResponse(w http.ResponseWriter) error {
w.WriteHeader(400)
return nil
}
type PostBuckets409Response struct {
}
func (response PostBuckets409Response) VisitPostBucketsResponse(w http.ResponseWriter) error {
w.WriteHeader(409)
return nil
}
type DeleteBucketsBucketNameRequestObject struct {
BucketName string `json:"bucketName"`
}
type DeleteBucketsBucketNameResponseObject interface {
VisitDeleteBucketsBucketNameResponse(w http.ResponseWriter) error
}
type DeleteBucketsBucketName204Response struct {
}
func (response DeleteBucketsBucketName204Response) VisitDeleteBucketsBucketNameResponse(w http.ResponseWriter) error {
w.WriteHeader(204)
return nil
}
type DeleteBucketsBucketName404Response struct {
}
func (response DeleteBucketsBucketName404Response) VisitDeleteBucketsBucketNameResponse(w http.ResponseWriter) error {
w.WriteHeader(404)
return nil
}
type DeleteBucketsBucketName500Response struct {
}
func (response DeleteBucketsBucketName500Response) VisitDeleteBucketsBucketNameResponse(w http.ResponseWriter) error {
w.WriteHeader(500)
return nil
}
type GetBucketsBucketNameObjectsRequestObject struct {
BucketName string `json:"bucketName"`
Params GetBucketsBucketNameObjectsParams
}
type GetBucketsBucketNameObjectsResponseObject interface {
VisitGetBucketsBucketNameObjectsResponse(w http.ResponseWriter) error
}
type GetBucketsBucketNameObjects200JSONResponse struct {
Items *[]Object `json:"items,omitempty"`
// Limit Maximum number of items returned in the response
Limit *int `json:"limit,omitempty"`
// Offset Number of items skipped before starting the response
Offset *int `json:"offset,omitempty"`
// Total Total number of objects available in the bucket
Total *int `json:"total,omitempty"`
}
func (response GetBucketsBucketNameObjects200JSONResponse) VisitGetBucketsBucketNameObjectsResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
return json.NewEncoder(w).Encode(response)
}
type GetBucketsBucketNameObjects404Response struct {
}
func (response GetBucketsBucketNameObjects404Response) VisitGetBucketsBucketNameObjectsResponse(w http.ResponseWriter) error {
w.WriteHeader(404)
return nil
}
type DeleteBucketsBucketNameObjectsObjectKeyRequestObject struct {
BucketName string `json:"bucketName"`
ObjectKey string `json:"objectKey"`
}
type DeleteBucketsBucketNameObjectsObjectKeyResponseObject interface {
VisitDeleteBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error
}
type DeleteBucketsBucketNameObjectsObjectKey204Response struct {
}
func (response DeleteBucketsBucketNameObjectsObjectKey204Response) VisitDeleteBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error {
w.WriteHeader(204)
return nil
}
type DeleteBucketsBucketNameObjectsObjectKey404Response struct {
}
func (response DeleteBucketsBucketNameObjectsObjectKey404Response) VisitDeleteBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error {
w.WriteHeader(404)
return nil
}
type DeleteBucketsBucketNameObjectsObjectKey500Response struct {
}
func (response DeleteBucketsBucketNameObjectsObjectKey500Response) VisitDeleteBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error {
w.WriteHeader(500)
return nil
}
type GetBucketsBucketNameObjectsObjectKeyRequestObject struct {
BucketName string `json:"bucketName"`
ObjectKey string `json:"objectKey"`
}
type GetBucketsBucketNameObjectsObjectKeyResponseObject interface {
VisitGetBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error
}
type GetBucketsBucketNameObjectsObjectKey200ApplicationoctetStreamResponse struct {
Body io.Reader
ContentLength int64
}
func (response GetBucketsBucketNameObjectsObjectKey200ApplicationoctetStreamResponse) VisitGetBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/octet-stream")
if response.ContentLength != 0 {
w.Header().Set("Content-Length", fmt.Sprint(response.ContentLength))
}
w.WriteHeader(200)
if closer, ok := response.Body.(io.ReadCloser); ok {
defer closer.Close()
}
_, err := io.Copy(w, response.Body)
return err
}
type GetBucketsBucketNameObjectsObjectKey404Response struct {
}
func (response GetBucketsBucketNameObjectsObjectKey404Response) VisitGetBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error {
w.WriteHeader(404)
return nil
}
type PutBucketsBucketNameObjectsObjectKeyRequestObject struct {
BucketName string `json:"bucketName"`
ObjectKey string `json:"objectKey"`
Body io.Reader
}
type PutBucketsBucketNameObjectsObjectKeyResponseObject interface {
VisitPutBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error
}
type PutBucketsBucketNameObjectsObjectKey201Response struct {
}
func (response PutBucketsBucketNameObjectsObjectKey201Response) VisitPutBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error {
w.WriteHeader(201)
return nil
}
type PutBucketsBucketNameObjectsObjectKey400Response struct {
}
func (response PutBucketsBucketNameObjectsObjectKey400Response) VisitPutBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error {
w.WriteHeader(400)
return nil
}
type PutBucketsBucketNameObjectsObjectKey500Response struct {
}
func (response PutBucketsBucketNameObjectsObjectKey500Response) VisitPutBucketsBucketNameObjectsObjectKeyResponse(w http.ResponseWriter) error {
w.WriteHeader(500)
return nil
}
// StrictServerInterface represents all server handlers.
type StrictServerInterface interface {
// List all buckets
// (GET /buckets)
GetBuckets(ctx context.Context, request GetBucketsRequestObject) (GetBucketsResponseObject, error)
// Create a new bucket
// (POST /buckets)
PostBuckets(ctx context.Context, request PostBucketsRequestObject) (PostBucketsResponseObject, error)
// Delete a bucket
// (DELETE /buckets/{bucketName})
DeleteBucketsBucketName(ctx context.Context, request DeleteBucketsBucketNameRequestObject) (DeleteBucketsBucketNameResponseObject, error)
// List objects in a bucket
// (GET /buckets/{bucketName}/objects)
GetBucketsBucketNameObjects(ctx context.Context, request GetBucketsBucketNameObjectsRequestObject) (GetBucketsBucketNameObjectsResponseObject, error)
// Delete an object
// (DELETE /buckets/{bucketName}/objects/{objectKey})
DeleteBucketsBucketNameObjectsObjectKey(ctx context.Context, request DeleteBucketsBucketNameObjectsObjectKeyRequestObject) (DeleteBucketsBucketNameObjectsObjectKeyResponseObject, error)
// Get object
// (GET /buckets/{bucketName}/objects/{objectKey})
GetBucketsBucketNameObjectsObjectKey(ctx context.Context, request GetBucketsBucketNameObjectsObjectKeyRequestObject) (GetBucketsBucketNameObjectsObjectKeyResponseObject, error)
// Upload an object
// (PUT /buckets/{bucketName}/objects/{objectKey})
PutBucketsBucketNameObjectsObjectKey(ctx context.Context, request PutBucketsBucketNameObjectsObjectKeyRequestObject) (PutBucketsBucketNameObjectsObjectKeyResponseObject, error)
}
type StrictHandlerFunc = strictnethttp.StrictHTTPHandlerFunc
type StrictMiddlewareFunc = strictnethttp.StrictHTTPMiddlewareFunc
type StrictHTTPServerOptions struct {
RequestErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
ResponseErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc) ServerInterface {
return &strictHandler{ssi: ssi, middlewares: middlewares, options: StrictHTTPServerOptions{
RequestErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusBadRequest)
},
ResponseErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusInternalServerError)
},
}}
}
func NewStrictHandlerWithOptions(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc, options StrictHTTPServerOptions) ServerInterface {
return &strictHandler{ssi: ssi, middlewares: middlewares, options: options}
}
type strictHandler struct {
ssi StrictServerInterface
middlewares []StrictMiddlewareFunc
options StrictHTTPServerOptions
}
// GetBuckets operation middleware
func (sh *strictHandler) GetBuckets(w http.ResponseWriter, r *http.Request, params GetBucketsParams) {
var request GetBucketsRequestObject
request.Params = params
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.GetBuckets(ctx, request.(GetBucketsRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "GetBuckets")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(GetBucketsResponseObject); ok {
if err := validResponse.VisitGetBucketsResponse(w); err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
}
} else if response != nil {
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
}
}
// PostBuckets operation middleware
func (sh *strictHandler) PostBuckets(w http.ResponseWriter, r *http.Request) {
var request PostBucketsRequestObject
var body PostBucketsJSONRequestBody
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't decode JSON body: %w", err))
return
}
request.Body = &body
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.PostBuckets(ctx, request.(PostBucketsRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "PostBuckets")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(PostBucketsResponseObject); ok {
if err := validResponse.VisitPostBucketsResponse(w); err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
}
} else if response != nil {
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
}
}
// DeleteBucketsBucketName operation middleware
func (sh *strictHandler) DeleteBucketsBucketName(w http.ResponseWriter, r *http.Request, bucketName string) {
var request DeleteBucketsBucketNameRequestObject
request.BucketName = bucketName
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.DeleteBucketsBucketName(ctx, request.(DeleteBucketsBucketNameRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "DeleteBucketsBucketName")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(DeleteBucketsBucketNameResponseObject); ok {
if err := validResponse.VisitDeleteBucketsBucketNameResponse(w); err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
}
} else if response != nil {
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
}
}
// GetBucketsBucketNameObjects operation middleware
func (sh *strictHandler) GetBucketsBucketNameObjects(w http.ResponseWriter, r *http.Request, bucketName string, params GetBucketsBucketNameObjectsParams) {
var request GetBucketsBucketNameObjectsRequestObject
request.BucketName = bucketName
request.Params = params
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.GetBucketsBucketNameObjects(ctx, request.(GetBucketsBucketNameObjectsRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "GetBucketsBucketNameObjects")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(GetBucketsBucketNameObjectsResponseObject); ok {
if err := validResponse.VisitGetBucketsBucketNameObjectsResponse(w); err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
}
} else if response != nil {
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
}
}
// DeleteBucketsBucketNameObjectsObjectKey operation middleware
func (sh *strictHandler) DeleteBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request, bucketName string, objectKey string) {
var request DeleteBucketsBucketNameObjectsObjectKeyRequestObject
request.BucketName = bucketName
request.ObjectKey = objectKey
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.DeleteBucketsBucketNameObjectsObjectKey(ctx, request.(DeleteBucketsBucketNameObjectsObjectKeyRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "DeleteBucketsBucketNameObjectsObjectKey")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(DeleteBucketsBucketNameObjectsObjectKeyResponseObject); ok {
if err := validResponse.VisitDeleteBucketsBucketNameObjectsObjectKeyResponse(w); err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
}
} else if response != nil {
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
}
}
// GetBucketsBucketNameObjectsObjectKey operation middleware
func (sh *strictHandler) GetBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request, bucketName string, objectKey string) {
var request GetBucketsBucketNameObjectsObjectKeyRequestObject
request.BucketName = bucketName
request.ObjectKey = objectKey
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.GetBucketsBucketNameObjectsObjectKey(ctx, request.(GetBucketsBucketNameObjectsObjectKeyRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "GetBucketsBucketNameObjectsObjectKey")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(GetBucketsBucketNameObjectsObjectKeyResponseObject); ok {
if err := validResponse.VisitGetBucketsBucketNameObjectsObjectKeyResponse(w); err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
}
} else if response != nil {
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
}
}
// PutBucketsBucketNameObjectsObjectKey operation middleware
func (sh *strictHandler) PutBucketsBucketNameObjectsObjectKey(w http.ResponseWriter, r *http.Request, bucketName string, objectKey string) {
var request PutBucketsBucketNameObjectsObjectKeyRequestObject
request.BucketName = bucketName
request.ObjectKey = objectKey
request.Body = r.Body
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.PutBucketsBucketNameObjectsObjectKey(ctx, request.(PutBucketsBucketNameObjectsObjectKeyRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "PutBucketsBucketNameObjectsObjectKey")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(PutBucketsBucketNameObjectsObjectKeyResponseObject); ok {
if err := validResponse.VisitPutBucketsBucketNameObjectsObjectKeyResponse(w); err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
}
} else if response != nil {
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
}
}
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
2024-11-13 21:16:22 +01:00
"H4sIAAAAAAAC/+xYS28bNxD+KwTbQwvIktymh+6pcQsERh826vRUBAG1Oysx5ivkrGzV0H8vhuRKK+3K",
"VmS3KIrcKD5mhvN9Mx9XD7y02lkDBgMvHngoF6BFHF405S0gjZy3DjxKiPOlB4FQvRdxrYJQeulQWsML",
"/iOtSWsYSg0BhXbM1gwXwGbJ2ojX1ms6yiuBcEb7+IjjygEveEAvzZyvR9wIDX3zbxfAaKVndO/8ejNj",
"Zx+gRLJ4lUa969zCatjRLazYV7ICg7KW4L9unWaTA0ErEfC9thXtr4aN0hbWbulnaWP7uCwF+deBLNHK",
"rlEmDZutEMLWkDQIc/BD+aIpaWobAbcGRUodaCEVhdA4Zz3+APdCOwXj0mregsZfX1+ym7SBgtwNjhZr",
"65kWRsylmefoAoUnTBtrQOvFHFgAv5QljClmiYqsJxzZTd7x+vqSj/gSfEj2z8fT8ZTcWgdGOMkL/m2c",
"GnEncBEhnyTexPEcBmj8O6CXsAQmmKMoie9MyYCUUqFUJl4MupPhHDVFSwyLlXBZ8YK/AbzILikMLzQg",
"+MCLP4ew0+Je6kYz0+gZeHIpEXRgaJkHbLzhhA0v+McG/GqbdyW1JO6kGk63qkWjkBfn0+kQ6oP11fca",
"bqVjM6itBxZQeCTc0LLSKkX3phR4CI1CFmI5DkVn6zotDoQ3FNy7EfcQnDUh1ek302lLRjARM+GckmXM",
"8uRDoAs8dIzvVnm8y87gSw81L/gXk20DnOTuN8mtb1sWwnuxir8tCjVQcjTdSV3LD7EUUomZgqOLbq9a",
"BviXbY8pnO9SUnYP3YBfgmfgvU1uQqO18Cte8F/IRofAZMPZcKiTUwEYuMu7IxWQSJBrtk/0axs6TPfw",
"sYGAF7ZaPQO6YSn4rScDFN4MWJYnPuK5OfGC69WZgbuz4+WCpih66amRo29g3aPjeT+odPU2BBaasoQQ",
"6kapSJ5XQ2hdiIrlRKU93x+0K5QHUa0Y3MtA2O1AOwBY3NE2u8lDGlDi1smFAhzI7E9xnok2rcJUkTIS",
"w2Hg06EM/cXG0THtzgwimaPLvYRa97aVzLr2d2Hqtpd9lPsd5dXBVCf3QxAePmMssto2pjqlMveyfhi6",
"ScbgNPFq1fZO4oIUlwUHZXqMJB+PidcW16scw0nwviioo39NQT8L6PECerV5du8LaEpxj7S/HkAswQVV",
"+9JqbzSgp6M2Q32t2DNKcDhi/D4iTzk4Uv3bItuofxv9vgA9+y3QeTxv7Y8/oVH1Xwfd9/jRzWjykAY/",
"w+oobdk89GtvdQz96T50QGJyK7pq/f9Xe9KTn5MD/m3nUi+sc/kz6hSds75F70UUr+UC2XhC0E6hzSPy",
"9Zkzj3DmMbGwJQKeBfQg9K5obP63mEkjonrte+r1tbex68YHMFQtwJVAcRIPdyj2BrBDLtcMkOsPp6yo",
"8rM5myPDS/B3XiZ+xvd2/K/CbFr508S7bv5HxKut/yeZd8x34jNJd8LnXO6RTaTIsd9zl2YplOwR+VO7",
"Y8vLbXeM6/FAYkrjFS/4AtGFYjIRTo47/8ZNlud8/W79dwAAAP//MM2B5t8VAAA=",
2024-11-12 22:12:41 +01:00
}
// GetSwagger returns the content of the embedded swagger specification file
// or error if failed to decode
func decodeSpec() ([]byte, error) {
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
if err != nil {
return nil, fmt.Errorf("error base64 decoding spec: %w", err)
}
zr, err := gzip.NewReader(bytes.NewReader(zipped))
if err != nil {
return nil, fmt.Errorf("error decompressing spec: %w", err)
}
var buf bytes.Buffer
_, err = buf.ReadFrom(zr)
if err != nil {
return nil, fmt.Errorf("error decompressing spec: %w", err)
}
return buf.Bytes(), nil
}
var rawSpec = decodeSpecCached()
// a naive cached of a decoded swagger spec
func decodeSpecCached() func() ([]byte, error) {
data, err := decodeSpec()
return func() ([]byte, error) {
return data, err
}
}
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
res := make(map[string]func() ([]byte, error))
if len(pathToFile) > 0 {
res[pathToFile] = rawSpec
}
return res
}
// GetSwagger returns the Swagger specification corresponding to the generated code
// in this file. The external references of Swagger specification are resolved.
// The logic of resolving external references is tightly connected to "import-mapping" feature.
// Externally referenced files must be embedded in the corresponding golang packages.
// Urls can be supported but this task was out of the scope.
func GetSwagger() (swagger *openapi3.T, err error) {
resolvePath := PathToRawSpec("")
loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
pathToFile := url.String()
pathToFile = path.Clean(pathToFile)
getSpec, ok := resolvePath[pathToFile]
if !ok {
err1 := fmt.Errorf("path not found: %s", pathToFile)
return nil, err1
}
return getSpec()
}
var specData []byte
specData, err = rawSpec()
if err != nil {
return
}
swagger, err = loader.LoadFromData(specData)
if err != nil {
return
}
return
}