Documentation
¶
Index ¶
- Variables
- func GetEntityFromRequest[T any](r *HTTPServiceRequest) (T, error)
- func GetEntityFromResponse[T any](r ServiceResponse) (T, error)
- func GetHttpFromResponse(r ServiceResponse) (*http.Response, error)
- func RegisterSchema(name string, version string, data []byte)
- func RegisterTargetType(name string, targetConstructor TargetConstructor)
- func RegisterTaskType(name string, taskConstructor TaskConstructor)
- func SchemaRegistry() map[string]Schema
- type Aggregate
- type Configurable
- type EchoRouter
- type HTTPMethod
- type HTTPServiceRequest
- func (sr *HTTPServiceRequest) GetAPIName() string
- func (sr *HTTPServiceRequest) GetBody() []byte
- func (sr *HTTPServiceRequest) GetForm() *url.Values
- func (sr *HTTPServiceRequest) GetHeader() http.Header
- func (sr *HTTPServiceRequest) GetID() uuid.UUID
- func (sr *HTTPServiceRequest) GetInternalPath() string
- func (sr *HTTPServiceRequest) GetMethod() HTTPMethod
- func (sr *HTTPServiceRequest) GetMultipart() MultipartDataInterface
- func (sr *HTTPServiceRequest) GetPostForm() *url.Values
- func (sr *HTTPServiceRequest) GetRequestMeta() RequestMetaInterface
- func (sr *HTTPServiceRequest) GetResponse() ServiceResponse
- func (sr *HTTPServiceRequest) GetServiceName() string
- func (sr *HTTPServiceRequest) GetTrailer() http.Header
- func (sr *HTTPServiceRequest) GetURL() *url.URL
- func (sr *HTTPServiceRequest) SetAPIName(name string)
- func (sr *HTTPServiceRequest) SetBody(body []byte)
- func (sr *HTTPServiceRequest) SetForm(form *url.Values)
- func (sr *HTTPServiceRequest) SetHeader(header http.Header)
- func (sr *HTTPServiceRequest) SetID(id uuid.UUID)
- func (sr *HTTPServiceRequest) SetInternalPath(path string)
- func (sr *HTTPServiceRequest) SetMethod(method HTTPMethod)
- func (sr *HTTPServiceRequest) SetMultipart(data MultipartDataInterface)
- func (sr *HTTPServiceRequest) SetPostForm(form *url.Values)
- func (sr *HTTPServiceRequest) SetRequestMeta(meta RequestMetaInterface)
- func (sr *HTTPServiceRequest) SetResponse(response ServiceResponse)
- func (sr *HTTPServiceRequest) SetServiceName(name string)
- func (sr *HTTPServiceRequest) SetTrailer(trailer http.Header)
- func (sr *HTTPServiceRequest) SetURL(url *url.URL)
- type Handler
- type HasPrecedence
- type HttpResponseMeta
- func (rm *HttpResponseMeta) GetHeader() http.Header
- func (rm *HttpResponseMeta) GetOriginalResponse() *http.Response
- func (rm *HttpResponseMeta) GetProto() string
- func (rm *HttpResponseMeta) GetProtoMajor() int
- func (rm *HttpResponseMeta) GetProtoMinor() int
- func (rm *HttpResponseMeta) GetStatus() string
- func (rm *HttpResponseMeta) GetStatusCode() int
- func (rm *HttpResponseMeta) GetTrailer() http.Header
- func (rm *HttpResponseMeta) GetTransferEncoding() []string
- func (rm *HttpResponseMeta) SetHeader(header http.Header)
- func (rm *HttpResponseMeta) SetOriginalResponse(resp *http.Response)
- func (rm *HttpResponseMeta) SetProto(proto string)
- func (rm *HttpResponseMeta) SetProtoMajor(major int)
- func (rm *HttpResponseMeta) SetProtoMinor(minor int)
- func (rm *HttpResponseMeta) SetStatus(status string)
- func (rm *HttpResponseMeta) SetStatusCode(code int)
- func (rm *HttpResponseMeta) SetTrailer(trailer http.Header)
- func (rm *HttpResponseMeta) SetTransferEncoding(encoding []string)
- type HttpServiceResponse
- type Hub
- func (hub *Hub) AddService(svc *Service) error
- func (hub *Hub) GetLogger() *zerolog.Logger
- func (hub *Hub) GetService(apiName string, serviceName string) (*Service, bool)
- func (hub *Hub) GetServices() map[string]*Service
- func (hub *Hub) HandleRequest(r *http.Request) (ServiceResponse, error)
- func (hub *Hub) SetLogger(l *zerolog.Logger)
- type MultipartData
- type MultipartDataInterface
- type NoOpTarget
- type RegisteredTargets
- type RegisteredTaskTypes
- type RequestMeta
- func (rm *RequestMeta) GetContentLength() int64
- func (rm *RequestMeta) GetHost() string
- func (rm *RequestMeta) GetOriginalRequest() *http.Request
- func (rm *RequestMeta) GetParams() map[string]string
- func (rm *RequestMeta) GetProto() string
- func (rm *RequestMeta) GetProtoMajor() int
- func (rm *RequestMeta) GetProtoMinor() int
- func (rm *RequestMeta) GetRemoteAddr() string
- func (rm *RequestMeta) GetRequestURI() string
- func (rm *RequestMeta) GetTransferEncoding() []string
- func (rm *RequestMeta) SetContentLength(length int64)
- func (rm *RequestMeta) SetHost(host string)
- func (rm *RequestMeta) SetOriginalRequest(req *http.Request)
- func (rm *RequestMeta) SetParams(params map[string]string)
- func (rm *RequestMeta) SetProto(proto string)
- func (rm *RequestMeta) SetProtoMajor(major int)
- func (rm *RequestMeta) SetProtoMinor(minor int)
- func (rm *RequestMeta) SetRemoteAddr(addr string)
- func (rm *RequestMeta) SetRequestURI(uri string)
- func (rm *RequestMeta) SetTransferEncoding(encoding []string)
- type RequestMetaInterface
- type ResponseMeta
- type Schema
- type Service
- type ServiceRequest
- type ServiceResponse
- type Target
- type TargetConstructor
- type TargetConstructorFunc
- type Task
- type TaskConstructor
- type TaskConstructorFunc
- type Workflow
- type WorkflowStep
- type WorkflowTasks
Constants ¶
This section is empty.
Variables ¶
var ErrMethodNotConfigured error = fmt.Errorf("error not configured")
ErrMethodNotConfigured is returned when a requested HTTP method is not configured for a service.
Functions ¶
func GetEntityFromRequest ¶
func GetEntityFromRequest[T any](r *HTTPServiceRequest) (T, error)
GetEntityFromRequest unmarshals the request body into a given entity type.
Parameters:
- r: A pointer to a ServiceRequest containing the request data.
Returns:
- T: The unmarshaled entity of type T.
- error: An error if unmarshaling fails, nil otherwise.
func GetEntityFromResponse ¶
func GetEntityFromResponse[T any](r ServiceResponse) (T, error)
GetEntityFromResponse unmarshals the response body into a given entity type.
Parameters:
- r: A pointer to a ServiceResponse containing the response data.
Returns:
- T: The unmarshaled entity of type T.
- error: An error if unmarshaling fails, nil otherwise.
func GetHttpFromResponse ¶
func GetHttpFromResponse(r ServiceResponse) (*http.Response, error)
GetHttpFromResponse converts our custom ServiceResponse back to a standard http.Response.
Parameters:
- r: A pointer to a ServiceResponse to be converted.
Returns:
- *http.Response: A pointer to the converted http.Response.
- error: An error if conversion fails, nil otherwise.
func RegisterSchema ¶
func RegisterTargetType ¶
func RegisterTargetType(name string, targetConstructor TargetConstructor)
func RegisterTaskType ¶
func RegisterTaskType(name string, taskConstructor TaskConstructor)
func SchemaRegistry ¶
Types ¶
type Configurable ¶
type Configurable interface {
Configure(map[string]interface{})
GetConfig() interface{}
}
type EchoRouter ¶
type EchoRouter interface {
CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}
This is a simple interface which specifies echo.Route addition functions which are present on both echo.Echo and echo.Group, since we want to allow using either of them for path registration
type HTTPMethod ¶
type HTTPMethod string
HTTPMethod is a string type representing HTTP methods.
const ( HTTPMethodGET HTTPMethod = "GET" HTTPMethodPOST HTTPMethod = "POST" HTTPMethodPUT HTTPMethod = "PUT" HTTPMethodDELETE HTTPMethod = "DELETE" HTTPMethodHEAD HTTPMethod = "HEAD" HTTPMethodOPTIONS HTTPMethod = "OPTIONS" HTTPMethodPATCH HTTPMethod = "PATCH" HTTPMethodTRACE HTTPMethod = "TRACE" HTTPMethodCONNECT HTTPMethod = "CONNECT" )
Enum values for HTTPMethod
func StringToHTTPMethod ¶
func StringToHTTPMethod(method string) (HTTPMethod, error)
func (HTTPMethod) String ¶
func (m HTTPMethod) String() string
type HTTPServiceRequest ¶
type HTTPServiceRequest struct {
ID uuid.UUID // Unique identifier for the request
ApiName string // Name of the API being called
ServiceName string // Name of the specific service within the API
Method HTTPMethod // HTTP method of the request
URL *url.URL // Full URL of the request
InternalPath string // Internal path after removing prefixes
Body []byte // Raw body of the request
Form *url.Values // URL-encoded form data
PostForm *url.Values // Posted form data
Multipart *MultipartData // Multipart form data, including file uploads
Response *ServiceResponse // Associated response (if any)
RequestMeta RequestMeta // Additional metadata about the request
Header http.Header // HTTP headers
Trailer http.Header // HTTP trailers
}
ServiceRequest represents a standardized request structure used within the service.
func GetRequestFromHttp ¶
func GetRequestFromHttp(r *http.Request) (*HTTPServiceRequest, error)
GetRequestFromHttp converts a standard http.Request to our custom ServiceRequest.
Parameters:
- r: A pointer to an http.Request to be converted.
Returns:
- *ServiceRequest: A pointer to the converted ServiceRequest.
- error: An error if conversion fails, nil otherwise.
func (*HTTPServiceRequest) GetAPIName ¶
func (sr *HTTPServiceRequest) GetAPIName() string
func (*HTTPServiceRequest) GetBody ¶
func (sr *HTTPServiceRequest) GetBody() []byte
func (*HTTPServiceRequest) GetForm ¶
func (sr *HTTPServiceRequest) GetForm() *url.Values
func (*HTTPServiceRequest) GetHeader ¶
func (sr *HTTPServiceRequest) GetHeader() http.Header
func (*HTTPServiceRequest) GetID ¶
func (sr *HTTPServiceRequest) GetID() uuid.UUID
func (*HTTPServiceRequest) GetInternalPath ¶
func (sr *HTTPServiceRequest) GetInternalPath() string
func (*HTTPServiceRequest) GetMethod ¶
func (sr *HTTPServiceRequest) GetMethod() HTTPMethod
func (*HTTPServiceRequest) GetMultipart ¶
func (sr *HTTPServiceRequest) GetMultipart() MultipartDataInterface
func (*HTTPServiceRequest) GetPostForm ¶
func (sr *HTTPServiceRequest) GetPostForm() *url.Values
func (*HTTPServiceRequest) GetRequestMeta ¶
func (sr *HTTPServiceRequest) GetRequestMeta() RequestMetaInterface
func (*HTTPServiceRequest) GetResponse ¶
func (sr *HTTPServiceRequest) GetResponse() ServiceResponse
func (*HTTPServiceRequest) GetServiceName ¶
func (sr *HTTPServiceRequest) GetServiceName() string
func (*HTTPServiceRequest) GetTrailer ¶
func (sr *HTTPServiceRequest) GetTrailer() http.Header
func (*HTTPServiceRequest) GetURL ¶
func (sr *HTTPServiceRequest) GetURL() *url.URL
func (*HTTPServiceRequest) SetAPIName ¶
func (sr *HTTPServiceRequest) SetAPIName(name string)
func (*HTTPServiceRequest) SetBody ¶
func (sr *HTTPServiceRequest) SetBody(body []byte)
func (*HTTPServiceRequest) SetForm ¶
func (sr *HTTPServiceRequest) SetForm(form *url.Values)
func (*HTTPServiceRequest) SetHeader ¶
func (sr *HTTPServiceRequest) SetHeader(header http.Header)
func (*HTTPServiceRequest) SetID ¶
func (sr *HTTPServiceRequest) SetID(id uuid.UUID)
func (*HTTPServiceRequest) SetInternalPath ¶
func (sr *HTTPServiceRequest) SetInternalPath(path string)
func (*HTTPServiceRequest) SetMethod ¶
func (sr *HTTPServiceRequest) SetMethod(method HTTPMethod)
func (*HTTPServiceRequest) SetMultipart ¶
func (sr *HTTPServiceRequest) SetMultipart(data MultipartDataInterface)
func (*HTTPServiceRequest) SetPostForm ¶
func (sr *HTTPServiceRequest) SetPostForm(form *url.Values)
func (*HTTPServiceRequest) SetRequestMeta ¶
func (sr *HTTPServiceRequest) SetRequestMeta(meta RequestMetaInterface)
func (*HTTPServiceRequest) SetResponse ¶
func (sr *HTTPServiceRequest) SetResponse(response ServiceResponse)
func (*HTTPServiceRequest) SetServiceName ¶
func (sr *HTTPServiceRequest) SetServiceName(name string)
func (*HTTPServiceRequest) SetTrailer ¶
func (sr *HTTPServiceRequest) SetTrailer(trailer http.Header)
func (*HTTPServiceRequest) SetURL ¶
func (sr *HTTPServiceRequest) SetURL(url *url.URL)
type Handler ¶
type Handler struct {
InboundWorkflow Workflow // Workflow to be applied to incoming requests
OutboundWorkflow Workflow // Workflow to be applied to outgoing responses
Target Target // The target operation to be executed
}
Handler defines the structure for handling a specific HTTP method within a service.
type HasPrecedence ¶
type HasPrecedence interface {
Precedence() int // a value indicating precedence when a chain of
}
HasPrecedence provides an interface for types(such as WorkflowSteps) that can be applied in order given a precedence value, where the lowest precedence value is executed first.
type HttpResponseMeta ¶
type HttpResponseMeta struct {
OriginalResponse *http.Response // The original http.Response
Status string // Status line of the response
StatusCode int // Status code of the response
Proto string // Protocol version
ProtoMajor int // Major protocol version
ProtoMinor int // Minor protocol version
TransferEncoding []string // Transfer encodings
Header http.Header // HTTP headers
Trailer http.Header // HTTP trailers
}
ResponseMeta contains metadata about the HTTP response.
func (*HttpResponseMeta) GetHeader ¶
func (rm *HttpResponseMeta) GetHeader() http.Header
func (*HttpResponseMeta) GetOriginalResponse ¶
func (rm *HttpResponseMeta) GetOriginalResponse() *http.Response
func (*HttpResponseMeta) GetProto ¶
func (rm *HttpResponseMeta) GetProto() string
func (*HttpResponseMeta) GetProtoMajor ¶
func (rm *HttpResponseMeta) GetProtoMajor() int
func (*HttpResponseMeta) GetProtoMinor ¶
func (rm *HttpResponseMeta) GetProtoMinor() int
func (*HttpResponseMeta) GetStatus ¶
func (rm *HttpResponseMeta) GetStatus() string
func (*HttpResponseMeta) GetStatusCode ¶
func (rm *HttpResponseMeta) GetStatusCode() int
func (*HttpResponseMeta) GetTrailer ¶
func (rm *HttpResponseMeta) GetTrailer() http.Header
func (*HttpResponseMeta) GetTransferEncoding ¶
func (rm *HttpResponseMeta) GetTransferEncoding() []string
func (*HttpResponseMeta) SetHeader ¶
func (rm *HttpResponseMeta) SetHeader(header http.Header)
func (*HttpResponseMeta) SetOriginalResponse ¶
func (rm *HttpResponseMeta) SetOriginalResponse(resp *http.Response)
func (*HttpResponseMeta) SetProto ¶
func (rm *HttpResponseMeta) SetProto(proto string)
func (*HttpResponseMeta) SetProtoMajor ¶
func (rm *HttpResponseMeta) SetProtoMajor(major int)
func (*HttpResponseMeta) SetProtoMinor ¶
func (rm *HttpResponseMeta) SetProtoMinor(minor int)
func (*HttpResponseMeta) SetStatus ¶
func (rm *HttpResponseMeta) SetStatus(status string)
func (*HttpResponseMeta) SetStatusCode ¶
func (rm *HttpResponseMeta) SetStatusCode(code int)
func (*HttpResponseMeta) SetTrailer ¶
func (rm *HttpResponseMeta) SetTrailer(trailer http.Header)
func (*HttpResponseMeta) SetTransferEncoding ¶
func (rm *HttpResponseMeta) SetTransferEncoding(encoding []string)
type HttpServiceResponse ¶
type HttpServiceResponse struct {
ResponseMeta ResponseMeta // Metadata about the response
Body []byte // Raw body of the response
}
ServiceResponse represents a standardized response structure used within the service.
func GetResponseFromHttp ¶
func GetResponseFromHttp(r *http.Response) (*HttpServiceResponse, error)
GetResponseFromHttp converts a standard http.Response to our custom ServiceResponse.
Parameters:
- r: A pointer to an http.Response to be converted.
Returns:
- *ServiceResponse: A pointer to the converted ServiceResponse.
- error: An error if conversion fails, nil otherwise.
func (*HttpServiceResponse) GetBody ¶
func (sr *HttpServiceResponse) GetBody() []byte
func (*HttpServiceResponse) GetResponseMeta ¶
func (sr *HttpServiceResponse) GetResponseMeta() ResponseMeta
func (*HttpServiceResponse) SetBody ¶
func (sr *HttpServiceResponse) SetBody(body []byte)
func (*HttpServiceResponse) SetResponseMeta ¶
func (sr *HttpServiceResponse) SetResponseMeta(meta ResponseMeta)
type Hub ¶
type Hub struct {
APIVersion string
Version string
ApplicationName string
// contains filtered or unexported fields
}
Hub is the central entity in the system, responsible for managing services and routing HTTP requests. It acts as a mediator between incoming HTTP requests and the appropriate services that handle them.
func NewHub ¶
NewHub creates and initializes a new Hub instance.
Parameters:
- logger: A pointer to a zerolog.Logger for logging operations.
- applicationVersion: A string representing the version of the application.
Returns:
- A pointer to the newly created Hub and nil error on success.
- nil and an error if initialization fails.
func (*Hub) AddService ¶
AddService registers a new service with the Hub.
Parameter:
- svc: A pointer to the Service to be added.
Returns:
- An error if the service couldn't be added, nil otherwise.
func (*Hub) GetLogger ¶
GetLogger returns the current logger used by the Hub.
Returns:
- A pointer to the current zerolog.Logger.
func (*Hub) GetService ¶
GetService retrieves a service from the Hub by its API name and service name.
Parameters:
- apiName: The name of the API.
- serviceName: The name of the service.
Returns:
- A pointer to the Service and true if found.
- nil and false if the service is not found.
func (*Hub) GetServices ¶
GetServices returns a map of all registered services in the Hub.
Returns:
- A map with service keys as strings and Service pointers as values.
func (*Hub) HandleRequest ¶
func (hub *Hub) HandleRequest(r *http.Request) (ServiceResponse, error)
HandleRequest is the main entry point for processing HTTP requests.
Parameter:
- r: A pointer to the http.Request to be handled.
Returns:
- A pointer to ServiceResponse and nil error on success.
- nil and an error if request handling fails.
type MultipartData ¶
type MultipartData struct {
Value map[string][]string // Regular form values
FileData map[string][]byte // File data, keyed by field name
}
MultipartData holds both regular form values and file data for multipart requests.
func (*MultipartData) GetFileData ¶
func (md *MultipartData) GetFileData() map[string][]byte
func (*MultipartData) GetValue ¶
func (md *MultipartData) GetValue() map[string][]string
func (*MultipartData) SetFileData ¶
func (md *MultipartData) SetFileData(fileData map[string][]byte)
func (*MultipartData) SetValue ¶
func (md *MultipartData) SetValue(value map[string][]string)
type MultipartDataInterface ¶
type MultipartDataInterface interface {
GetValue() map[string][]string
SetValue(value map[string][]string)
GetFileData() map[string][]byte
SetFileData(fileData map[string][]byte)
}
MultipartDataInterface represents the interface for multipart form data.
type NoOpTarget ¶
type NoOpTarget struct{}
func (*NoOpTarget) Apply ¶
func (t *NoOpTarget) Apply(ctx context.Context, request ServiceRequest) (ServiceResponse, error)
type RegisteredTargets ¶
type RegisteredTargets map[string]TargetConstructor
RegisteredWorkflowSteps allows us to register workflow steps at start-up in order to use them at start-up
func TargetRegistry ¶
func TargetRegistry() RegisteredTargets
RegisteredRequestWorkflowSteps exposes a singleton object containing all registered worklfow steps which can be applied to service requests
type RegisteredTaskTypes ¶
type RegisteredTaskTypes map[string]TaskConstructor
RegisteredWorkflowSteps allows us to register workflow steps at start-up in order to use them at start-up
func TaskRegistry ¶
func TaskRegistry() RegisteredTaskTypes
RegisteredRequestWorkflowSteps exposes a singleton object containing all registered worklfow steps which can be applied to service requests
type RequestMeta ¶
type RequestMeta struct {
OriginalRequest *http.Request // The original http.Request
Params map[string]string // Additional parameters (e.g., from router)
Proto string // Protocol version
ProtoMajor int // Major protocol version
ProtoMinor int // Minor protocol version
ContentLength int64 // Length of the request body
TransferEncoding []string // Transfer encodings
Host string // Requested host
RemoteAddr string // Remote address of the client
RequestURI string // Unmodified request-target of the Request-Line
}
RequestMeta contains additional metadata about the original HTTP request.
func (*RequestMeta) GetContentLength ¶
func (rm *RequestMeta) GetContentLength() int64
func (*RequestMeta) GetHost ¶
func (rm *RequestMeta) GetHost() string
func (*RequestMeta) GetOriginalRequest ¶
func (rm *RequestMeta) GetOriginalRequest() *http.Request
func (*RequestMeta) GetParams ¶
func (rm *RequestMeta) GetParams() map[string]string
func (*RequestMeta) GetProto ¶
func (rm *RequestMeta) GetProto() string
func (*RequestMeta) GetProtoMajor ¶
func (rm *RequestMeta) GetProtoMajor() int
func (*RequestMeta) GetProtoMinor ¶
func (rm *RequestMeta) GetProtoMinor() int
func (*RequestMeta) GetRemoteAddr ¶
func (rm *RequestMeta) GetRemoteAddr() string
func (*RequestMeta) GetRequestURI ¶
func (rm *RequestMeta) GetRequestURI() string
func (*RequestMeta) GetTransferEncoding ¶
func (rm *RequestMeta) GetTransferEncoding() []string
func (*RequestMeta) SetContentLength ¶
func (rm *RequestMeta) SetContentLength(length int64)
func (*RequestMeta) SetHost ¶
func (rm *RequestMeta) SetHost(host string)
func (*RequestMeta) SetOriginalRequest ¶
func (rm *RequestMeta) SetOriginalRequest(req *http.Request)
func (*RequestMeta) SetParams ¶
func (rm *RequestMeta) SetParams(params map[string]string)
func (*RequestMeta) SetProto ¶
func (rm *RequestMeta) SetProto(proto string)
func (*RequestMeta) SetProtoMajor ¶
func (rm *RequestMeta) SetProtoMajor(major int)
func (*RequestMeta) SetProtoMinor ¶
func (rm *RequestMeta) SetProtoMinor(minor int)
func (*RequestMeta) SetRemoteAddr ¶
func (rm *RequestMeta) SetRemoteAddr(addr string)
func (*RequestMeta) SetRequestURI ¶
func (rm *RequestMeta) SetRequestURI(uri string)
func (*RequestMeta) SetTransferEncoding ¶
func (rm *RequestMeta) SetTransferEncoding(encoding []string)
type RequestMetaInterface ¶
type RequestMetaInterface interface {
GetOriginalRequest() *http.Request
SetOriginalRequest(req *http.Request)
GetParams() map[string]string
SetParams(params map[string]string)
GetProto() string
SetProto(proto string)
GetProtoMajor() int
SetProtoMajor(major int)
GetProtoMinor() int
SetProtoMinor(minor int)
GetContentLength() int64
SetContentLength(length int64)
GetTransferEncoding() []string
SetTransferEncoding(encoding []string)
GetHost() string
SetHost(host string)
GetRemoteAddr() string
SetRemoteAddr(addr string)
GetRequestURI() string
SetRequestURI(uri string)
}
RequestMetaInterface represents the interface for request metadata.
type ResponseMeta ¶
type ResponseMeta interface {
GetOriginalResponse() *http.Response
GetStatus() string
SetStatus(status string)
GetStatusCode() int
SetStatusCode(code int)
GetProto() string
SetProto(proto string)
GetProtoMajor() int
SetProtoMajor(major int)
GetProtoMinor() int
SetProtoMinor(minor int)
GetTransferEncoding() []string
SetTransferEncoding(encoding []string)
GetHeader() http.Header
SetHeader(header http.Header)
GetTrailer() http.Header
SetTrailer(trailer http.Header)
}
ResponseMetaInterface represents the interface for response metadata.
type Service ¶
type Service struct {
Name string // Name of the service
SchemaName string // Name of the schema used by the service
SchemaVersion string // Version of the schema
APIName string // Name of the API this service belongs to
IsPublic bool // Indicates if the service is publicly accessible
ServiceTimeout *time.Duration // Timeout for service operations
Methods map[HTTPMethod]*Handler // Map of HTTP methods to their respective handlers
}
Service represents a single service or DDD-style aggregate. It consists of handlers with incoming and outgoing workflows, and a target for each allowed HTTP method.
func NewService ¶
NewService creates and returns a new Service instance.
Parameters:
- apiName: Name of the API this service belongs to.
- name: Name of the service.
- schemaName: Name of the schema used by the service.
- schemaVersion: Version of the schema.
- public: Indicates if the service is publicly accessible.
Returns:
- *Service: A pointer to the newly created Service.
- error: Always nil in the current implementation.
func (*Service) DoRequest ¶
func (service *Service) DoRequest(ctx context.Context, request ServiceRequest) error
DoRequest processes an incoming service request by applying the appropriate workflows and target operation.
Parameters:
- ctx: The context for the request.
- request: A pointer to the ServiceRequest to be processed.
Returns:
- error: Any error encountered during processing, or nil if successful.
func (*Service) GetHandlers ¶
func (service *Service) GetHandlers() map[HTTPMethod]*Handler
GetHandlers returns a map of all configured HTTP methods and their handlers for the service.
Returns:
- map[HTTPMethod]*Handler: A map of HTTP methods to their respective handlers.
func (*Service) SetHandler ¶
func (service *Service) SetHandler(method HTTPMethod, handler *Handler)
SetHandler assigns a Handler to a specific HTTP method for the service.
Parameters:
- method: The HTTP method to assign the handler to.
- handler: A pointer to the Handler to be assigned.
type ServiceRequest ¶
type ServiceRequest interface {
GetID() uuid.UUID
GetAPIName() string
GetServiceName() string
GetMethod() HTTPMethod
GetURL() *url.URL
GetInternalPath() string
GetBody() []byte
SetBody(body []byte)
GetForm() *url.Values
SetForm(form *url.Values)
GetPostForm() *url.Values
SetPostForm(form *url.Values)
GetMultipart() MultipartDataInterface
SetMultipart(data MultipartDataInterface)
GetResponse() ServiceResponse
SetResponse(response ServiceResponse)
GetRequestMeta() RequestMetaInterface
SetRequestMeta(meta RequestMetaInterface)
GetHeader() http.Header
SetHeader(header http.Header)
GetTrailer() http.Header
SetTrailer(trailer http.Header)
}
ServiceRequestInterface represents the interface for a standardized request structure.
type ServiceResponse ¶
type ServiceResponse interface {
GetResponseMeta() ResponseMeta
SetResponseMeta(meta ResponseMeta)
GetBody() []byte
SetBody(body []byte)
}
ServiceResponseInterface represents the interface for a standardized response structure.
type Target ¶
type Target interface {
Apply(ctx context.Context, request ServiceRequest) (ServiceResponse, error)
}
Target represents the end destination of an incoming request. Similar to a Task, but accepts a ServiceRequest and returns ServiceResponse It will usually handle writing an entity to some persistence medium.
func GetTarget ¶
GetTarget retrieves a Target Constructor instance by its name, passes in a config and returns a configured Target instance. It returns an error if the target type is not registered.
Parameters: - taskName: the name of the task to retrieve - config: a map containing the configuration for the task
Returns: - Task: the configured Task instance - error: an error if the task is not registered
type TargetConstructor ¶
TargetConstructor takes a config object and returns a configured Target instance.
func NewNoOpTargetConstructor ¶
func NewNoOpTargetConstructor() TargetConstructor
type TargetConstructorFunc ¶
func TargetConstructorFromFunction ¶
func TargetConstructorFromFunction( fn func(map[string]interface{}) (Target, error), ) TargetConstructorFunc
TargetConstructorFromFunction creates a TargetConstructorFunc from a function with the signature func(map[string]interface{}) (T, error), where T implements Target
type Task ¶
type Task interface {
Name() string
Apply(ctx context.Context, request ServiceRequest) error
}
Task is the interface for a task that can be performed as part of a workflow. Tasks applied to incoming requests and outgoing responses both accept and return ServiceRequest, but outgoing responses generally will work with the response object.
func GetTask ¶
GetTask retrieves a Task Constructor instance by its name, passes in a config and returns a configured Task instance. It returns an error if the task type is not registered.
Parameters: - taskName: the name of the task to retrieve - config: a map containing the configuration for the task
Returns: - Task: the configured Task instance - error: an error if the task is not registered
type TaskConstructor ¶
TaskConstructor takes a config object and returns a configured Target instance.
type TaskConstructorFunc ¶
func TaskConstructorFromFunction ¶
func TaskConstructorFromFunction( fn func(map[string]interface{}) (Task, error), ) TaskConstructorFunc
TaskConstructorFromFunction creates a TaskConstructorFunc from a function with the signature func(map[string]interface{}) (T, error), where T implements Task
type Workflow ¶
type Workflow interface {
Apply(ctx context.Context, in ServiceRequest) error
}
Workflow is the interface for a workflow that can be applied to a ServiceRequest.
type WorkflowStep ¶
type WorkflowStep struct {
Task Task // the task to be applied
Name string
Description string
TaskType string
Ref string
ExecutionType string
Config map[string]interface{}
Precedence int // a value indicating precedence within a chain of
}
WorkflowStep provides an struct for transformations / work to be applied upon an incoming object of type T, with a precedence. This is intended top allow Tasks to be chained into workflows that can be applied upon incoming objects in a pre-specified order.
func (WorkflowStep) Apply ¶
func (w WorkflowStep) Apply(ctx context.Context, request *HTTPServiceRequest) error
func (WorkflowStep) GetPrecedence ¶
func (w WorkflowStep) GetPrecedence() int
func (WorkflowStep) GetStepName ¶
func (w WorkflowStep) GetStepName() string
func (WorkflowStep) GetTask ¶
func (w WorkflowStep) GetTask() Task
func (WorkflowStep) GetTaskName ¶
func (w WorkflowStep) GetTaskName() string
type WorkflowTasks ¶
type WorkflowTasks struct {
Steps map[int][]*WorkflowStep
}
Workflow is a chain of workflow steps that can be applied sequentially according to priority.
func NewWorkflowTasks ¶
func NewWorkflowTasks(steps ...*WorkflowStep) *WorkflowTasks
NewWorkflow creates a new workflow
func (*WorkflowTasks) Apply ¶
func (chain *WorkflowTasks) Apply( ctx context.Context, in ServiceRequest) error
Apply applies all transformations in this chain, in order of precedence