mirror of https://gitee.com/answerdev/answer.git
refactor(agent): make a register for site URL
This commit is contained in:
parent
fb412cb417
commit
209dc4f623
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
||||
"github.com/answerdev/answer/pkg/uid"
|
||||
"github.com/answerdev/answer/plugin"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
"github.com/segmentfault/pacman/log"
|
||||
|
@ -36,15 +37,14 @@ func NewSiteInfoService(
|
|||
tagCommonService *tagcommon.TagCommonService,
|
||||
configService *config.ConfigService,
|
||||
) *SiteInfoService {
|
||||
//usersSiteInfo, _ := siteInfoCommonService.GetSiteUsers(context.Background())
|
||||
//if usersSiteInfo != nil {
|
||||
// constant.DefaultAvatar = usersSiteInfo.DefaultAvatar
|
||||
// constant.DefaultGravatarBaseURL = usersSiteInfo.GravatarBaseURL
|
||||
//}
|
||||
generalSiteInfo, _ := siteInfoCommonService.GetSiteGeneral(context.Background())
|
||||
if generalSiteInfo != nil {
|
||||
constant.DefaultSiteURL = generalSiteInfo.SiteUrl
|
||||
}
|
||||
plugin.RegisterGetSiteURLFunc(func() string {
|
||||
generalSiteInfo, err := siteInfoCommonService.GetSiteGeneral(context.Background())
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return ""
|
||||
}
|
||||
return generalSiteInfo.SiteUrl
|
||||
})
|
||||
|
||||
return &SiteInfoService{
|
||||
siteInfoRepo: siteInfoRepo,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@ -15,10 +14,19 @@ type Agent interface {
|
|||
var (
|
||||
CallAgent,
|
||||
registerAgent = MakePlugin[Agent](true)
|
||||
siteURLFn func() string
|
||||
)
|
||||
|
||||
// SiteURL The site url is the domain address of the current site. e.g. http://localhost:8080
|
||||
// When some Agent plugins want to redirect to the origin site, it can use this function to get the site url.
|
||||
func SiteURL() string {
|
||||
return constant.DefaultSiteURL
|
||||
if siteURLFn != nil {
|
||||
return siteURLFn()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// RegisterGetSiteURLFunc Register a function to get the site url.
|
||||
func RegisterGetSiteURLFunc(fn func() string) {
|
||||
siteURLFn = fn
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue