raiden

package module
v1.0.0-alpha-rc Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 30 Imported by: 0

README

Raiden Framework

Introduction

Raiden is a cutting-edge framework designed for seamless integration with Supabase, focusing on enhancing security, streamlining backend processes, and providing consistent schema management. It specifically addresses the need to avoid direct client-side calls to the database, ensuring more secure and efficient data handling.

Key Objectives

  • Enhanced Security: Prevent direct client-side database calls to bolster security.
  • Unified Backend Management: Introduce a unified layer for managing Remote Procedure Calls (RPC), Edge Functions, and standard APIs, simplifying backend complexity.
  • Consistent Schema Management: Provide tools for consistent and efficient management and persistence of database schemas.

Features

  • Secure Database Interaction: Ensures secure communication between client and database, mitigating risks associated with direct database access.
  • Unified Backend Layer: Streamlines the creation and management of RPCs, Edge Functions, and APIs, offering a centralized way to handle backend logic.
  • Schema Consistency: Tools to manage database schemas with ease, ensuring consistency across different stages of development.

Getting Started

Prerequisites
  • Go (version 1.21.6 or higher)
  • Supabase account and project setup
Installation

Download our binary, or build from your local.

Usage:
  raiden [command]

Available Commands:
  apply       Apply resource to supabase
  build       Build app binary
  completion  Generate the autocompletion script for the specified shell
  configure   Configure project
  generate    Generate application resource
  help        Help about any command
  imports     Import supabase resource
  init        Init golang app
  run         Run app server
  serve       Serve app binary
  start       Start new app
  version     Show application information

Flags:
  -h, --help      help for raiden
  -v, --verbose   enable verbose output

Use "raiden [command] --help" for more information about a command.

Documentation

For detailed documentation, including security practices and schema management, visit [sev-2.com].

Contributing

Contributions are welcome! Please read our Contributing Guidelines for more information.

License

Raiden is open source and is licensed under the MIT License.

Contact

For support or queries, please contact us at admin@refactory.id.

Documentation

Index

Constants

View Source
const (
	DefaultRoleValidUntilLayout = "2006-01-02"
	DefaultRoleConnectionLimit  = 60
)
View Source
const (
	RpcBehaviorVolatile  RpcBehaviorType = "VOLATILE"
	RpcBehaviorStable    RpcBehaviorType = "STABLE"
	RpcBehaviorImmutable RpcBehaviorType = "IMMUTABLE"

	RpcSecurityTypeDefiner RpcSecurityType = "DEFINER"
	RpcSecurityTypeInvoker RpcSecurityType = "INVOKER"

	RpcTemplate = `` /* 145-byte string literal not displayed */
)

Variables

View Source
var (
	DefaultRpcParamPrefix = "in_"
	DefaultRpcSchema      = "public"
)

Functions

func BuildRpc

func BuildRpc(rpc Rpc) (err error)

func CorsMiddleware

func CorsMiddleware(config *Config) fasthttp.RequestHandler

func Debug

func Debug(v ...any)

func Debugf

func Debugf(format string, v ...any)

func Error

func Error(v ...any)

func Errorf

func Errorf(format string, v ...any)

func ExecuteRpc

func ExecuteRpc(ctx Context, rpc Rpc) (any, error)

----- Execute Rpc -----

func Fatal

func Fatal(v ...any)

func Fatalf

func Fatalf(format string, v ...any)

func GetValidRpcReturnNameDecl

func GetValidRpcReturnNameDecl(pType RpcReturnDataType, returnAlias bool) (string, error)

func Info

func Info(v ...any)

func Infof

func Infof(format string, v ...any)

func MarshalRpcParamTag

func MarshalRpcParamTag(paramTag *RpcParamTag) (string, error)

func MarshallAndValidate

func MarshallAndValidate(ctx *fasthttp.RequestCtx, controller any) error

Marshall request data (path param, query and body data) to Payload data in actual controller

Example :

type Request {
		Search 		string	`query:"q"`
		Resource 	string	`path:"resource" validate:"required"`
}

Controller {
		raiden.ControllerBase
		Payload	*Request
}

Example Request : GET /hello/{resource}?q="some-resource"

base on example above this code will auto marshall data from fasthttp.Request to Request struct and validate all data is appropriate base on validate tag

func NewGracefulListener

func NewGracefulListener(ln net.Listener, maxWaitTime time.Duration) net.Listener

NewGracefulListener wraps the given listener into 'graceful shutdown' listener.

func NewRouter

func NewRouter(config *Config) *router

func Panic

func Panic(v ...any)

func Panicf

func Panicf(format string, v ...any)

func PrintJson

func PrintJson(data any, pretty bool)

func ProxyHandler

