api_server

package
v0.0.0-...-595e2a2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddServiceToServer

func AddServiceToServer(s Server, service Service) error

func ConstructResourceEndpoint

func ConstructResourceEndpoint(ep ResourceEndpointI, resourceType string, op api.Operation)

func FullRequestPath

func FullRequestPath(r Request) string

func FullRequestServicePath

func FullRequestServicePath(r Request) string

func InitKebabEndpoint

func InitKebabEndpoint(ep ResourceEndpointI, operationName string, accessType ...access_control.AccessType)

func InitResourceEndpoint

func InitResourceEndpoint(ep ResourceEndpointI, resourceType string, operationName string, accessType ...access_control.AccessType)

func MessageFromRequest

func MessageFromRequest[T any](request Request, init ...func(*T)) (*T, error)

func ParseDbQuery

func ParseDbQuery(request Request, model interface{}, queryName string, cmd ...api.Query) (*db.Filter, error)

func ParseValidateRequest

func ParseValidateRequest[T any](request Request, init ...func(*T)) (*T, error)

func ServiceName

func ServiceName(service string, version string) string

func SetResponseList

func SetResponseList(r Request, response api.ResponseListI, resourceType ...string)

func UniqueFormData

func UniqueFormData(request Request) map[string]string

Types

type AuthParameterGetter

type AuthParameterGetter = func(r *Request, key string) string

type AuthParameterSetter

type AuthParameterSetter = func(r *Request, key string, value string)

type CheckAccess

type CheckAccess struct{}

func (*CheckAccess) HandleRequest

func (e *CheckAccess) HandleRequest(request Request) error

type CheckAccessEndpoint

type CheckAccessEndpoint struct {
	EndpointBase
	CheckAccess
}

func NewCheckAccessEndpoint

func NewCheckAccessEndpoint(operationName string, accessType ...access_control.AccessType) *CheckAccessEndpoint

type CheckAccessResourceEndpoint

type CheckAccessResourceEndpoint struct {
	ResourceEndpoint
	CheckAccess
}

func NewCheckAccessResourceEndpoint

func NewCheckAccessResourceEndpoint(resource string, operationName string,
	accessType ...access_control.AccessType) *CheckAccessResourceEndpoint

type CheckStatusEndpoint

type CheckStatusEndpoint struct {
	ResourceEndpoint
}

func NewCheckStatusEndpoint

func NewCheckStatusEndpoint() *CheckStatusEndpoint

func (*CheckStatusEndpoint) HandleRequest

func (e *CheckStatusEndpoint) HandleRequest(request Request) error

type DynamicFieldTranslator

type DynamicFieldTranslator interface {
	Tr(field *DynamicTableField, tableName ...string) (string, bool)
}

type DynamicTable

type DynamicTable struct {
	api.ResponseStub
	Columns              []*DynamicTableField `json:"columns"`
	DefaultSortColumn    string               `json:"default_sort_column"`
	DefaultSortDirection string               `json:"default_sort_direction"`
}

type DynamicTableConfig

type DynamicTableConfig struct {
	Operation            api.Operation
	Model                interface{}
	Displays             map[string]string
	ColumnsOrder         []string
	DefaultSortField     string
	DefaultSortDirection string
	EnumGetters          map[string]EnumGetter
	Enums                FieldEnums
	VisibleColumns       []string
}

type DynamicTableEndpoint

type DynamicTableEndpoint struct {
	ResourceEndpoint
	// contains filtered or unexported fields
}

func NewDynamicTableEndpoint

func NewDynamicTableEndpoint(service *DynamicTablesService) *DynamicTableEndpoint

func (*DynamicTableEndpoint) HandleRequest

func (e *DynamicTableEndpoint) HandleRequest(request Request) error

type DynamicTableField

type DynamicTableField struct {
	Field      string       `json:"field"`
	Type       string       `json:"type"`
	Index      bool         `json:"index"`
	Display    string       `json:"display"`
	Enum       []*EnumEntry `json:"enum,omitempty"`
	Visible    bool         `json:"visible"`
	Money      bool         `json:"money"`
	EnumGetter EnumGetter   `json:"-"`
}

type DynamicTableQuery

type DynamicTableQuery struct {
	Path string `json:"path" validate:"required" vmessage:"Invalid table path."`
}

type DynamicTables

type DynamicTables interface {
	AddTable(table *DynamicTableConfig) error
	Table(request Request, path string) (*DynamicTable, error)
	SetTranslator(translator DynamicFieldTranslator)
}

