server

package
v0.0.0-...-0eb5a07 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTypeAssertionError is thrown when type an interface does not match the asserted type
	ErrTypeAssertionError = errors.New("unable to assert type")
)

Functions

func AssertConfigurationRequired

func AssertConfigurationRequired(obj Configuration) error

AssertConfigurationRequired checks if the required fields are not zero-ed

func AssertConfigurationSourceRequired

func AssertConfigurationSourceRequired(obj ConfigurationSource) error

AssertConfigurationSourceRequired checks if the required fields are not zero-ed

func AssertConfigurationTweakwiseRequired

func AssertConfigurationTweakwiseRequired(obj ConfigurationTweakwise) error

AssertConfigurationTweakwiseRequired checks if the required fields are not zero-ed

func AssertGcpSourceAllOfRequired

func AssertGcpSourceAllOfRequired(obj GcpSourceAllOf) error

AssertGcpSourceAllOfRequired checks if the required fields are not zero-ed

func AssertGcpSourceRequired

func AssertGcpSourceRequired(obj GcpSource) error

AssertGcpSourceRequired checks if the required fields are not zero-ed

func AssertRecurseConfigurationRequired

func AssertRecurseConfigurationRequired(objSlice interface{}) error

AssertRecurseConfigurationRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of Configuration (e.g. [][]Configuration), otherwise ErrTypeAssertionError is thrown.

func AssertRecurseConfigurationSourceRequired

func AssertRecurseConfigurationSourceRequired(objSlice interface{}) error

AssertRecurseConfigurationSourceRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of ConfigurationSource (e.g. [][]ConfigurationSource), otherwise ErrTypeAssertionError is thrown.

func AssertRecurseConfigurationTweakwiseRequired

func AssertRecurseConfigurationTweakwiseRequired(objSlice interface{}) error

AssertRecurseConfigurationTweakwiseRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of ConfigurationTweakwise (e.g. [][]ConfigurationTweakwise), otherwise ErrTypeAssertionError is thrown.

func AssertRecurseGcpSourceAllOfRequired

func AssertRecurseGcpSourceAllOfRequired(objSlice interface{}) error

AssertRecurseGcpSourceAllOfRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of GcpSourceAllOf (e.g. [][]GcpSourceAllOf), otherwise ErrTypeAssertionError is thrown.

func AssertRecurseGcpSourceRequired

func AssertRecurseGcpSourceRequired(objSlice interface{}) error

AssertRecurseGcpSourceRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of GcpSource (e.g. [][]GcpSource), otherwise ErrTypeAssertionError is thrown.

func AssertRecurseInterfaceRequired

func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error

AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. This method traverse nested slices in a preorder fashion.

func AssertRecurseSourceRequired

func AssertRecurseSourceRequired(objSlice interface{}) error

AssertRecurseSourceRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of Source (e.g. [][]Source), otherwise ErrTypeAssertionError is thrown.

func AssertRecurseValueRequired

func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error

AssertRecurseValueRequired checks each struct in the nested slice against the callback. This method traverse nested slices in a preorder fashion.

func AssertSourceRequired

func AssertSourceRequired(obj Source) error

AssertSourceRequired checks if the required fields are not zero-ed

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)

DefaultErrorHandler defines the default logic on how to handle errors from the controller. Any errors from parsing request params will return a StatusBadRequest. Otherwise, the error code originating from the servicer will be used.

func EncodeJSONResponse

func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error

EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code

func IsZeroValue

func IsZeroValue(val interface{}) bool

IsZeroValue checks if the val is the zero-ed value.

func Logger

func Logger(inner http.Handler, name string) http.Handler

func NewRouter

func NewRouter(routers ...Router) *mux.Router

NewRouter creates a new router for any number of api routers

func ReadFormFileToTempFile

func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error)

ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file

func ReadFormFilesToTempFiles

func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error)

ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files

Types

type Configuration

type Configuration struct {
	Tweakwise ConfigurationTweakwise `json:"tweakwise"`

	Source ConfigurationSource `json:"source"`
}

