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"
|
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||||
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
||||||
"github.com/answerdev/answer/pkg/uid"
|
"github.com/answerdev/answer/pkg/uid"
|
||||||
|
"github.com/answerdev/answer/plugin"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/segmentfault/pacman/errors"
|
"github.com/segmentfault/pacman/errors"
|
||||||
"github.com/segmentfault/pacman/log"
|
"github.com/segmentfault/pacman/log"
|
||||||
|
@ -36,15 +37,14 @@ func NewSiteInfoService(
|
||||||
tagCommonService *tagcommon.TagCommonService,
|
tagCommonService *tagcommon.TagCommonService,
|
||||||
configService *config.ConfigService,
|
configService *config.ConfigService,
|
||||||
) *SiteInfoService {
|
) *SiteInfoService {
|
||||||
//usersSiteInfo, _ := siteInfoCommonService.GetSiteUsers(context.Background())
|
plugin.RegisterGetSiteURLFunc(func() string {
|
||||||
//if usersSiteInfo != nil {
|
generalSiteInfo, err := siteInfoCommonService.GetSiteGeneral(context.Background())
|
||||||
// constant.DefaultAvatar = usersSiteInfo.DefaultAvatar
|
if err != nil {
|
||||||
// constant.DefaultGravatarBaseURL = usersSiteInfo.GravatarBaseURL
|
log.Error(err)
|
||||||
//}
|
return ""
|
||||||
generalSiteInfo, _ := siteInfoCommonService.GetSiteGeneral(context.Background())
|
}
|
||||||
if generalSiteInfo != nil {
|
return generalSiteInfo.SiteUrl
|
||||||
constant.DefaultSiteURL = generalSiteInfo.SiteUrl
|
})
|
||||||
}
|
|
||||||
|
|
||||||
return &SiteInfoService{
|
return &SiteInfoService{
|
||||||
siteInfoRepo: siteInfoRepo,
|
siteInfoRepo: siteInfoRepo,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/answerdev/answer/internal/base/constant"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,10 +14,19 @@ type Agent interface {
|
||||||
var (
|
var (
|
||||||
CallAgent,
|
CallAgent,
|
||||||
registerAgent = MakePlugin[Agent](true)
|
registerAgent = MakePlugin[Agent](true)
|
||||||
|
siteURLFn func() string
|
||||||
)
|
)
|
||||||
|
|
||||||
// SiteURL The site url is the domain address of the current site. e.g. http://localhost:8080
|
// 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.
|
// When some Agent plugins want to redirect to the origin site, it can use this function to get the site url.
|
||||||
func SiteURL() string {
|
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