func ProxyHandler(
	targetURL *url.URL,
	basePath string,
	requestInterceptor func(req *fasthttp.Request),
	responseInterceptor func(resp *fasthttp.Response) error,
) fasthttp.RequestHandler

Default Proxy Handler

func RestProxy

func RestProxy(appCtx Context, modelName string) error

RestHandler

func RpcParamToGoType

func RpcParamToGoType(dataType RpcParamDataType) string

func RpcReturnToGoType

func RpcReturnToGoType(dataType RpcReturnDataType) string

func SetLogLevel

func SetLogLevel(level logger.LogLevel)

func StorageProxy

func StorageProxy(appCtx Context, bucketName string, routePath string) error

func Validate

func Validate(payload any, requestValidators ...ValidatorFunc) error

validate payload

func Warning

func Warning(v ...any)

func Warningf

func Warningf(format string, v ...any)

Types

type Acl

type Acl struct {
	Roles []string
	Check *string
	Using string
}

type AclTag

type AclTag struct {
	Read  Acl
	Write Acl
}

func UnmarshalAclTag

func UnmarshalAclTag(tag string) AclTag

type Bucket

type Bucket interface {
	Name() string
	Public() bool
	AllowedMimeTypes() []string
	FileSizeLimit() int
	AvifAutoDetection() bool
}

type BucketBase

type BucketBase struct{}

func (*BucketBase) AllowedMimeTypes

func (b *BucketBase) AllowedMimeTypes() []string

func (*BucketBase) AvifAutoDetection

func (b *BucketBase) AvifAutoDetection() bool

func (*BucketBase) FileSizeLimit

func (b *BucketBase) FileSizeLimit() *int

func (*BucketBase) Public

func (b *BucketBase) Public() bool

type Chain

type Chain interface {
	Append(middlewares ...MiddlewareFn) Chain
	Prepend(middlewares ...MiddlewareFn) Chain
	Then(httpMethod string, routeType RouteType, fn Controller) RouteHandlerFn
}

Chain defines a chain of middleware.

func NewChain

func NewChain(middlewares ...MiddlewareFn) Chain

This is a modified version of https://github.com/zeromicro/go-zero/blob/master/rest/chain/chain.go New creates a new Chain, memorizing the given list of middleware middlewares. New serves no other function, middlewares are only called upon a call to Then() or ThenFunc().

type ColumnTag

type ColumnTag struct {
	Name          string
	Type          string
	PrimaryKey    bool
	AutoIncrement bool
	Nullable      bool
	Default       any
	Unique        bool
}

definition of column tag, example : column:"name:id;type:bigint;primaryKey;autoIncrement;nullable:false;unique;default:now()"

func UnmarshalColumnTag

func UnmarshalColumnTag(tag string) ColumnTag

type Config

type Config struct {
	AccessToken            string           `mapstructure:"ACCESS_TOKEN"`
	AnonKey                string           `mapstructure:"ANON_KEY"`
	BreakerEnable          bool             `mapstructure:"BREAKER_ENABLE"`
	CorsAllowedOrigins     string           `mapstructure:"CORS_ALLOWED_ORIGINS"`
	CorsAllowedMethods     string           `mapstructure:"CORS_ALLOWED_METHODS"`
	CorsAllowedHeaders     string           `mapstructure:"CORS_ALLOWED_HEADERS"`
	CorsAllowCredentials   bool             `mapstructure:"CORS_ALLOWED_CREDENTIALS"`
	DeploymentTarget       DeploymentTarget `mapstructure:"DEPLOYMENT_TARGET"`
	Environment            string           `mapstructure:"ENVIRONMENT"`
	ProjectId              string           `mapstructure:"PROJECT_ID"`
	ProjectName            string           `mapstructure:"PROJECT_NAME"`
	ServiceKey             string           `mapstructure:"SERVICE_KEY"`
	ServerHost             string           `mapstructure:"SERVER_HOST"`
	ServerPort             string           `mapstructure:"SERVER_PORT"`
	SupabaseApiUrl         string           `mapstructure:"SUPABASE_API_URL"`
	SupabaseApiBasePath    string           `mapstructure:"SUPABASE_API_BASE_PATH"`
	SupabasePublicUrl      string           `mapstructure:"SUPABASE_PUBLIC_URL"`
	TraceEnable            bool             `mapstructure:"TRACE_ENABLE"`
	TraceCollector         string           `mapstructure:"TRACE_COLLECTOR"`
	TraceCollectorEndpoint string           `mapstructure:"TRACE_COLLECTOR_ENDPOINT"`
	Version                string           `mapstructure:"VERSION"`
}

func LoadConfig

func LoadConfig(path *string) (*Config, error)

The function `LoadConfig` loads a configuration file based on the provided path or uses default values if no path is provided.

type Context