type ConfigurationApiController

type ConfigurationApiController struct {
	// contains filtered or unexported fields
}

ConfigurationApiController binds http requests to an api service and writes the service results to the http response

func (*ConfigurationApiController) ConfigurationGet

func (c *ConfigurationApiController) ConfigurationGet(w http.ResponseWriter, r *http.Request)

ConfigurationGet - Fetch the current configuration

func (*ConfigurationApiController) ConfigurationPost

func (c *ConfigurationApiController) ConfigurationPost(w http.ResponseWriter, r *http.Request)

ConfigurationPost - Create a new configuration option

func (*ConfigurationApiController) Routes

func (c *ConfigurationApiController) Routes() Routes

Routes returns all the api routes for the ConfigurationApiController

type ConfigurationApiOption

type ConfigurationApiOption func(*ConfigurationApiController)

ConfigurationApiOption for how the controller is set up.

func WithConfigurationApiErrorHandler

func WithConfigurationApiErrorHandler(h ErrorHandler) ConfigurationApiOption

WithConfigurationApiErrorHandler inject ErrorHandler into controller

type ConfigurationApiRouter

type ConfigurationApiRouter interface {
	ConfigurationGet(http.ResponseWriter, *http.Request)
	ConfigurationPost(http.ResponseWriter, *http.Request)
}

ConfigurationApiRouter defines the required methods for binding the api requests to a responses for the ConfigurationApi The ConfigurationApiRouter implementation should parse necessary information from the http request, pass the data to a ConfigurationApiServicer to perform the required actions, then write the service results to the http response.

type ConfigurationApiService

type ConfigurationApiService struct {
}

ConfigurationApiService is a service that implements the logic for the ConfigurationApiServicer This service should implement the business logic for every endpoint for the ConfigurationApi API. Include any external packages or services that will be required by this service.

func (*ConfigurationApiService) ConfigurationGet

func (s *ConfigurationApiService) ConfigurationGet(ctx context.Context) (ImplResponse, error)

ConfigurationGet - Fetch the current configuration

func (*ConfigurationApiService) ConfigurationPost

func (s *ConfigurationApiService) ConfigurationPost(ctx context.Context, configuration Configuration) (ImplResponse, error)

ConfigurationPost - Create a new configuration option

type ConfigurationApiServicer

type ConfigurationApiServicer interface {
	ConfigurationGet(context.Context) (ImplResponse, error)
	ConfigurationPost(context.Context, Configuration) (ImplResponse, error)
}

ConfigurationApiServicer defines the api actions for the ConfigurationApi service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can be ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

func NewConfigurationApiService

func NewConfigurationApiService() ConfigurationApiServicer

NewConfigurationApiService creates a default api service

type ConfigurationSource

type ConfigurationSource struct {
	Type string `json:"type"`

	// The ID of the project that contains the Pub/Sub topic
	ProjectId string `json:"project_id"`

	// Name of the product topic
	ProductTopic string `json:"product_topic"`
}

ConfigurationSource - The source for the subscriptions. Only one is allowed.

type ConfigurationTweakwise

type ConfigurationTweakwise struct {

	// The tweakwise token
	Token string `json:"token"`

	// The tweakwise instance key
	Instance string `json:"instance"`
}

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)

ErrorHandler defines the required method for handling error. You may implement it and inject this into a controller if you would like errors to be handled differently from the DefaultErrorHandler

type GcpSource

type GcpSource struct {
	Type string `json:"type"`

	// The ID of the project that contains the Pub/Sub topic
	ProjectId string `json:"project_id"`

	// Name of the product topic
	ProductTopic string `json:"product_topic"`
}

type GcpSourceAllOf

type GcpSourceAllOf struct {

	// The ID of the project that contains the Pub/Sub topic
	ProjectId string `json:"project_id"`

	// Name of the product topic
	ProductTopic string `json:"product_topic"`
}

GcpSourceAllOf - Use GCP to listen for events. See https://docs.commercetools.com/api/projects/subscriptions#google-cloud-pubsub-destination for more information

