Documentation
¶
Index ¶
- Constants
- Variables
- func GetMiddlewareGenerator(c gapp.ServiceContainer) (func(string) (func(next gin.HandlerFunc) gin.HandlerFunc, error), error)
- func NewMiddlewareGenerator(cfg gconfig.Manager) (func(string) (func(gin.HandlerFunc) gin.HandlerFunc, error), error)
- type Envelope
- type ListReport
- type Provider
- type Status
- type StatusError
- func (e StatusError) GetCode() string
- func (e StatusError) GetMessage() string
- func (e *StatusError) SetEndpoint(val int) *StatusError
- func (e *StatusError) SetError(err any) *StatusError
- func (e *StatusError) SetMessage(msg string) *StatusError
- func (e *StatusError) SetParam(param int) *StatusError
- func (e *StatusError) SetService(val int) *StatusError
- type StatusErrorList
Constants ¶
const ( // ContainerID defines the default id used to register // the application envelope middleware and related services. ContainerID = gapp.ContainerID + ".rest.envelope" )
Variables ¶
var ( // ErrNilPointer defines a nil pointer argument error ErrNilPointer = gapp.ErrNilPointer // ErrConversion defines a type conversion error ErrConversion = gapp.ErrConversion )
var ( // ConfigPathServiceID defines the config path that used to store the // application service identifier. ConfigPathServiceID = genv.String( "GAPP_REST_ENVELOPE_CONFIG_PATH_SERVER_ID", "service.id") // ConfigPathTransportAcceptList defines the config path that used to // store the application accepted mime types. ConfigPathTransportAcceptList = genv.String( "GAPP_REST_ENVELOPE_CONFIG_PATH_TRANSPORT_ACCEPT_LIST", "rest.accept") // ConfigPathEndpointIDFormat defines the format of the configuration // path where the endpoint identification number can be retrieved. ConfigPathEndpointIDFormat = genv.String( "GAPP_REST_ENVELOPE_CONFIG_PATH_ENDPOINT_ID_FORMAT", "endpoints.%s.id") )
Functions ¶
func GetMiddlewareGenerator ¶
func GetMiddlewareGenerator(c gapp.ServiceContainer) (func(string) (func(next gin.HandlerFunc) gin.HandlerFunc, error), error)
GetMiddlewareGenerator will try to retrieve the registered logging middleware for ok responses instance from the application service container.
func NewMiddlewareGenerator ¶
func NewMiddlewareGenerator(cfg gconfig.Manager) (func(string) (func(gin.HandlerFunc) gin.HandlerFunc, error), error)
NewMiddlewareGenerator returns a middleware generator function based on the application configuration. This middleware generator function should be called with the corresponding endpoint name, so it can generate the appropriate middleware function.
Types ¶
type Envelope ¶
type Envelope struct {
XMLName xml.Name `json:"-" xml:"envelope"`
StatusCode int `json:"-" xml:"-"`
Status *Status `json:"status" xml:"status"`
Report *ListReport `json:"report,omitempty" xml:"report,omitempty"`
Data interface{} `json:"data,omitempty" xml:"data,omitempty"`
}
Envelope identifies the structure of a response structured format.
func NewEnvelope ¶
func NewEnvelope(statusCode int, data interface{}, report *ListReport) *Envelope
NewEnvelope instantiates a new response data envelope structure
func (*Envelope) AddError ¶
func (s *Envelope) AddError(err *StatusError) *Envelope
AddError add a new error to the response envelope instance
func (Envelope) GetStatusCode ¶
GetStatusCode returned the stored enveloped response status code
func (*Envelope) SetEndpoint ¶
SetEndpoint assign the endpoint identifier to all stored error codes
func (*Envelope) SetService ¶
SetService assign the service identifier to all stored error codes
type ListReport ¶
type ListReport struct {
Search string `json:"search" xml:"search"`
Start uint `json:"start" xml:"start"`
Count uint `json:"count" xml:"count"`
Total uint `json:"total" xml:"total"`
Prev string `json:"prev" xml:"prev"`
Next string `json:"next" xml:"next"`
}
ListReport defines the structure of a response list report containing all the request information, but also the total amount of filtering records and links for the previous and next pages
func NewListReport ¶
func NewListReport(search string, start, count, total uint) *ListReport
NewListReport instantiates a new response list report by populating the prev and next link information regarding the given filtering information
type Provider ¶
type Provider struct{}
Provider defines the default envelope provider to be used on the application initialization to register the file system adapter service.
type Status ¶
type Status struct {
Success bool `json:"success" xml:"success"`
Errors StatusErrorList `json:"errors" xml:"errors"`
}
Status defines the structure to manipulate a response status information structure.
func NewStatus ¶
func NewStatus() *Status
NewStatus instantiates a new request result status structure.
func (*Status) AddError ¶
func (s *Status) AddError(err *StatusError) *Status
AddError append a new error to the status error list
func (*Status) SetEndpoint ¶
SetEndpoint assign an endpoint code to all stored errors.
func (*Status) SetService ¶
SetService assign a service code to all stored errors.
type StatusError ¶
type StatusError struct {
Service int `json:"-" xml:"-"`
Endpoint int `json:"-" xml:"-"`
Param int `json:"-" xml:"-"`
Error string `json:"-" xml:"-"`
Code string `json:"code" xml:"code"`
Message string `json:"message" xml:"message"`
}
StatusError defines the structure to manipulate an error structure that hold the information of an execution error and be assigned to the response status error list.
func NewStatusError ¶ added in v1.2.0
func NewStatusError(err any, msg string) *StatusError
NewStatusError instantiates a new error instance.
func (StatusError) GetCode ¶
func (e StatusError) GetCode() string
GetCode retrieves the composed code of the error
func (StatusError) GetMessage ¶
func (e StatusError) GetMessage() string
GetMessage retrieves the message associated to the error
func (*StatusError) SetEndpoint ¶
func (e *StatusError) SetEndpoint(val int) *StatusError
SetEndpoint assigns an endpoint code value to the error.
func (*StatusError) SetError ¶
func (e *StatusError) SetError(err any) *StatusError
SetError assigns a error code value to the error.
func (*StatusError) SetMessage ¶
func (e *StatusError) SetMessage(msg string) *StatusError
SetMessage assigns a message to the error.
func (*StatusError) SetParam ¶
func (e *StatusError) SetParam(param int) *StatusError
SetParam assigns a parameter code value to the error.
func (*StatusError) SetService ¶
func (e *StatusError) SetService(val int) *StatusError
SetService assigns a service code value to the error.
type StatusErrorList ¶
type StatusErrorList []*StatusError
StatusErrorList defines a type of data that holds a list of error structures.
func (StatusErrorList) MarshalXML ¶
func (s StatusErrorList) MarshalXML(e *xml.Encoder, start xml.StartElement) error
MarshalXML serialize the error list into a xml string