type Context interface {
	Ctx() context.Context
	SetCtx(ctx context.Context)

	Config() *Config

	SendRpc(Rpc) error
	ExecuteRpc(Rpc) (any, error)

	SendJson(data any) error
	SendError(message string) error
	SendErrorWithCode(statusCode int, err error) error

	RequestContext() *fasthttp.RequestCtx

	Span() trace.Span
	SetSpan(span trace.Span)

	Tracer() trace.Tracer

	Write(data []byte)
	WriteError(err error)
}

The `Context` interface defines a set of methods that can be implemented by a struct to provide a context for handling HTTP requests in the Raiden framework.

type Controller

type Controller interface {
	BeforeAll(ctx Context) error
	AfterAll(ctx Context) error

	AfterGet(ctx Context) error
	BeforeGet(ctx Context) error
	Get(ctx Context) error

	AfterPost(ctx Context) error
	BeforePost(ctx Context) error
	Post(ctx Context) error

	AfterPut(ctx Context) error
	BeforePut(ctx Context) error
	Put(ctx Context) error

	AfterPatch(ctx Context) error
	BeforePatch(ctx Context) error
	Patch(ctx Context) error

	AfterDelete(ctx Context) error
	BeforeDelete(ctx Context) error
	Delete(ctx Context) error

	AfterOptions(ctx Context) error
	BeforeOptions(ctx Context) error
	Options(ctx Context) error

	AfterHead(ctx Context) error
	BeforeHead(ctx Context) error
	Head(ctx Context) error
}

The `Controller` interface defines a set of methods that a controller in the Raiden framework should implement. These methods correspond to different HTTP methods (GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD) and are used to handle incoming requests and generate responses. Each method has a "Before" and "After" counterpart, which can be used to perform pre-processing and post-processing tasks respectively.

type ControllerBase

type ControllerBase struct{}

The `ControllerBase` struct is a base struct that implements the `Controller` interface. It provides default implementations for all the methods defined in the interface. These default implementations return a `NotImplemented` error, indicating that the corresponding handler method is not implemented in the actual controller. The actual controller can embed the `ControllerBase` struct and override the methods as needed.

func (*ControllerBase) AfterAll

func (*ControllerBase) AfterAll(ctx Context) error

func (*ControllerBase) AfterDelete

func (*ControllerBase) AfterDelete(ctx Context) error

func (*ControllerBase) AfterGet

func (*ControllerBase) AfterGet(ctx Context) error

func (*ControllerBase) AfterHead

func (*ControllerBase) AfterHead(ctx Context) error

func (*ControllerBase) AfterOptions

func (*ControllerBase) AfterOptions(ctx Context) error

func (*ControllerBase) AfterPatch

func (*ControllerBase) AfterPatch(ctx Context) error

func (*ControllerBase) AfterPost

func (*ControllerBase) AfterPost(ctx Context) error

func (*ControllerBase) AfterPut

func (*ControllerBase) AfterPut(ctx Context) error

func (*ControllerBase) BeforeAll

func (*ControllerBase) BeforeAll(ctx Context) error

func (*ControllerBase) BeforeDelete

func (*ControllerBase) BeforeDelete(ctx Context) error

func (*ControllerBase) BeforeGet

func (*ControllerBase) BeforeGet(ctx Context) error

func (*ControllerBase) BeforeHead

func (*ControllerBase) BeforeHead(ctx Context) error

func (*ControllerBase) BeforeOptions

func (*ControllerBase) BeforeOptions(ctx Context) error

func (*ControllerBase) BeforePatch

func (*ControllerBase) BeforePatch(ctx Context) error

func (*ControllerBase) BeforePost

func (*ControllerBase) BeforePost(ctx Context) error

func (*ControllerBase) BeforePut

func (*ControllerBase) BeforePut(ctx Context) error

func (*ControllerBase) Delete

func (*ControllerBase) Delete(ctx Context) error

func (*ControllerBase) Get

func (*ControllerBase) Get(ctx Context) error

func (*ControllerBase) Head

func (*ControllerBase) Head(ctx Context) error

func (*ControllerBase) Options

func (*ControllerBase) Options(ctx Context) error

func (*ControllerBase) Patch

func (*ControllerBase) Patch(ctx Context) error

func (*ControllerBase) Post

func (*ControllerBase) Post(ctx Context) error

func (*ControllerBase) Put

func (*ControllerBase) Put(ctx Context) error

type CorsOptions

type CorsOptions struct {
	AllowedOrigins     []string
	AllowedMethods     []string
	AllowedHeaders     []string
	AllowCredentials   bool
	OptionsPassthrough bool
}

Handle cors

type Ctx

type Ctx struct {
	context.Context
	*fasthttp.RequestCtx
	// contains filtered or unexported fields
}