type ImplResponse

type ImplResponse struct {
	Code int
	Body interface{}
}

ImplResponse response defines an error code with the associated body

func Response

func Response(code int, body interface{}) ImplResponse

Response return a ImplResponse struct filled

type ManageApiController

type ManageApiController struct {
	// contains filtered or unexported fields
}

ManageApiController binds http requests to an api service and writes the service results to the http response

func (*ManageApiController) ConnectPost

func (c *ManageApiController) ConnectPost(w http.ResponseWriter, r *http.Request)

ConnectPost - Connect the application

func (*ManageApiController) Routes

func (c *ManageApiController) Routes() Routes

Routes returns all the api routes for the ManageApiController

func (*ManageApiController) StartPost

func (c *ManageApiController) StartPost(w http.ResponseWriter, r *http.Request)

StartPost - Start the application

func (*ManageApiController) StopPost

func (c *ManageApiController) StopPost(w http.ResponseWriter, r *http.Request)

StopPost - Stop the application

type ManageApiOption

type ManageApiOption func(*ManageApiController)

ManageApiOption for how the controller is set up.

func WithManageApiErrorHandler

func WithManageApiErrorHandler(h ErrorHandler) ManageApiOption

WithManageApiErrorHandler inject ErrorHandler into controller

type ManageApiRouter

type ManageApiRouter interface {
	ConnectPost(http.ResponseWriter, *http.Request)
	StartPost(http.ResponseWriter, *http.Request)
	StopPost(http.ResponseWriter, *http.Request)
}

ManageApiRouter defines the required methods for binding the api requests to a responses for the ManageApi The ManageApiRouter implementation should parse necessary information from the http request, pass the data to a ManageApiServicer to perform the required actions, then write the service results to the http response.

type ManageApiService

type ManageApiService struct {
}

ManageApiService is a service that implements the logic for the ManageApiServicer This service should implement the business logic for every endpoint for the ManageApi API. Include any external packages or services that will be required by this service.

func (*ManageApiService) ConnectPost

func (s *ManageApiService) ConnectPost(ctx context.Context) (ImplResponse, error)

ConnectPost - Connect the application

func (*ManageApiService) StartPost

func (s *ManageApiService) StartPost(ctx context.Context) (ImplResponse, error)

StartPost - Start the application

func (*ManageApiService) StopPost

func (s *ManageApiService) StopPost(ctx context.Context) (ImplResponse, error)

StopPost - Stop the application

type ManageApiServicer

type ManageApiServicer interface {
	ConnectPost(context.Context) (ImplResponse, error)
	StartPost(context.Context) (ImplResponse, error)
	StopPost(context.Context) (ImplResponse, error)
}

ManageApiServicer defines the api actions for the ManageApi service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can be ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

func NewManageApiService

func NewManageApiService() ManageApiServicer

NewManageApiService creates a default api service

type ParsingError

type ParsingError struct {
	Err error
}

ParsingError indicates that an error has occurred when parsing request parameters

func (*ParsingError) Error

func (e *ParsingError) Error() string

func (*ParsingError) Unwrap

func (e *ParsingError) Unwrap() error

type RequiredError

type RequiredError struct {
	Field string
}

RequiredError indicates that an error has occurred when parsing request parameters

func (*RequiredError) Error

func (e *RequiredError) Error() string

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

A Route defines the parameters for an api endpoint

type Router

type Router interface {
	Routes() Routes
}

Router defines the required methods for retrieving api routes

func NewConfigurationApiController

func NewConfigurationApiController(s ConfigurationApiServicer, opts ...ConfigurationApiOption) Router

NewConfigurationApiController creates a default api controller

func NewManageApiController

func NewManageApiController(s ManageApiServicer, opts ...ManageApiOption) Router

NewManageApiController creates a default api controller

type Routes

type Routes []Route

Routes are a collection of defined api endpoints

type Source

type Source struct {
	Type string `json:"type"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL