protocol

package
v0.0.0-...-0acdc99 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyRole  = "Role"
	KeyQuery = "Query"
	KeyAuth  = "Auth"
	KeyDTO   = "DTO"
	KeyFile  = "File"
	MaxLimit = "MaxLimit"
)

Variables

View Source
var ResourceIdParameter = RequestParameter{
	Definition: misc.NewQueryDefinition(misc.Id, []misc.QueryOperator{misc.QueryOperatorEqual}, misc.DataTypeString),
	Query:      false,
	Optional:   false,
}

Functions

func NewTestAuthenticator

func NewTestAuthenticator(claim misc.JwtClaim, rs bool) testAuthenticator

Types

type Action

type Action func(req Request)

An Action is a function that handles an HTTP request.

type Api

type Api interface {
	Run(ip string, port uint, mode string) error
	AppendDuplexModule(mod DuplexModule)
	AppendModule(mod Module)
	AppendPreHandlers(string, Action)
	GetRoute(url, method string) *RequestDefinition
	AppendAuthorizer(baseURL string, authorizer Authorizer)
	AppendAuthenticator(baseURL string, authorizer Authenticator)
	SetCors(cors []string)
	SetLogHandler(LogHandler)
	SetLogPolicy(model.LogPolicy)
	TestHandle(*httptest.ResponseRecorder, *http.Request) error
	// OpenAPI
	SetExternalDocs(openapi.ExternalDocs)
	SetInfo(openapi.Info)
	SetContact(openapi.Contact)
	SetServers([]openapi.Server)
	EnableOpenApi(route string) error
	SetErrors([]string)
}

The Api interface defines the methods required to run an HTTP server and handle incoming requests.

type Authenticator

type Authenticator interface {
	GetModel(token string) (misc.JwtClaim, error)
	CheckToken(token string) (bool, error)
}

type Authorizer

type Authorizer func(identity string, permission string) (bool, error)

type DuplexConnection

type DuplexConnection interface {
	Publish(topic string, message any) error
	GetCaller() (misc.Caller, bool)
	MustGetCaller() misc.Caller
}

type DuplexHandler

type DuplexHandler func(msg DuplexMessage)

type DuplexHandlerDefinition

type DuplexHandlerDefinition struct {
	Topic          string
	Dto            any
	Handler        DuplexHandler
	AnyPermissions []string
	FreeRoute      bool // Free route require neither authentication nor authorization
}

type DuplexMessage

type DuplexMessage interface {
	GetDto() any
	MustGetCaller() misc.Caller
	GetTopic() string
}

type DuplexModule

type DuplexModule interface {
	GetDuplexHandlers() []*DuplexHandlerDefinition
	GetBaseURL() string
	OnDuplexConnected(DuplexConnection)
	OnDuplexDisconnected(DuplexConnection)
}

type FileHeader

type FileHeader interface {
	GetHeader() textproto.MIMEHeader
	GetSize() int64
	GetFilename() string
	OpenFile() (fileProtocol.File, error)
}

type FileMultipart

type FileMultipart interface {
	fileProtocol.File
	Multipart
}

type HTTPMethod

type HTTPMethod string

type LogHandler

type LogHandler interface {
	Handle(model.HttpLog)
}

type Module

type Module interface {
	GetRequestHandlers() []*RequestDefinition
	GetBaseURL() string
	GetTag() openapi.Tag
}

The Module interface defines the methods required to handle a group of related request handlers.

type Multipart

type Multipart interface {
	io.ReadCloser
	GetPartName() string
	GetMimeType() string
}

type MultipartDefinition

type MultipartDefinition interface {
	IsOptional() bool
	GetPartName() string
	IsSingle() bool
	GetObject() interface{}
	GetSupportedTypes() []string
}

type MultipartFileDefinition

type MultipartFileDefinition interface {
	MultipartDefinition
	Verify(FileHeader) error
}

type MultipartValueDefinition

type MultipartValueDefinition interface {
	MultipartDefinition
	Verify() error
}

type Request

type Request interface {
	// GetJson and other stuff
	SetServerError(msg string)
	SetForbidden()
	SetUnauthorized(msg string, code string)
	SetBadRequest(msg string, code string)
	SetNotFound(msg string, code string)
	ReturnStatus(int, error)
	Set(key string, value interface{})
	SetFile(key string, f FileHeader)
	SetFiles(key string, f []FileHeader)
	Get(key string) (interface{}, bool)
	MustGet(key string) interface{}
	GetDTO() (interface{}, bool)
	MustGetDTO() interface{}
	GetFile(partName string) (FileHeader, bool)
	MustGetFile(partName string) FileHeader
	GetFiles(partName string) ([]FileHeader, bool)
	MustGetFiles(partName string) []FileHeader
	Negotiate(stausCode int, err error, dto interface{})
	RangeFile(status int, err error, file fileProtocol.SeekerFile)
	WriteFile(status int, err error, file fileProtocol.File)
	ReturnMultipartMixed(status int, err error, out ...Multipart)
	GetPagination() (misc.Pagination, bool)
	GetCursorPagination() (misc.CursorPagination, bool)
	GetCaller() (misc.Caller, bool)
	MustGetCaller() misc.Caller
	GetSort() []misc.Sort
	GetQuery() []misc.Query
	GetDefaultQuery() (string, bool)
	IsAndQuery() bool
}

The Request interface defines the methods available to an HTTP request handler.

type RequestDefinition

type RequestDefinition struct {
	Route          string
	Parameters     []RequestParameter
	Dto            Verifier
	DtoArray       Verifier
	FileParts      []MultipartFileDefinition
	ValueParts     []MultipartValueDefinition
	Handler        Action
	MaxLimit       int
	Method         HTTPMethod
	AnyPermissions []string
	FreeRoute      bool // Free route require neither authentication nor authorization

	// Specific for Swagger
	Summary             string
	Description         string
	OperationId         string // Tools use this UNIQUE id to idenitfy the action example: GetUserById,GetUsers, ....
	Deprecated          bool   // Set true if this definition is deprecated
	ResponseDefinitions []ResponseDefinition
}

type RequestParameter

type RequestParameter struct {
	Definition misc.QueryDefinition
	Query      bool
	Optional   bool
}

type ResponseDefinition

type ResponseDefinition struct {
	Description string // For example: success operation
	Status      int
	Dto         any // Might be basic dto,
	IsFile      bool
}

Describe the output

type Verifier

type Verifier interface {
	Verify() error
}

The Verifier interface defines the method required to validate input data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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