The `Ctx` struct is a struct that implements the `Context` interface in the Raiden framework. It embeds the `context.Context` and `*fasthttp.RequestCtx` types, which provide the context and request information for handling HTTP requests. Additionally, it has fields for storing the configuration (`config`), span (`span`), and tracer (`tracer`) for tracing and monitoring purposes.

func (*Ctx) Config

func (c *Ctx) Config() *Config

func (*Ctx) Ctx

func (c *Ctx) Ctx() context.Context

func (*Ctx) ExecuteRpc

func (c *Ctx) ExecuteRpc(rpc Rpc) (any, error)

func (*Ctx) RequestContext

func (c *Ctx) RequestContext() *fasthttp.RequestCtx

func (*Ctx) SendError

func (c *Ctx) SendError(message string) error

func (*Ctx) SendErrorWithCode

func (c *Ctx) SendErrorWithCode(statusCode int, err error) error

func (*Ctx) SendJson

func (c *Ctx) SendJson(data any) error

The `SendJson` function is a method of the `Ctx` struct in the Raiden framework. It is responsible for sending a JSON response to the client.

func (*Ctx) SendRpc

func (c *Ctx) SendRpc(rpc Rpc) error

func (*Ctx) SetCtx

func (c *Ctx) SetCtx(ctx context.Context)

func (*Ctx) SetSpan

func (c *Ctx) SetSpan(span trace.Span)

func (*Ctx) Span

func (c *Ctx) Span() trace.Span

func (*Ctx) Tracer

func (c *Ctx) Tracer() trace.Tracer

func (*Ctx) Write

func (c *Ctx) Write(data []byte)

The `Write` function is a method of the `Ctx` struct in the Raiden framework. It is responsible for writing the response body to the HTTP response.

func (*Ctx) WriteError

func (c *Ctx) WriteError(err error)

The `WriteError` function is a method of the `Ctx` struct in the Raiden framework. It is responsible for writing an error response to the HTTP response body.

type DeploymentTarget

type DeploymentTarget string
const (
	DeploymentTargetCloud      DeploymentTarget = "cloud"
	DeploymentTargetSelfHosted DeploymentTarget = "self_hosted"
)

type ErrorResponse

type ErrorResponse struct {
	StatusCode int    `json:"-"`
	Code       string `json:"code,omitempty"`
	Details    any    `json:"details,omitempty"`
	Hint       string `json:"hint,omitempty"`
	Message    string `json:"message"`
}

func (*ErrorResponse) Error

func (err *ErrorResponse) Error() string

type GracefulListener

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

--- graceful shutdown listener ----

func (*GracefulListener) Accept

func (ln *GracefulListener) Accept() (net.Conn, error)

Accept creates a conn

func (*GracefulListener) Addr

func (ln *GracefulListener) Addr() net.Addr

Addr returns the listen address

func (*GracefulListener) Close

func (ln *GracefulListener) Close() error

Close closes the inner listener and waits until all the pending open connections are closed before returning.

type HealthController

type HealthController struct {
	ControllerBase
	Payload *HealthRequest
	Result  HealthResponse
}

func (*HealthController) Get

func (c *HealthController) Get(ctx Context) error

type HealthRequest

type HealthRequest struct{}

type HealthResponse

type HealthResponse struct {
	Message string `json:"message"`
}

type JoinTag

type JoinTag struct {
	JoinType   RelationType
	PrimaryKey string
	ForeignKey string

	Through          string
	SourcePrimaryKey string
	SourceForeignKey string

	TargetPrimaryKey string
	TargetForeignKey string
}

definition of join tag, example: - join:"joinType:hasOne;primaryKey:id;foreignKey:candidate_id" - join:"joinType:hasMany;primaryKey:id;foreignKey:scouter_id" - join:"joinType:manyToMany;through:submission;sourcePrimaryKey:id;sourceForeignKey:candidate_id;targetPrimaryKey:id;targetForeign:candidate_id"

func UnmarshalJoinTag

func UnmarshalJoinTag(tag string) JoinTag

type MiddlewareFn

type MiddlewareFn func(next RouteHandlerFn) RouteHandlerFn

--- define type and constant ----

func BreakerMiddleware

func BreakerMiddleware(path string) MiddlewareFn

Handler open / close circuit breaker base on request error throttle

type ModelBase

type ModelBase struct {
}

type RelationType

type RelationType string
var (
	RelationTypeHasOne     RelationType = "hasOne"
	RelationTypeHasMany    RelationType = "hasMany"
	RelationTypeManyToMany RelationType = "manyToMany"
)

type RestController

type RestController struct {
	Controller
	ModelName string
}

----- Rest Controller -----

func (RestController) AfterAll

func (rc RestController) AfterAll(ctx Context) error