type DynamicTablesService

type DynamicTablesService struct {
	ServiceBase
}

func NewDynamicTablesService

func NewDynamicTablesService(multitenancy ...bool) *DynamicTablesService

type EchoEndpoint

type EchoEndpoint struct {
	EndpointBase
}

func NewEchoEndpoint

func NewEchoEndpoint(opName ...string) *EchoEndpoint

func (*EchoEndpoint) HandleRequest

func (e *EchoEndpoint) HandleRequest(request Request) error

func (*EchoEndpoint) IsRequestPayloadNeeded

func (e *EchoEndpoint) IsRequestPayloadNeeded() bool

type Endpoint

type Endpoint interface {
	api.Operation
	generic_error.ErrorsExtender
	MessageHandlers

	SetMessageHandlers(handlers MessageHandlers)

	NewRequestMessage() interface{}

	// Handle request to server API.
	HandleRequest(request Request) error

	// Precheck request before some authorization methods
	PrecheckBeforeAuth(request Request, smsMessage *string, skipSms *bool) error

	IsRequestPayloadNeeded() bool

	SetRequestPreprocessor(handler EndpointHandler)
	GetRequestPreprocessor() EndpointHandler
	PreprocessBeforeAuth(request Request) error

	SetRequestPostprocessor(handler EndpointHandler)
	GetRequestPostprocessor() EndpointHandler
	Postprocess(request Request) error
}

Interface of API endpoint.

type EndpointBase

type EndpointBase struct {
	api.Operation
	generic_error.ErrorsExtenderBase
	MessageHandlers
	// contains filtered or unexported fields
}

Base type for API endpoints.

func (*EndpointBase) Construct

func (e *EndpointBase) Construct(op api.Operation)

func (*EndpointBase) GetRequestPostprocessor

func (e *EndpointBase) GetRequestPostprocessor() EndpointHandler

func (*EndpointBase) GetRequestPreprocessor

func (e *EndpointBase) GetRequestPreprocessor() EndpointHandler

func (*EndpointBase) HandleRequest

func (e *EndpointBase) HandleRequest(request Request) error

func (*EndpointBase) Init

func (e *EndpointBase) Init(operationName string, accessType ...access_control.AccessType)

func (*EndpointBase) IsRequestPayloadNeeded

func (e *EndpointBase) IsRequestPayloadNeeded() bool

func (*EndpointBase) NewRequestMessage

func (e *EndpointBase) NewRequestMessage() interface{}

func (*EndpointBase) Postprocess

func (e *EndpointBase) Postprocess(request Request) error

func (*EndpointBase) PrecheckBeforeAuth

func (e *EndpointBase) PrecheckBeforeAuth(request Request, smsMessage *string, skipSms *bool) error

func (*EndpointBase) PreprocessBeforeAuth

func (e *EndpointBase) PreprocessBeforeAuth(request Request) error

func (*EndpointBase) SetMessageHandlers

func (e *EndpointBase) SetMessageHandlers(handlers MessageHandlers)

func (*EndpointBase) SetRequestPostprocessor

func (e *EndpointBase) SetRequestPostprocessor(handler EndpointHandler)

func (*EndpointBase) SetRequestPreprocessor

func (e *EndpointBase) SetRequestPreprocessor(handler EndpointHandler)

type EndpointHandler

type EndpointHandler = func(request Request) error

type EndpointNoHandler

type EndpointNoHandler struct{}

Base type for API endpoints with empty handlers.

func (*EndpointNoHandler) HandleRequest

func (e *EndpointNoHandler) HandleRequest(request Request) error

type EnumEntry

type EnumEntry struct {
	Value   string `json:"value"`
	Display string `json:"display"`
}

func EnumList

func EnumList(enumList []string) []*EnumEntry

func EnumMap

func EnumMap(enumMap map[string]string) []*EnumEntry

type EnumGetter

type EnumGetter func(request Request) ([]*EnumEntry, error)

type FieldEnums

type FieldEnums = map[string][]*EnumEntry

type File

type File struct {
	Content     []byte
	ContentType string
	Name        string
}

type MessageBuilder

type MessageBuilder func() interface{}

type MessageContent

type MessageContent interface {
	BinaryContent() []byte
	SetBinaryContent([]byte)
	SetLogicMessage(interface{})
	LogicMessage() interface{}
	SetTransportMessage(interface{})
	TransportMessage() interface{}
}

type MessageConverter

type MessageConverter func(msg MessageContent) error

