generated

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 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 AssertContextAreaConstraints

func AssertContextAreaConstraints(obj ContextArea) error

AssertContextAreaConstraints checks if the values respects the defined constraints

func AssertContextAreaRequired

func AssertContextAreaRequired(obj ContextArea) error

AssertContextAreaRequired checks if the required fields are not zero-ed

func AssertElementSpecConstraints

func AssertElementSpecConstraints(obj ElementSpec) error

AssertElementSpecConstraints checks if the values respects the defined constraints

func AssertElementSpecRequired

func AssertElementSpecRequired(obj ElementSpec) error

AssertElementSpecRequired checks if the required fields are not zero-ed

func AssertMicrofrontendResourceConstraints

func AssertMicrofrontendResourceConstraints(obj MicrofrontendResource) error

AssertMicrofrontendResourceConstraints checks if the values respects the defined constraints

func AssertMicrofrontendResourceRequired

func AssertMicrofrontendResourceRequired(obj MicrofrontendResource) error

AssertMicrofrontendResourceRequired checks if the required fields are not zero-ed

func AssertMicrofrontendSpecConstraints

func AssertMicrofrontendSpecConstraints(obj MicrofrontendSpec) error

AssertMicrofrontendSpecConstraints checks if the values respects the defined constraints

func AssertMicrofrontendSpecRequired

func AssertMicrofrontendSpecRequired(obj MicrofrontendSpec) error

AssertMicrofrontendSpecRequired checks if the required fields are not zero-ed

func AssertRecurseInterfaceRequired

func AssertRecurseInterfaceRequired[T any](obj interface{}, callback func(T) error) error

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

func AssertRecurseValueRequired

func AssertRecurseValueRequired[T any](value reflect.Value, callback func(T) error) error

AssertRecurseValueRequired checks each struct in the nested slice against the callback. This method traverse nested slices in a preorder fashion. ErrTypeAssertionError is thrown if the underlying struct does not match type T.

func AssertStaticConfigAreaConstraints

func AssertStaticConfigAreaConstraints(obj StaticConfigArea) error

AssertStaticConfigAreaConstraints checks if the values respects the defined constraints

func AssertStaticConfigAreaRequired

func AssertStaticConfigAreaRequired(obj StaticConfigArea) error

AssertStaticConfigAreaRequired checks if the required fields are not zero-ed

func AssertStaticConfigConstraints

func AssertStaticConfigConstraints(obj StaticConfig) error

AssertStaticConfigConstraints checks if the values respects the defined constraints

func AssertStaticConfigRequired

func AssertStaticConfigRequired(obj StaticConfig) error

AssertStaticConfigRequired 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, headers map[string][]string, 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 Constraint

type Constraint[T Number | string | bool] func(actual T) error

func WithMaximum

func WithMaximum[T Number](expected T) Constraint[T]

func WithMinimum

func WithMinimum[T Number](expected T) Constraint[T]

type ContextArea

type ContextArea struct {

	// The elements to be incorporated into the context area.  These elements will be rendered in the sequence they appear in the array.
	Elements []ElementSpec `json:"elements"`

	// The microfrontends referenced by any of the elements. The browser triggers the loading of microfrontend resources when the element is rendered.
	Microfrontends map[string]MicrofrontendSpec `json:"microfrontends,omitempty"`
}

ContextArea - Elements to be inserted into the microfrontend context area. The context area refers to a section in the document flow, the content of which depends on the system's configuration. For instance, the context area `top-level-application` could be used to render the top-level application tiles.

type ElementSpec

type ElementSpec struct {

	// The name of the microfrontend to which the element belongs. The browser  loads the microfrontend before rendering the element.  If this property is not provided, it's assumed that the browser has already  loaded all necessary resources for the element prior to rendering.
	Microfrontend string `json:"microfrontend,omitempty"`

	// The name of the element, which corresponds to its tag name used in the document flow.
	TagName string `json:"tagName"`

	// Attributes to be assigned to the element during rendering.
	Attributes map[string]string `json:"attributes,omitempty"`

	// The styles of the element. Primarily intended as a fallback for specific cases,  such as setting CSS variables.
	Style map[string]string `json:"style,omitempty"`
}

ElementSpec - Specification of the element. Elements serve as the building blocks of the application. Each element should be a web component rendered by the browser. When rendered in context, such as with the `polyfea-context` element, the `context` attribute is set to the name of the context area.

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 ImplResponse

type ImplResponse struct {
	Code    int
	Headers map[string][]string
	Body    interface{}
}

ImplResponse defines an implementation response with error code and the associated body

func Response

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

Response return a ImplResponse struct filled

func ResponseWithHeaders

func ResponseWithHeaders(code int, headers map[string][]string, body interface{}) ImplResponse

ResponseWithHeaders return a ImplResponse struct filled, including headers

type MicrofrontendResource