AfterAll implements Controller. Subtle: this method shadows the method (Controller).AfterAll of RestController.Controller.

func (RestController) AfterDelete

func (rc RestController) AfterDelete(ctx Context) error

AfterDelete implements Controller. Subtle: this method shadows the method (Controller).AfterDelete of RestController.Controller.

func (RestController) AfterGet

func (rc RestController) AfterGet(ctx Context) error

AfterGet implements Controller. Subtle: this method shadows the method (Controller).AfterGet of RestController.Controller.

func (RestController) AfterHead

func (rc RestController) AfterHead(ctx Context) error

AfterHead implements Controller. Subtle: this method shadows the method (Controller).AfterHead of RestController.Controller.

func (RestController) AfterOptions

func (rc RestController) AfterOptions(ctx Context) error

AfterOptions implements Controller. Subtle: this method shadows the method (Controller).AfterOptions of RestController.Controller.

func (RestController) AfterPatch

func (rc RestController) AfterPatch(ctx Context) error

AfterPatch implements Controller. Subtle: this method shadows the method (Controller).AfterPatch of RestController.Controller.

func (RestController) AfterPost

func (rc RestController) AfterPost(ctx Context) error

AfterPost implements Controller. Subtle: this method shadows the method (Controller).AfterPost of RestController.Controller.

func (RestController) AfterPut

func (rc RestController) AfterPut(ctx Context) error

AfterPut implements Controller. Subtle: this method shadows the method (Controller).AfterPut of RestController.Controller.

func (RestController) BeforeAll

func (rc RestController) BeforeAll(ctx Context) error

BeforeAll implements Controller.

func (RestController) BeforeDelete

func (rc RestController) BeforeDelete(ctx Context) error

BeforeDelete implements Controller. Subtle: this method shadows the method (Controller).BeforeDelete of RestController.Controller.

func (RestController) BeforeGet

func (rc RestController) BeforeGet(ctx Context) error

BeforeGet implements Controller. Subtle: this method shadows the method (Controller).BeforeGet of RestController.Controller.

func (RestController) BeforeHead

func (rc RestController) BeforeHead(ctx Context) error

BeforeHead implements Controller. Subtle: this method shadows the method (Controller).BeforeHead of RestController.Controller.

func (RestController) BeforeOptions

func (rc RestController) BeforeOptions(ctx Context) error

BeforeOptions implements Controller. Subtle: this method shadows the method (Controller).BeforeOptions of RestController.Controller.

func (RestController) BeforePatch

func (rc RestController) BeforePatch(ctx Context) error

BeforePatch implements Controller. Subtle: this method shadows the method (Controller).BeforePatch of RestController.Controller.

func (RestController) BeforePost

func (rc RestController) BeforePost(ctx Context) error

BeforePost implements Controller. Subtle: this method shadows the method (Controller).BeforePost of RestController.Controller.

func (RestController) BeforePut

func (rc RestController) BeforePut(ctx Context) error

BeforePut implements Controller. Subtle: this method shadows the method (Controller).BeforePut of RestController.Controller.

func (RestController) Delete

func (rc RestController) Delete(ctx Context) error

Delete implements Controller.

func (RestController) Get

func (rc RestController) Get(ctx Context) error

Get implements Controller.

func (RestController) Head

func (rc RestController) Head(ctx Context) error

Head implements Controller. Subtle: this method shadows the method (Controller).Head of RestController.Controller.

func (RestController) Options

func (rc RestController) Options(ctx Context) error

Options implements Controller. Subtle: this method shadows the method (Controller).Options of RestController.Controller.

func (RestController) Patch

func (rc RestController) Patch(ctx Context) error

Patch implements Controller.

func (RestController) Post

func (rc RestController) Post(ctx Context) error

Post implements Controller.

func (RestController) Put

func (rc RestController) Put(ctx Context) error

Put implements Controller.

type Role

type Role interface {
	// name
	Name() string

	// default 60
	ConnectionLimit() int

	// default true
	InheritRole() bool

	// default false
	CanBypassRls() bool

	// default false
	CanCreateDB() bool

	// default false
	CanCreateRole() bool

	// default false
	CanLogin() bool

	// default nil
	ValidUntil() *objects.SupabaseTime
}

TODO : support organizational unit roles

type RoleBase

type RoleBase struct {
}

TODO : support organizational unit roles

func (*RoleBase) CanBypassRls

func (r *RoleBase) CanBypassRls() bool

func (*RoleBase) CanCreateDB

func (r *RoleBase) CanCreateDB() bool

func (*RoleBase) CanCreateRole

func (r *RoleBase) CanCreateRole() bool

func (*RoleBase) CanLogin

func (r *RoleBase) CanLogin() bool

func (*RoleBase) ConnectionLimit

