Documentation
¶
Index ¶
- Variables
- func MakePlugin[T Base](super bool) (CallFn[T], RegisterFn[T])
- func Register(p Base)
- func Translate(ctx EchoContext, key string) string
- func TranslateWithData(lang i18n.Language, key string, data any) string
- type Base
- type CDN
- type Cache
- type CallFn
- type Caller
- type Config
- type ConfigField
- type ConfigFieldOption
- type ConfigFieldUIOptions
- type ConfigType
- type Connector
- type Data
- type EchoContext
- type Embed
- type EmbedConfig
- type ExternalLoginUserInfo
- type Info
- type InputType
- type LoadingAction
- type LoadingActionType
- type OnCompleteAction
- type RegisterFn
- type Render
- type RenderConfig
- type Sidebar
- type SidebarConfig
- type Stack
- type TagSelectorOption
- type TranslateFn
- type Translator
- type UIOptionAction
Constants ¶
This section is empty.
Variables ¶
var (
// CallBase is a function that calls all registered base plugins
CallBase, _ = MakePlugin[Base](true)
)
var (
// CallCDN is a function that calls all registered parsers
CallCDN, _ = MakePlugin[CDN](false)
)
var (
// CallCache is a function that calls all registered cache
CallCache, _ = MakePlugin[Cache](false)
)
var (
// CallConfig is a function that calls all registered config plugins
CallConfig, _ = MakePlugin[Config](true)
)
var (
// CallConnector is a function that calls all registered connectors
CallConnector, _ = MakePlugin[Connector](false)
)
var (
// CallEmbed is a function that calls all registered parsers
CallEmbed, _ = MakePlugin[Embed](false)
)
var (
// CallRender is a function that calls all registered parsers
CallRender, _ = MakePlugin[Render](false)
)
var (
// CallRender is a function that calls all registered parsers
CallSidebar, _ = MakePlugin[Sidebar](false)
)
var ( DefaultCDNFileType = map[string]bool{ ".ico": true, ".json": true, ".css": true, ".js": true, ".webp": true, ".woff2": true, ".woff": true, ".jpg": true, ".svg": true, ".png": true, ".map": true, ".txt": true, } )
var StatusManager = statusManager{ // contains filtered or unexported fields }
StatusManager is a manager that manages the status of plugins Init Plugins: json.Unmarshal([]byte(`{"plugin1": true, "plugin2": false}`), &plugin.StatusManager) Dump Status: json.Marshal(plugin.StatusManager)
Functions ¶
func MakePlugin ¶
func MakePlugin[T Base](super bool) (CallFn[T], RegisterFn[T])
MakePlugin creates a plugin caller and register stack manager The parameter super presents if the plugin can be disabled. It returns a register function and a caller function The register function is used to register a plugin, it will be called in the plugin's init function The caller function is used to call all registered plugins
func Translate ¶
func Translate(ctx EchoContext, key string) string
Translate translates the key to the current language of the context
Types ¶
type Base ¶
type Base interface {
// Info returns the plugin information
Info() Info
}
Base is the base plugin
type Cache ¶
type Cache interface {
Base
GetString(ctx context.Context, key string) (data string, exist bool, err error)
SetString(ctx context.Context, key, value string, ttl time.Duration) (err error)
GetInt64(ctx context.Context, key string) (data int64, exist bool, err error)
SetInt64(ctx context.Context, key string, value int64, ttl time.Duration) (err error)
Increase(ctx context.Context, key string, value int64) (data int64, err error)
Decrease(ctx context.Context, key string, value int64) (data int64, err error)
Del(ctx context.Context, key string) (err error)
Flush(ctx context.Context) (err error)
}
type Config ¶
type Config interface {
Base
// ConfigFields returns the list of config fields
ConfigFields() []ConfigField
// ConfigReceiver receives the config data, it calls when the config is saved or initialized.
// We recommend to unmarshal the data to a struct, and then use the struct to do something.
// The config is encoded in JSON format.
// It depends on the definition of ConfigFields.
ConfigReceiver(config []byte) error
}
type ConfigField ¶
type ConfigField struct {
Name string `json:"name"`
Type ConfigType `json:"type"`
Title Translator `json:"title"`
Description Translator `json:"description"`
Required bool `json:"required"`
Value any `json:"value"`
UIOptions ConfigFieldUIOptions `json:"ui_options"`
Options []ConfigFieldOption `json:"options,omitempty"`
}
type ConfigFieldOption ¶
type ConfigFieldOption struct {
Label Translator `json:"label"`
Value string `json:"value"`
}
type ConfigFieldUIOptions ¶
type ConfigFieldUIOptions struct {
Placeholder Translator `json:"placeholder"`
Rows string `json:"rows,omitempty"`
InputType InputType `json:"input_type,omitempty"`
Label Translator `json:"label"`
Action *UIOptionAction `json:"action,omitempty"`
Variant string `json:"variant,omitempty"`
Text Translator `json:"text"`
ClassName string `json:"class_name,omitempty"`
FieldClassName string `json:"field_class_name,omitempty"`
}
type ConfigType ¶
type ConfigType string
const ( ConfigTypeInput ConfigType = "input" ConfigTypeTextarea ConfigType = "textarea" ConfigTypeCheckbox ConfigType = "checkbox" ConfigTypeRadio ConfigType = "radio" ConfigTypeSelect ConfigType = "select" ConfigTypeUpload ConfigType = "upload" ConfigTypeTimezone ConfigType = "timezone" ConfigTypeSwitch ConfigType = "switch" ConfigTypeButton ConfigType = "button" ConfigTypeLegend ConfigType = "legend" ConfigTypeTagSelector ConfigType = "tag_selector" )
type Connector ¶
type Connector interface {
Base
// ConnectorLogoSVG presents the logo in svg format
ConnectorLogoSVG() string
// ConnectorName presents the name of the connector
// e.g. Facebook, Twitter, Instagram
ConnectorName() Translator
// ConnectorSlugName presents the slug name of the connector
// Please use lowercase and hyphen as the separator
// e.g. facebook, twitter, instagram
ConnectorSlugName() string
// ConnectorSender presents the sender of the connector
// It handles the start endpoint of the connector
// receiverURL is the whole URL of the receiver
ConnectorSender(ctx *echo.Context, receiverURL string) (redirectURL string)
// ConnectorReceiver presents the receiver of the connector
// It handles the callback endpoint of the connector, and returns the
ConnectorReceiver(ctx *echo.Context, receiverURL string) (userInfo ExternalLoginUserInfo, err error)
}
type EchoContext ¶
type Embed ¶
type Embed interface {
Base
GetEmbedConfigs(ctx echo.Context) (embedConfigs []*EmbedConfig, err error)
}
type EmbedConfig ¶
type ExternalLoginUserInfo ¶
type ExternalLoginUserInfo struct {
// required. The unique user ID provided by the third-party login
ExternalID string
// optional. This name is used preferentially during registration
DisplayName string
// optional. This username is used preferentially during registration
Username string
// optional. If email exist will bind the existing user
// IMPORTANT: The email must have been verified. If the plugin can't guarantee the email is verified, please leave it empty.
Email string
// optional. The avatar URL provided by the third-party login platform
Avatar string
// optional. The original user information provided by the third-party login platform
MetaInfo string
}
ExternalLoginUserInfo external login user info
type Info ¶
type Info struct {
Name Translator
SlugName string
Description Translator
Author string
Version string
Link string
}
Info presents the plugin information
type InputType ¶
type InputType string
const ( InputTypeText InputType = "text" InputTypeColor InputType = "color" InputTypeDate InputType = "date" InputTypeDatetime InputType = "datetime-local" InputTypeEmail InputType = "email" InputTypeMonth InputType = "month" InputTypeNumber InputType = "number" InputTypePassword InputType = "password" InputTypeRange InputType = "range" InputTypeSearch InputType = "search" InputTypeTel InputType = "tel" InputTypeTime InputType = "time" InputTypeUrl InputType = "url" InputTypeWeek InputType = "week" )
type LoadingAction ¶
type LoadingAction struct {
Text Translator `json:"text"`
State LoadingActionType `json:"state"`
}
type LoadingActionType ¶
type LoadingActionType string
const ( LoadingActionStateNone LoadingActionType = "none" LoadingActionStatePending LoadingActionType = "pending" LoadingActionStateComplete LoadingActionType = "completed" )
type OnCompleteAction ¶
type RegisterFn ¶
type RegisterFn[T Base] func(p T)
type Render ¶
type Render interface {
Base
GetRenderConfig(ctx echo.Context) (renderConfig *RenderConfig)
}
type RenderConfig ¶
type RenderConfig struct {
SelectTheme string `json:"select_theme"`
}
type Sidebar ¶
type Sidebar interface {
Base
GetSidebarConfig() (sidebarConfig *SidebarConfig, err error)
}
type SidebarConfig ¶
type SidebarConfig struct {
Tags []*TagSelectorOption `json:"tags"`
LinksText string `json:"links_text"`
}
type TagSelectorOption ¶
type TagSelectorOption struct {
TagID string `json:"tag_id"`
SlugName string `json:"slug_name"`
DisplayName string `json:"display_name"`
Recommend bool `json:"recommend"`
Reserved bool `json:"reserved"`
}
TagSelectorOption represents a tag option in the tag selector config value field
type TranslateFn ¶
type TranslateFn func(ctx EchoContext) string
TranslateFn presents a generator of translated string. We use it to delegate the translation work outside the plugin.
type Translator ¶
type Translator struct {
Fn TranslateFn
}
Translator contains a function that translates the key to the current language of the context
func MakeTranslator ¶
func MakeTranslator(key string) Translator
MakeTranslator generates a translator from the key
func (Translator) Translate ¶
func (t Translator) Translate(ctx EchoContext) string
Translate translates the key to the current language of the context
type UIOptionAction ¶
type UIOptionAction struct {
Url string `json:"url"`
Method string `json:"method,omitempty"`
Loading *LoadingAction `json:"loading,omitempty"`
OnComplete *OnCompleteAction `json:"on_complete,omitempty"`
}