type MessageHandlers

type MessageHandlers interface {
	NewTransportRequest(ep Endpoint) interface{}
	TransportRequestToLogic(msg MessageContent) error
	LogicResponseToTransport(msg MessageContent) error
}

type MessageHandlersConfig

type MessageHandlersConfig struct {
	RequestFromTransport    MessageConverter
	ResponseToTransport     MessageConverter
	TransportRequestBuilder MessageBuilder
}

func (*MessageHandlersConfig) LogicResponseToTransport

func (m *MessageHandlersConfig) LogicResponseToTransport(msg MessageContent) error

func (*MessageHandlersConfig) NewTransportRequest

func (m *MessageHandlersConfig) NewTransportRequest(ep Endpoint) interface{}

func (*MessageHandlersConfig) TransportRequestToLogic

func (m *MessageHandlersConfig) TransportRequestToLogic(msg MessageContent) error

type Request

type Request interface {
	auth.AuthContext
	common.WithParameters

	Server() Server
	Response() Response
	Endpoint() Endpoint

	ParseAndValidate(cmd interface{}) error
	FormData() map[string][]string
	FormFile() (*multipart.FileHeader, error)

	SetMessage(msg RequestMessage)
	Message() RequestMessage
}

Interface of request to server API.

type RequestBase

type RequestBase struct {
	auth.TenancyUserContext
	auth.SessionBase
	// contains filtered or unexported fields
}

func (*RequestBase) Endpoint

func (r *RequestBase) Endpoint() Endpoint

func (*RequestBase) GetSessionParameter

func (r *RequestBase) GetSessionParameter(key string) string

func (*RequestBase) Init

func (r *RequestBase) Init(app app_context.Context, log logger.Logger, db db.DB, fields ...logger.Fields)

func (*RequestBase) LoadSessionParameters

func (r *RequestBase) LoadSessionParameters(parameters map[string]string)

func (*RequestBase) Message

func (r *RequestBase) Message() RequestMessage

func (*RequestBase) SetEndpoint

func (r *RequestBase) SetEndpoint(endpoint Endpoint)

func (*RequestBase) SetMessage

func (r *RequestBase) SetMessage(msg RequestMessage)

func (*RequestBase) SetSessionParameter

func (r *RequestBase) SetSessionParameter(key string, value string)

func (*RequestBase) StoreSessionParameters

func (r *RequestBase) StoreSessionParameters() map[string]string

type RequestMessage

type RequestMessage interface {
	MessageContent
}

type RequestMessageBase

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

func NewRequestMessage

func NewRequestMessage() *RequestMessageBase

func (*RequestMessageBase) BinaryContent

func (m *RequestMessageBase) BinaryContent() []byte

func (*RequestMessageBase) LogicMessage

func (m *RequestMessageBase) LogicMessage() any

func (*RequestMessageBase) SetBinaryContent

func (m *RequestMessageBase) SetBinaryContent(content []byte)

func (*RequestMessageBase) SetLogicMessage

func (m *RequestMessageBase) SetLogicMessage(msg interface{})

func (*RequestMessageBase) SetTransportMessage

func (m *RequestMessageBase) SetTransportMessage(msg interface{})

func (*RequestMessageBase) TransportMessage

func (m *RequestMessageBase) TransportMessage() any

type ResourceEndpoint

type ResourceEndpoint struct {
	api.ResourceBase
	EndpointBase
}

type ResourceEndpointI

type ResourceEndpointI interface {
	api.Resource
	Endpoint
	// contains filtered or unexported methods
}

type Response

type Response interface {
	Message() interface{}
	SetMessage(message api.Response)
	SetStatusMessage(status string)
	SetSuccessStatusMessage()
	Request() Request
	SetRequest(request Request)

	Payload() []byte
	SetPayload(payload []byte)

	SetRedirectPath(path string)
	RedirectPath() string

	SetFile(file *File)
	File() *File
}

Interface of response of server API.

type ResponseBase

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

func (*ResponseBase) File

func (r *ResponseBase) File() *File

func (*ResponseBase) Message

func (r *ResponseBase) Message() interface{}

func (*ResponseBase) Payload

func (r *ResponseBase) Payload() []byte

func (*ResponseBase) RedirectPath

func (r *ResponseBase) RedirectPath() string

func (*ResponseBase) Request

func (r *ResponseBase) Request() Request

func (*ResponseBase) SetFile

func (r *ResponseBase) SetFile(file *File)

func (*ResponseBase) SetMessage