func (r *RoleBase) ConnectionLimit() int

----- Base Role Default Func -----

func (*RoleBase) InheritRole

func (r *RoleBase) InheritRole() bool

func (*RoleBase) ValidUntil

func (r *RoleBase) ValidUntil() *objects.SupabaseTime

type Route

type Route struct {
	Type       RouteType
	Methods    []string
	Path       string
	Controller Controller
	Model      any
	Storage    Bucket
}

----- define route type, constant and variable -----

type RouteHandlerFn

type RouteHandlerFn func(ctx Context) error

----- define route type, constant and variable -----

func TraceMiddleware

func TraceMiddleware(next RouteHandlerFn) RouteHandlerFn

extract trace id and span id from incoming request and create new trace context and span context, inject trace and span context to request context, and set span status

type RouteType

type RouteType string

----- define route type, constant and variable -----

const (
	RouteTypeCustom   RouteType = "custom"
	RouteTypeFunction RouteType = "function"
	RouteTypeRest     RouteType = "rest"
	RouteTypeRpc      RouteType = "rpc"
	RouteTypeRealtime RouteType = "realtime"
	RouteTypeStorage  RouteType = "storage"
)

type Rpc

type Rpc interface {
	BindModels()
	BindModel(model any, alias string) Rpc
	GetModels() map[string]RpcModel
	SetName(name string)
	GetName() string
	SetParams(params []RpcParam)
	GetParams() []RpcParam
	UseParamPrefix() bool
	SetSchema(schema string)
	GetSchema() string
	SetSecurity(security RpcSecurityType)
	GetSecurity() RpcSecurityType
	SetBehavior(behavior RpcBehaviorType)
	GetBehavior() RpcBehaviorType
	SetReturnType(returnType RpcReturnDataType)
	GetReturnType() RpcReturnDataType
	SetReturnTypeStmt(returnTypeStmt string)
	GetReturnTypeStmt() string
	SetRawDefinition(definition string)
	GetRawDefinition() string
	SetCompleteStmt(stmt string)
	GetCompleteStmt() string
}

----- Define type, variable and constant -----

type RpcBase

type RpcBase struct {
	Name              string
	Schema            string
	Params            []RpcParam
	Definition        string
	SecurityType      RpcSecurityType
	ReturnType        RpcReturnDataType
	ReturnTypeStmt    string
	Behavior          RpcBehaviorType
	CompleteStatement string
	Models            map[string]RpcModel
}

----- Define type, variable and constant -----

func (*RpcBase) BindModel

func (r *RpcBase) BindModel(model any, alias string) Rpc

func (*RpcBase) BindModels

func (r *RpcBase) BindModels()

func (*RpcBase) GetBehavior

func (r *RpcBase) GetBehavior() RpcBehaviorType

func (*RpcBase) GetCompleteStmt

func (r *RpcBase) GetCompleteStmt() string

func (*RpcBase) GetModels

func (r *RpcBase) GetModels() map[string]RpcModel

func (*RpcBase) GetName

func (r *RpcBase) GetName() string

func (*RpcBase) GetParams

func (r *RpcBase) GetParams() []RpcParam

func (*RpcBase) GetRawDefinition

func (r *RpcBase) GetRawDefinition() (d string)

func (*RpcBase) GetReturnType

func (r *RpcBase) GetReturnType() (rt RpcReturnDataType)

func (*RpcBase) GetReturnTypeStmt

func (r *RpcBase) GetReturnTypeStmt() string

func (*RpcBase) GetSchema

func (r *RpcBase) GetSchema() string

func (*RpcBase) GetSecurity

func (r *RpcBase) GetSecurity() RpcSecurityType

func (*RpcBase) SetBehavior

func (r *RpcBase) SetBehavior(behavior RpcBehaviorType)

func (*RpcBase) SetCompleteStmt

func (r *RpcBase) SetCompleteStmt(stmt string)

func (*RpcBase) SetName

func (r *RpcBase) SetName(name string)

func (*RpcBase) SetParams

func (r *RpcBase) SetParams(params []RpcParam)

func (*RpcBase) SetRawDefinition

func (r *RpcBase) SetRawDefinition(definition string)

func (*RpcBase) SetReturnType

func (r *RpcBase) SetReturnType(returnType RpcReturnDataType)

func (*RpcBase) SetReturnTypeStmt

func (r *RpcBase) SetReturnTypeStmt(returnTypeStmt string)

func (*RpcBase) SetSchema

func (r *RpcBase) SetSchema(schema string)

func (*RpcBase) SetSecurity

func (r *RpcBase) SetSecurity(security RpcSecurityType)

func (*RpcBase) UseParamPrefix

func (r *RpcBase) UseParamPrefix() bool

type RpcBehaviorType

type RpcBehaviorType string