type MicrofrontendResource struct {

	// The type of the resource. This could be a script, stylesheet, or any other `link` element.
	Kind string `json:"kind,omitempty"`

	// The URL of the resource. This URL is usually relative to the application's base URL  and is typically served as a subpath  of `<base_href>/polyfea/webcomponent/<microfrontend-name>/<resource-path...>`.
	Href string `json:"href,omitempty"`

	// Additional attributes to be assigned to the `link` or `script` element,  alongside the `rel` and `href` attributes.
	Attributes map[string]string `json:"attributes,omitempty"`

	// If set to `true`, the browser will complete loading the resource before it finishes  loading the microfrontend. If set to `false`, the browser will load the resource  asynchronously, allowing for continued loading and rendering in the meantime.
	WaitOnLoad bool `json:"waitOnLoad,omitempty"`
}

MicrofrontendResource - The resource that the microfrontend requires. This resource could be a script, stylesheet, or any other `link` element. The browser loads this resource when the microfrontend is requested. The loading process can occur either synchronously or asynchronously.

type MicrofrontendSpec

type MicrofrontendSpec struct {

	// The microfrontends that this microfrontend depends on.  The specification of these dependencies is provided in the context area information.
	DependsOn []string `json:"dependsOn,omitempty"`

	// A shorthand for the microfrontend script module resource. The browser loads this module before rendering the elements. If the module has dependencies on other resources, it may load them itself, provided their references are given as a relative path to the module.
	Module string `json:"module,omitempty"`

	// The resources that the browser should load. Only resources that need to be directly  loaded into the document's `head` element should be specified here. Typical examples  include fonts and stylesheets that must be globally available.
	Resources []MicrofrontendResource `json:"resources,omitempty"`
}

MicrofrontendSpec - Specification of the microfrontend. Microfrontend resources are loaded by the browser as needed. Each microfrontend comprises a set of resources that are loaded prior to, or in parallel with, the rendering of microfrontend elements. Additionally, a microfrontend can have dependencies on other microfrontends.

type Number

type Number interface {
	~int32 | ~int64 | ~float32 | ~float64
}

type Operation

type Operation[T Number | string | bool] func(actual string) (T, bool, error)

func WithDefaultOrParse

func WithDefaultOrParse[T Number | string | bool](def T, parse ParseString[T]) Operation[T]

func WithParse

func WithParse[T Number | string | bool](parse ParseString[T]) Operation[T]

func WithRequire

func WithRequire[T Number | string | bool](parse ParseString[T]) Operation[T]

type ParseString

type ParseString[T Number | string | bool] func(v string) (T, error)

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 PolyfeaAPIController

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

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

func (*PolyfeaAPIController) GetContextArea

func (c *PolyfeaAPIController) GetContextArea(w http.ResponseWriter, r *http.Request)

GetContextArea - Get the context area information.

func (*PolyfeaAPIController) GetStaticConfig

func (c *PolyfeaAPIController) GetStaticConfig(w http.ResponseWriter, r *http.Request)

GetStaticConfig - Get the static information about all resources and context areas.

func (*PolyfeaAPIController) Routes

func (c *PolyfeaAPIController) Routes() Routes

Routes returns all the api routes for the PolyfeaAPIController

type PolyfeaAPIOption

type PolyfeaAPIOption func(*PolyfeaAPIController)

PolyfeaAPIOption for how the controller is set up.

func WithPolyfeaAPIErrorHandler

func WithPolyfeaAPIErrorHandler(h ErrorHandler) PolyfeaAPIOption

WithPolyfeaAPIErrorHandler inject ErrorHandler into controller

type PolyfeaAPIRouter

type PolyfeaAPIRouter interface {
	GetContextArea(http.ResponseWriter, *http.Request, http.Header)
	GetStaticConfig(http.ResponseWriter, *http.Request, http.Header)
}

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

type PolyfeaAPIServicer

type PolyfeaAPIServicer interface {
	GetContextArea(context.Context, string, string, int32, http.Header) (ImplResponse, error)
	GetStaticConfig(context.Context, http.Header) (ImplResponse, error)
}

PolyfeaAPIServicer defines the api actions for the PolyfeaAPI 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.

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 {
	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 NewPolyfeaAPIController

func NewPolyfeaAPIController(s PolyfeaAPIServicer, opts ...PolyfeaAPIOption) Router

NewPolyfeaAPIController creates a default api controller

type Routes

type Routes map[string]Route

Routes is a map of defined api endpoints

type StaticConfig

type StaticConfig struct {

	// A list of context areas along with their elements. Each context area is identified by its  name and the regex path where it's rendered. In the event of a conflict, the first matching  context area is selected.
	ContextAreas []StaticConfigArea `json:"contextAreas,omitempty"`

	// A dictionary of microfrontends, each identified by its unique name.
	Microfrontends map[string]MicrofrontendSpec `json:"microfrontends"`
}

StaticConfig - Specification of the application's static configuration. This configuration is a compilation of all contexts/paths and their elements. It's particularly useful during development, testing, or for simpler applications.

type StaticConfigArea

type StaticConfigArea struct {

	// Name of the context area.
	Name string `json:"name"`

	// The regular expression used to match the path relative to the base href  where this context area should be applied. If no path is provided, the  context area specification applies to all paths. In the event of conflicts,  the first matching context area is used.
	Path string `json:"path,omitempty"`

	ContextArea ContextArea `json:"contextArea,omitempty"`
}

StaticConfigArea - Specification of the static configuration for a context area, identified by a specific name and path regex.

Jump to

Keyboard shortcuts

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