{"modulePath":"github.com/answerdev/answer","version":"v1.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\n## Constants\n\n```go\nconst (\n\tSearchContentStatusAvailable = 1\n\tSearchContentStatusDeleted   = 10\n)\n```\n\n## Variables\n\n```go\nvar (\n\tCallAgent, _ = MakePlugin[Agent](true)\n)\n```\n\n```go\nvar (\n\t// CallBase is a function that calls all registered base plugins\n\tCallBase, _ = MakePlugin[Base](true)\n)\n```\n\n```go\nvar (\n\t// CallCache is a function that calls all registered cache\n\tCallCache, _ = MakePlugin[Cache](false)\n)\n```\n\n```go\nvar (\n\t// CallConfig is a function that calls all registered config plugins\n\tCallConfig, _ = MakePlugin[Config](true)\n)\n```\n\n```go\nvar (\n\t// CallConnector is a function that calls all registered connectors\n\tCallConnector, _ = MakePlugin[Connector](false)\n)\n```\n\n```go\nvar (\n\t// CallFilter is a function that calls all registered parsers\n\tCallFilter, _ = MakePlugin[Filter](false)\n)\n```\n\n```go\nvar (\n\t// CallParser is a function that calls all registered parsers\n\tCallParser, _ = MakePlugin[Parser](false)\n)\n```\n\n```go\nvar (\n\t// CallUserCenter is a function that calls all registered parsers\n\tCallSearch, _ = MakePlugin[Search](false)\n)\n```\n\n```go\nvar (\n\t// CallStorage is a function that calls all registered storage\n\tCallStorage, _ = MakePlugin[Storage](false)\n)\n```\n\n```go\nvar (\n\t// CallUserCenter is a function that calls all registered parsers\n\tCallUserCenter, _ = MakePlugin[UserCenter](false)\n)\n```\n\n```go\nvar (\n\tDefaultFileTypeCheckMapping = map[UploadSource]map[string]bool{\n\t\tUserAvatar: {\n\t\t\t\".jpg\":  true,\n\t\t\t\".jpeg\": true,\n\t\t\t\".png\":  true,\n\t\t\t\".webp\": true,\n\t\t},\n\t\tUserPost: {\n\t\t\t\".jpg\":  true,\n\t\t\t\".jpeg\": true,\n\t\t\t\".png\":  true,\n\t\t\t\".gif\":  true,\n\t\t\t\".webp\": true,\n\t\t},\n\t\tAdminBranding: {\n\t\t\t\".jpg\":  true,\n\t\t\t\".jpeg\": true,\n\t\t\t\".png\":  true,\n\t\t\t\".ico\":  true,\n\t\t},\n\t}\n)\n```\n\n```go\nvar StatusManager = statusManager{\n\t// contains filtered or unexported fields\n}\n```\nStatusManager is a manager that manages the status of plugins Init Plugins: json.Unmarshal(\\[]byte(\\`{\"plugin1\": true, \"plugin2\": false}\\`), \u0026plugin.StatusManager) Dump Status: json.Marshal(plugin.StatusManager)\n\n## Functions\n\n```go\nfunc MakePlugin[T Base](super bool) (CallFn[T], RegisterFn[T])\n```\nMakePlugin 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\n\n```go\nfunc RankAgentEnabled() (enabled bool)\n```\n\n```go\nfunc Register(p Base)\n```\nRegister registers a plugin\n\n```go\nfunc RegisterGetSiteURLFunc(fn func() string)\n```\nRegisterGetSiteURLFunc Register a function to get the site url.\n\n```go\nfunc SiteURL() string\n```\nSiteURL The site url is the domain address of the current site. e.g. [http://localhost:8080](http://localhost:8080) When some Agent plugins want to redirect to the origin site, it can use this function to get the site url.\n\n```go\nfunc Translate(ctx *GinContext, key string) string\n```\nTranslate translates the key to the current language of the context\n\n```go\nfunc UserCenterEnabled() (enabled bool)\n```\n\n## Types\n\n```go\ntype Agent interface {\n\tBase\n\tRegisterUnAuthRouter(r *gin.RouterGroup)\n\tRegisterAuthUserRouter(r *gin.RouterGroup)\n\tRegisterAuthAdminRouter(r *gin.RouterGroup)\n}\n```\n\n```go\ntype Base interface {\n\t// Info returns the plugin information\n\tInfo() Info\n}\n```\nBase is the base plugin\n\n```go\ntype Cache interface {\n\tBase\n\n\tGetString(ctx context.Context, key string) (data string, exist bool, err error)\n\tSetString(ctx context.Context, key, value string, ttl time.Duration) (err error)\n\tGetInt64(ctx context.Context, key string) (data int64, exist bool, err error)\n\tSetInt64(ctx context.Context, key string, value int64, ttl time.Duration) (err error)\n\tIncrease(ctx context.Context, key string, value int64) (data int64, err error)\n\tDecrease(ctx context.Context, key string, value int64) (data int64, err error)\n\tDel(ctx context.Context, key string) (err error)\n\tFlush(ctx context.Context) (err error)\n}\n```\n\n```go\ntype CallFn[T Base] func(fn Caller[T]) error\n```\n\n```go\ntype Caller[T Base] func(p T) error\n```\n\n```go\ntype Config interface {\n\tBase\n\n\t// ConfigFields returns the list of config fields\n\tConfigFields() []ConfigField\n\n\t// ConfigReceiver receives the config data, it calls when the config is saved or initialized.\n\t// We recommend to unmarshal the data to a struct, and then use the struct to do something.\n\t// The config is encoded in JSON format.\n\t// It depends on the definition of ConfigFields.\n\tConfigReceiver(config []byte) error\n}\n```\n\n```go\ntype ConfigField struct {\n\tName        string               `json:\"name\"`\n\tType        ConfigType           `json:\"type\"`\n\tTitle       Translator           `json:\"title\"`\n\tDescription Translator           `json:\"description\"`\n\tRequired    bool                 `json:\"required\"`\n\tValue       any                  `json:\"value\"`\n\tUIOptions   ConfigFieldUIOptions `json:\"ui_options\"`\n\tOptions     []ConfigFieldOption  `json:\"options,omitempty\"`\n}\n```\n\n```go\ntype ConfigFieldOption struct {\n\tLabel Translator `json:\"label\"`\n\tValue string     `json:\"value\"`\n}\n```\n\n```go\ntype ConfigFieldUIOptions struct {\n\tPlaceholder Translator      `json:\"placeholder,omitempty\"`\n\tRows        string          `json:\"rows,omitempty\"`\n\tInputType   InputType       `json:\"input_type,omitempty\"`\n\tLabel       Translator      `json:\"label,omitempty\"`\n\tAction      *UIOptionAction `json:\"action,omitempty\"`\n\tVariant     string          `json:\"variant,omitempty\"`\n\tText        Translator      `json:\"text,omitempty\"`\n}\n```\n\n```go\ntype ConfigType string\n```\n\n```go\nconst (\n\tConfigTypeInput    ConfigType = \"input\"\n\tConfigTypeTextarea ConfigType = \"textarea\"\n\tConfigTypeCheckbox ConfigType = \"checkbox\"\n\tConfigTypeRadio    ConfigType = \"radio\"\n\tConfigTypeSelect   ConfigType = \"select\"\n\tConfigTypeUpload   ConfigType = \"upload\"\n\tConfigTypeTimezone ConfigType = \"timezone\"\n\tConfigTypeSwitch   ConfigType = \"switch\"\n\tConfigTypeButton   ConfigType = \"button\"\n)\n```\n\n```go\ntype Connector interface {\n\tBase\n\n\t// ConnectorLogoSVG presents the logo in svg format\n\tConnectorLogoSVG() string\n\n\t// ConnectorName presents the name of the connector\n\t// e.g. Facebook, Twitter, Instagram\n\tConnectorName() Translator\n\n\t// ConnectorSlugName presents the slug name of the connector\n\t// Please use lowercase and hyphen as the separator\n\t// e.g. facebook, twitter, instagram\n\tConnectorSlugName() string\n\n\t// ConnectorSender presents the sender of the connector\n\t// It handles the start endpoint of the connector\n\t// receiverURL is the whole URL of the receiver\n\tConnectorSender(ctx *GinContext, receiverURL string) (redirectURL string)\n\n\t// ConnectorReceiver presents the receiver of the connector\n\t// It handles the callback endpoint of the connector, and returns the\n\tConnectorReceiver(ctx *GinContext, receiverURL string) (userInfo ExternalLoginUserInfo, err error)\n}\n```\n\n```go\ntype ControlCenter struct {\n\tName  string `json:\"name\"`\n\tLabel string `json:\"label\"`\n\tUrl   string `json:\"url\"`\n}\n```\n\n```go\ntype ExternalLoginUserInfo struct {\n\t// required. The unique user ID provided by the third-party login\n\tExternalID string\n\t// optional. This name is used preferentially during registration\n\tDisplayName string\n\t// optional. This username is used preferentially during registration\n\tUsername string\n\t// optional. If email exist will bind the existing user\n\t// IMPORTANT: The email must have been verified. If the plugin can't guarantee the email is verified, please leave it empty.\n\tEmail string\n\t// optional. The avatar URL provided by the third-party login platform\n\tAvatar string\n\t// optional. The original user information provided by the third-party login platform\n\tMetaInfo string\n}\n```\nExternalLoginUserInfo external login user info\n\n```go\ntype Filter interface {\n\tBase\n\tFilterText(text string) (err error)\n}\n```\n\n```go\ntype GinContext = gin.Context\n```\nGinContext is a wrapper of gin.Context We export it to make it easy to use in plugins\n\n```go\ntype Info struct {\n\tName        Translator\n\tSlugName    string\n\tDescription Translator\n\tAuthor      string\n\tVersion     string\n\tLink        string\n}\n```\nInfo presents the plugin information\n\n```go\ntype InputType string\n```\n\n```go\nconst (\n\tInputTypeText     InputType = \"text\"\n\tInputTypeColor    InputType = \"color\"\n\tInputTypeDate     InputType = \"date\"\n\tInputTypeDatetime InputType = \"datetime-local\"\n\tInputTypeEmail    InputType = \"email\"\n\tInputTypeMonth    InputType = \"month\"\n\tInputTypeNumber   InputType = \"number\"\n\tInputTypePassword InputType = \"password\"\n\tInputTypeRange    InputType = \"range\"\n\tInputTypeSearch   InputType = \"search\"\n\tInputTypeTel      InputType = \"tel\"\n\tInputTypeTime     InputType = \"time\"\n\tInputTypeUrl      InputType = \"url\"\n\tInputTypeWeek     InputType = \"week\"\n)\n```\n\n```go\ntype LoadingAction struct {\n\tText  Translator        `json:\"text\"`\n\tState LoadingActionType `json:\"state\"`\n}\n```\n\n```go\ntype LoadingActionType string\n```\n\n```go\nconst (\n\tLoadingActionStateNone     LoadingActionType = \"none\"\n\tLoadingActionStatePending  LoadingActionType = \"pending\"\n\tLoadingActionStateComplete LoadingActionType = \"completed\"\n)\n```\n\n```go\ntype OnCompleteAction struct {\n\tToastReturnMessage bool `json:\"toast_return_message\"`\n\tRefreshFormConfig  bool `json:\"refresh_form_config\"`\n}\n```\n\n```go\ntype Parser interface {\n\tBase\n\tParse(text string) (string, error)\n}\n```\n\n```go\ntype PersonalBranding struct {\n\tIcon  string `json:\"icon\"`\n\tName  string `json:\"name\"`\n\tLabel string `json:\"label\"`\n\tUrl   string `json:\"url\"`\n}\n```\n\n```go\ntype RegisterFn[T Base] func(p T)\n```\n\n```go\ntype Search interface {\n\tBase\n\tDescription() SearchDesc\n\tRegisterSyncer(ctx context.Context, syncer SearchSyncer)\n\tSearchContents(ctx context.Context, cond *SearchBasicCond) (res []SearchResult, total int64, err error)\n\tSearchQuestions(ctx context.Context, cond *SearchBasicCond) (res []SearchResult, total int64, err error)\n\tSearchAnswers(ctx context.Context, cond *SearchBasicCond) (res []SearchResult, total int64, err error)\n\tUpdateContent(ctx context.Context, content *SearchContent) (err error)\n\tDeleteContent(ctx context.Context, objectID string) (err error)\n}\n```\n\n```go\ntype SearchAcceptedCond int\n```\n\n```go\nconst (\n\tAcceptedCondAll SearchAcceptedCond = iota\n\tAcceptedCondTrue\n\tAcceptedCondFalse\n)\n```\n\n```go\ntype SearchBasicCond struct {\n\t// From zero-based page number\n\tPage int\n\t// Page size\n\tPageSize int\n\n\t// The keywords for search.\n\tWords []string\n\t// TagIDs is a list of tag IDs.\n\tTagIDs []string\n\t// The object's owner user ID.\n\tUserID string\n\t// The order of the search result.\n\tOrder SearchOrderCond\n\n\t// Weathers the question is accepted or not. Only support search question.\n\tQuestionAccepted SearchAcceptedCond\n\t// Weathers the answer is accepted or not. Only support search answer.\n\tAnswerAccepted SearchAcceptedCond\n\n\t// Only support search answer.\n\tQuestionID string\n\n\t// greater than or equal to the number of votes.\n\tVoteAmount int\n\t// greater than or equal to the number of views.\n\tViewAmount int\n\t// greater than or equal to the number of answers. Only support search question.\n\tAnswerAmount int\n}\n```\n\n```go\ntype SearchContent struct {\n\tObjectID    string              `json:\"objectID\"`\n\tTitle       string              `json:\"title\"`\n\tType        string              `json:\"type\"`\n\tContent     string              `json:\"content\"`\n\tAnswers     int64               `json:\"answers\"`\n\tStatus      SearchContentStatus `json:\"status\"`\n\tTags        []string            `json:\"tags\"`\n\tQuestionID  string              `json:\"questionID\"`\n\tUserID      string              `json:\"userID\"`\n\tViews       int64               `json:\"views\"`\n\tCreated     int64               `json:\"created\"`\n\tActive      int64               `json:\"active\"`\n\tScore       int64               `json:\"score\"`\n\tHasAccepted bool                `json:\"hasAccepted\"`\n}\n```\n\n```go\ntype SearchContentStatus int\n```\n\n```go\ntype SearchDesc struct {\n\t// A svg icon it wil be display in search result page. optional\n\tIcon string `json:\"icon\"`\n\t// The link address of the search engine. optional\n\tLink string `json:\"link\"`\n}\n```\n\n```go\ntype SearchOrderCond string\n```\n\n```go\nconst (\n\tSearchNewestOrder    SearchOrderCond = \"newest\"\n\tSearchActiveOrder    SearchOrderCond = \"active\"\n\tSearchScoreOrder     SearchOrderCond = \"score\"\n\tSearchRelevanceOrder SearchOrderCond = \"relevance\"\n)\n```\n\n```go\ntype SearchResult struct {\n\t// ID content ID\n\tID string\n\t// Type content type, example: \"answer\", \"question\"\n\tType string\n}\n```\n\n```go\ntype SearchSyncer interface {\n\tGetAnswersPage(ctx context.Context, page, pageSize int) (answerList []*SearchContent, err error)\n\tGetQuestionsPage(ctx context.Context, page, pageSize int) (questionList []*SearchContent, err error)\n}\n```\n\n```go\ntype SettingInfo struct {\n\tProfileSettingRedirectURL string `json:\"profile_setting_redirect_url\"`\n\tAccountSettingRedirectURL string `json:\"account_setting_redirect_url\"`\n}\n```\n\n```go\ntype Stack[T Base] struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\ntype Storage interface {\n\tBase\n\n\t// UploadFile uploads a file to storage.\n\t// The file is in the Form of the ctx and the key is \"file\"\n\tUploadFile(ctx *GinContext, source UploadSource) UploadFileResponse\n}\n```\n\n```go\ntype TranslateFn func(ctx *GinContext) string\n```\nTranslateFn presents a generator of translated string. We use it to delegate the translation work outside the plugin.\n\n```go\ntype Translator struct {\n\tFn TranslateFn\n}\n```\nTranslator contains a function that translates the key to the current language of the context\n\n```go\nfunc MakeTranslator(key string) Translator\n```\nMakeTranslator generates a translator from the key\n\n```go\nfunc (t Translator) Translate(ctx *GinContext) string\n```\nTranslate translates the key to the current language of the context\n\n```go\ntype UIOptionAction struct {\n\tUrl        string            `json:\"url\"`\n\tMethod     string            `json:\"method,omitempty\"`\n\tLoading    *LoadingAction    `json:\"loading,omitempty\"`\n\tOnComplete *OnCompleteAction `json:\"on_complete,omitempty\"`\n}\n```\n\n```go\ntype UploadFileResponse struct {\n\t// FullURL is the URL that can be used to access the file\n\tFullURL string\n\t// OriginalError is the error returned by the storage plugin. It is used for debugging.\n\tOriginalError error\n\t// DisplayErrorMsg is the error message that will be displayed to the user.\n\tDisplayErrorMsg Translator\n}\n```\n\n```go\ntype UploadSource string\n```\n\n```go\nconst (\n\tUserAvatar    UploadSource = \"user_avatar\"\n\tUserPost      UploadSource = \"user_post\"\n\tAdminBranding UploadSource = \"admin_branding\"\n)\n```\n\n```go\ntype UserCenter interface {\n\tBase\n\t// Description returns the description of the user center, including the name, icon, url, etc.\n\tDescription() UserCenterDesc\n\t// ControlCenterItems returns the items that will be displayed in the control center\n\tControlCenterItems() []ControlCenter\n\t// LoginCallback is called when the user center login callback is called\n\tLoginCallback(ctx *GinContext) (userInfo *UserCenterBasicUserInfo, err error)\n\t// SignUpCallback is called when the user center sign up callback is called\n\tSignUpCallback(ctx *GinContext) (userInfo *UserCenterBasicUserInfo, err error)\n\t// UserInfo returns the user information\n\tUserInfo(externalID string) (userInfo *UserCenterBasicUserInfo, err error)\n\t// UserStatus returns the latest user status\n\tUserStatus(externalID string) (userStatus UserStatus)\n\t// UserList returns the user list information\n\tUserList(externalIDs []string) (userInfo []*UserCenterBasicUserInfo, err error)\n\t// UserSettings returns the user settings\n\tUserSettings(externalID string) (userSettings *SettingInfo, err error)\n\t// PersonalBranding returns the personal branding information\n\tPersonalBranding(externalID string) (branding []*PersonalBranding)\n\t// AfterLogin is called after the user logs in\n\tAfterLogin(externalID, accessToken string)\n}\n```\n\n```go\nfunc GetUserCenter() (uc UserCenter, ok bool)\n```\n\n```go\ntype UserCenterBasicUserInfo struct {\n\tExternalID  string     `json:\"external_id\"`\n\tUsername    string     `json:\"username\"`\n\tDisplayName string     `json:\"display_name\"`\n\tEmail       string     `json:\"email\"`\n\tRank        int        `json:\"rank\"`\n\tAvatar      string     `json:\"avatar\"`\n\tMobile      string     `json:\"mobile\"`\n\tBio         string     `json:\"bio\"`\n\tStatus      UserStatus `json:\"status\"`\n}\n```\n\n```go\ntype UserCenterDesc struct {\n\tName                      string     `json:\"name\"`\n\tDisplayName               Translator `json:\"display_name\"`\n\tIcon                      string     `json:\"icon\"`\n\tUrl                       string     `json:\"url\"`\n\tLoginRedirectURL          string     `json:\"login_redirect_url\"`\n\tSignUpRedirectURL         string     `json:\"sign_up_redirect_url\"`\n\tRankAgentEnabled          bool       `json:\"rank_agent_enabled\"`\n\tUserStatusAgentEnabled    bool       `json:\"user_status_agent_enabled\"`\n\tUserRoleAgentEnabled      bool       `json:\"user_role_agent_enabled\"`\n\tMustAuthEmailEnabled      bool       `json:\"must_auth_email_enabled\"`\n\tEnabledOriginalUserSystem bool       `json:\"enabled_original_user_system\"`\n}\n```\n\n```go\ntype UserStatus int\n```\n\n```go\nconst (\n\tUserStatusAvailable UserStatus = 1\n\tUserStatusSuspended UserStatus = 9\n\tUserStatusDeleted   UserStatus = 10\n)\n```\n\n","path":"github.com/answerdev/answer/plugin","name":"plugin","synopsis":"","isRedistributable":true}