----- Define type, variable and constant -----

type RpcModel

type RpcModel struct {
	Alias string
	Model any
}

----- Define type, variable and constant -----

type RpcParam

type RpcParam struct {
	Name    string
	Type    RpcParamDataType
	Default *string
	Value   any
}

----- Define type, variable and constant -----

type RpcParamDataType

type RpcParamDataType string

---- Define rpc data type -----

const (
	RpcParamDataTypeInteger          RpcParamDataType = "INTEGER"
	RpcParamDataTypeBigInt           RpcParamDataType = "BIGINT"
	RpcParamDataTypeReal             RpcParamDataType = "REAL"
	RpcParamDataTypeDoublePreci      RpcParamDataType = "DOUBLE PRECISION"
	RpcParamDataTypeText             RpcParamDataType = "TEXT"
	RpcParamDataTypeVarchar          RpcParamDataType = "CHARACTER VARYING"
	RpcParamDataTypeVarcharAlias     RpcParamDataType = "VARCHAR"
	RpcParamDataTypeBoolean          RpcParamDataType = "BOOLEAN"
	RpcParamDataTypeBytea            RpcParamDataType = "BYTEA"
	RpcParamDataTypeTimestamp        RpcParamDataType = "TIMESTAMP WITHOUT TIME ZONE"
	RpcParamDataTypeTimestampAlias   RpcParamDataType = "TIMESTAMP"
	RpcParamDataTypeTimestampTZ      RpcParamDataType = "TIMESTAMP WITH TIME ZONE"
	RpcParamDataTypeTimestampTZAlias RpcParamDataType = "TIMESTAMPZ"
	RpcParamDataTypeJSON             RpcParamDataType = "JSON"
	RpcParamDataTypeJSONB            RpcParamDataType = "JSONB"
)

Define constants for rpc input data type

func GetValidRpcParamType

func GetValidRpcParamType(pType string, returnAlias bool) (RpcParamDataType, error)

type RpcParamTag

type RpcParamTag struct {
	Name         string
	Type         string
	DefaultValue string
}

----- Define type, variable and constant -----

func UnmarshalRpcParamTag

func UnmarshalRpcParamTag(tag string) (RpcParamTag, error)

type RpcParams

type RpcParams []RpcParam

----- Define type, variable and constant -----

func (RpcParams) ToQuery

func (p RpcParams) ToQuery(userPrefix bool) (string, error)

----- Rpc Param Functionality -----

type RpcReturnDataType

type RpcReturnDataType string
const (
	RpcReturnDataTypeInteger          RpcReturnDataType = "INTEGER"
	RpcReturnDataTypeBigInt           RpcReturnDataType = "BIGINT"
	RpcReturnDataTypeReal             RpcReturnDataType = "REAL"
	RpcReturnDataTypeDoublePreci      RpcReturnDataType = "DOUBLE PRECISION"
	RpcReturnDataTypeText             RpcReturnDataType = "TEXT"
	RpcReturnDataTypeVarchar          RpcReturnDataType = "CHARACTER VARYING"
	RpcReturnDataTypeVarcharAlias     RpcReturnDataType = "VARCHAR"
	RpcReturnDataTypeBoolean          RpcReturnDataType = "BOOLEAN"
	RpcReturnDataTypeBytea            RpcReturnDataType = "BYTEA"
	RpcReturnDataTypeTimestamp        RpcReturnDataType = "TIMESTAMP WITHOUT TIME ZONE"
	RpcReturnDataTypeTimestampAlias   RpcReturnDataType = "TIMESTAMP"
	RpcReturnDataTypeTimestampTZ      RpcReturnDataType = "TIMESTAMP WITH TIME ZONE"
	RpcReturnDataTypeTimestampTZAlias RpcReturnDataType = "TIMESTAMPZ"
	RpcReturnDataTypeJSON             RpcReturnDataType = "JSON"
	RpcReturnDataTypeJSONB            RpcReturnDataType = "JSONB"
	RpcReturnDataTypeRecord           RpcReturnDataType = "RECORD" // like tuple
	RpcReturnDataTypeTable            RpcReturnDataType = "TABLE"
	RpcReturnDataTypeSetOf            RpcReturnDataType = "SETOF"
	RpcReturnDataTypeVoid             RpcReturnDataType = "VOID"
)

Define constants for rpc return data type

func GetValidRpcReturnType

func GetValidRpcReturnType(pType string, returnAlias bool) (RpcReturnDataType, error)

type RpcSecurityType

type RpcSecurityType string

----- Define type, variable and constant -----

type Server

type Server struct {
	Config       *Config
	Router       *router
	HttpServer   *fasthttp.Server
	ShutdownFunc []func(ctx context.Context) error
}

--- server configuration ----

func NewServer

