api_server

package
v0.0.0-...-8122643 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddServiceToServer

func AddServiceToServer(s Server, service Service)

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 InitResourceEndpoint

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

func ParseDbQuery

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

func SetResponseList

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

func UniqueFormData

func UniqueFormData(request Request) map[string]string

Types

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() *EchoEndpoint

func (*EchoEndpoint) HandleRequest

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

type Endpoint

type Endpoint interface {
	api.Operation
	generic_error.ErrorsExtender

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

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

Interface of API endpoint.

type EndpointBase

type EndpointBase struct {
	api.Operation
	generic_error.ErrorsExtenderBase
}

Base type for API endpoints.

func (*EndpointBase) Construct

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

func (*EndpointBase) Init

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

func (*EndpointBase) PrecheckRequestBeforeAuth

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

type EndpointHandler

type EndpointHandler = func(request Request)

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 Request

type Request interface {
	auth.AuthContext
	common.WithParameters

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

	ParseValidate(cmd interface{}) error
	FormData() map[string][]string
}

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) Init

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

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)
	Request() Request
	SetRequest(request Request)

	Text() string
	SetText(text string)

	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) 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) SetRedirectPath

func (r *ResponseBase) SetRedirectPath(path string)

func (*ResponseBase) SetRequest

func (r *ResponseBase) SetRequest(request Request)

func (*ResponseBase) SetText

func (r *ResponseBase) SetText(text string)

func (*ResponseBase) Text

func (r *ResponseBase) Text() string

type Server

type Server interface {
	generic_error.ErrorManager
	auth.WithAuth

	// Get API version.
	ApiVersion() string

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

	// Add operation endpoint to server.
	AddEndpoint(ep Endpoint, multitenancy ...bool)

	// 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
}

Interface of generic server that implements some API.

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
	api.Resource

	SetSupportsMultitenancy(enable bool)
	SupportsMultitenancy() bool

	Server() Server
	AttachToServer(server Server) error

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

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

type ServiceBase

type ServiceBase struct {
	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, multitenancy ...bool)

func (*ServiceBase) Server

func (s *ServiceBase) Server() Server

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