func (r *ResponseBase) SetMessage(message api.Response)

func (*ResponseBase) SetPayload

func (r *ResponseBase) SetPayload(data []byte)

func (*ResponseBase) SetRedirectPath

func (r *ResponseBase) SetRedirectPath(path string)

func (*ResponseBase) SetRequest

func (r *ResponseBase) SetRequest(request Request)

func (*ResponseBase) SetStatusMessage

func (r *ResponseBase) SetStatusMessage(status string)

func (*ResponseBase) SetSuccessStatusMessage

func (r *ResponseBase) SetSuccessStatusMessage()

type Server

type Server interface {
	generic_error.ErrorManager
	auth.WithAuth
	app_context.WithApp

	Init(ctx app_context.Context, auth auth.Auth, tenancyManager multitenancy.Multitenancy, configPath ...string) error

	// Get API version.
	ApiVersion() string

	// Run server.
	Run(fin background_worker.Finisher)

	// Check if hateoas links are enabled.
	IsHateoas() bool

	// Get tenancy manager
	TenancyManager() multitenancy.Multitenancy

	// Check for testing mode.
	Testing() bool

	// Get dynamic tables store
	DynamicTables() DynamicTables

	// Load default server configuration from corresponding pool service
	SetConfigFromPoolService(service pool.PoolService, public ...bool)

	// Get pool service used for server configuration
	ConfigPoolService() pool.PoolService

	RegisterService(Service) error

	ListEndpoints()
}

Interface of generic server that implements some API.

type ServerBase

type ServerBase struct {
	app_context.WithAppBase
}

func (*ServerBase) ListEndpoints

func (s *ServerBase) ListEndpoints()

type ServerBaseConfig

type ServerBaseConfig struct {
	common.WithNameBaseConfig
	API_VERSION          string `validate:"required"`
	HATEOAS              bool
	OPLOG_USER_TYPE      string `default:"server_user"`
	DISABLE_MULTITENANCY bool
}

func (*ServerBaseConfig) ApiVersion

func (s *ServerBaseConfig) ApiVersion() string

func (*ServerBaseConfig) IsHateoas

func (s *ServerBaseConfig) IsHateoas() bool

type Service

type Service interface {
	generic_error.ErrorsExtender
	common.WithName
	api.Resource

	SetSupportsMultitenancy(enable bool)
	SupportsMultitenancy() bool

	Server() Server
	AttachToServer(server Server) error

	AddDynamicTables(tables ...*DynamicTableConfig)
	DynamicTables() []*DynamicTableConfig

	Package() string
	SetPackage(string)
}

Interface of service that implements one or more groups of API endpoints.

type ServiceBase

type ServiceBase struct {
	common.WithNameBase
	api.ResourceBase
	generic_error.ErrorsExtenderBase
	// contains filtered or unexported fields
}

func (*ServiceBase) AddDynamicTables

func (s *ServiceBase) AddDynamicTables(tables ...*DynamicTableConfig)

func (*ServiceBase) AttachToServer

func (s *ServiceBase) AttachToServer(server Server) error

func (*ServiceBase) DynamicTables

func (s *ServiceBase) DynamicTables() []*DynamicTableConfig

func (*ServiceBase) Init

func (s *ServiceBase) Init(pathName string, packageName string, multitenancy ...bool)

func (*ServiceBase) InitExplicit

func (s *ServiceBase) InitExplicit(pathName string, serviceName string, packageName string, multitenancy ...bool)

func (*ServiceBase) Package

func (s *ServiceBase) Package() string

func (*ServiceBase) Server

func (s *ServiceBase) Server() Server

func (*ServiceBase) SetEndpointMessageHandlers

func (s *ServiceBase) SetEndpointMessageHandlers(handlers map[string]MessageHandlers)

func (*ServiceBase) SetPackage

func (s *ServiceBase) SetPackage(value string)

func (*ServiceBase) SetSupportsMultitenancy

func (s *ServiceBase) SetSupportsMultitenancy(enable bool)

func (*ServiceBase) SupportsMultitenancy

func (s *ServiceBase) SupportsMultitenancy() bool

type ServiceEachEndpointHandler

type ServiceEachEndpointHandler = func(ep Endpoint)

type StatusResponse

type StatusResponse struct {
	api.ResponseStub
	Status string `json:"status"`
}

type StatusService

type StatusService struct {
	ServiceBase
}

func NewStatusService

func NewStatusService(multitenancy ...bool) *StatusService

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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