func NewServer(config *Config) *Server

func (*Server) RegisterRoute

func (s *Server) RegisterRoute(routes []*Route)

func (*Server) Run

func (s *Server) Run()

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) Use

func (s *Server) Use(middleware MiddlewareFn)

type StorageController

type StorageController struct {
	Controller
	BucketName string
	RoutePath  string
}

----- Rest Controller -----

func (StorageController) AfterAll

func (rc StorageController) AfterAll(ctx Context) error

AfterAll implements Controller. Subtle: this method shadows the method (Controller).AfterAll of RestController.Controller.

func (StorageController) AfterDelete

func (rc StorageController) AfterDelete(ctx Context) error

AfterDelete implements Controller. Subtle: this method shadows the method (Controller).AfterDelete of StorageController.Controller.

func (StorageController) AfterGet

func (rc StorageController) AfterGet(ctx Context) error

AfterGet implements Controller. Subtle: this method shadows the method (Controller).AfterGet of StorageController.Controller.

func (StorageController) AfterHead

func (rc StorageController) AfterHead(ctx Context) error

AfterHead implements Controller. Subtle: this method shadows the method (Controller).AfterHead of StorageController.Controller.

func (StorageController) AfterOptions

func (rc StorageController) AfterOptions(ctx Context) error

AfterOptions implements Controller. Subtle: this method shadows the method (Controller).AfterOptions of StorageController.Controller.

func (StorageController) AfterPatch

func (rc StorageController) AfterPatch(ctx Context) error

AfterPatch implements Controller. Subtle: this method shadows the method (Controller).AfterPatch of StorageController.Controller.

func (StorageController) AfterPost

func (rc StorageController) AfterPost(ctx Context) error

AfterPost implements Controller. Subtle: this method shadows the method (Controller).AfterPost of StorageController.Controller.

func (StorageController) AfterPut

func (rc StorageController) AfterPut(ctx Context) error

AfterPut implements Controller. Subtle: this method shadows the method (Controller).AfterPut of StorageController.Controller.

func (StorageController) BeforeAll

func (rc StorageController) BeforeAll(ctx Context) error

BeforeAll implements Controller.

func (StorageController) BeforeDelete

func (rc StorageController) BeforeDelete(ctx Context) error

BeforeDelete implements Controller. Subtle: this method shadows the method (Controller).BeforeDelete of StorageController.Controller.

func (StorageController) BeforeGet

func (rc StorageController) BeforeGet(ctx Context) error

BeforeGet implements Controller. Subtle: this method shadows the method (Controller).BeforeGet of StorageController.Controller.

func (StorageController) BeforeHead

func (rc StorageController) BeforeHead(ctx Context) error

BeforeHead implements Controller. Subtle: this method shadows the method (Controller).BeforeHead of StorageController.Controller.

func (StorageController) BeforeOptions

func (rc StorageController) BeforeOptions(ctx Context) error

BeforeOptions implements Controller. Subtle: this method shadows the method (Controller).BeforeOptions of StorageController.Controller.

func (StorageController) BeforePatch

func (rc StorageController) BeforePatch(ctx Context) error

BeforePatch implements Controller. Subtle: this method shadows the method (Controller).BeforePatch of StorageController.Controller.

func (StorageController) BeforePost

func (rc StorageController) BeforePost(ctx Context) error

BeforePost implements Controller. Subtle: this method shadows the method (Controller).BeforePost of StorageController.Controller.

func (StorageController) BeforePut

func (rc StorageController) BeforePut(ctx Context) error

BeforePut implements Controller. Subtle: this method shadows the method (Controller).BeforePut of StorageController.Controller.

func (StorageController) Delete

func (rc StorageController) Delete(ctx Context) error

Delete implements Controller.

func (StorageController) Get

func (rc StorageController) Get(ctx Context) error

Get implements Controller.

func (StorageController) Head

func (rc StorageController) Head(ctx Context) error

Head implements Controller. Subtle: this method shadows the method (Controller).Head of StorageController.Controller.

func (StorageController) Options

func (rc StorageController) Options(ctx Context) error

Options implements Controller. Subtle: this method shadows the method (Controller).Options of StorageController.Controller.

func (StorageController) Patch

func (rc StorageController) Patch(ctx Context) error

Patch implements Controller.

func (StorageController) Post

func (rc StorageController) Post(ctx Context) error

Post implements Controller.

func (StorageController) Put

func (rc StorageController) Put(ctx Context) error

Put implements Controller.

type ValidatorFunc

type ValidatorFunc struct {
	Name      string
	Validator validator.Func
}

custom struct for validation function

type WithValidator

type WithValidator func(name string, validateFn validator.Func) ValidatorFunc

custom type for custom validation function

Jump to

Keyboard shortcuts

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