mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 11:27:17 +08:00
feat: api支持传递locale,close #155
This commit is contained in:
@@ -20,7 +20,7 @@ type cacheRepo struct {
|
||||
|
||||
func NewCacheRepo(db *gorm.DB) biz.CacheRepo {
|
||||
return &cacheRepo{
|
||||
api: api.NewAPI(app.Version),
|
||||
api: api.NewAPI(app.Version, app.Locale),
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ type PanelTask struct {
|
||||
|
||||
func NewPanelTask(db *gorm.DB, log *slog.Logger, backup biz.BackupRepo, cache biz.CacheRepo, task biz.TaskRepo, setting biz.SettingRepo) *PanelTask {
|
||||
return &PanelTask{
|
||||
api: api.NewAPI(app.Version),
|
||||
api: api.NewAPI(app.Version, app.Locale),
|
||||
db: db,
|
||||
log: log,
|
||||
backupRepo: backup,
|
||||
|
||||
@@ -50,7 +50,7 @@ type CliService struct {
|
||||
func NewCliService(t *gotext.Locale, conf *koanf.Koanf, db *gorm.DB, appRepo biz.AppRepo, cache biz.CacheRepo, user biz.UserRepo, setting biz.SettingRepo, backup biz.BackupRepo, website biz.WebsiteRepo, databaseServer biz.DatabaseServerRepo) *CliService {
|
||||
return &CliService{
|
||||
hr: `+----------------------------------------------------`,
|
||||
api: api.NewAPI(app.Version),
|
||||
api: api.NewAPI(app.Version, app.Locale),
|
||||
t: t,
|
||||
conf: conf,
|
||||
db: db,
|
||||
|
||||
@@ -41,7 +41,7 @@ type DashboardService struct {
|
||||
func NewDashboardService(t *gotext.Locale, conf *koanf.Koanf, task biz.TaskRepo, website biz.WebsiteRepo, appRepo biz.AppRepo, setting biz.SettingRepo, cron biz.CronRepo, backupRepo biz.BackupRepo) *DashboardService {
|
||||
return &DashboardService{
|
||||
t: t,
|
||||
api: api.NewAPI(app.Version),
|
||||
api: api.NewAPI(app.Version, app.Locale),
|
||||
conf: conf,
|
||||
taskRepo: task,
|
||||
websiteRepo: website,
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
type API struct {
|
||||
panelVersion string
|
||||
client *resty.Client
|
||||
panelVersion, locale string
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
@@ -20,7 +20,7 @@ type Response struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
func NewAPI(panelVersion string, url ...string) *API {
|
||||
func NewAPI(panelVersion, locale string, url ...string) *API {
|
||||
if len(panelVersion) == 0 {
|
||||
panic("panel version is required")
|
||||
}
|
||||
@@ -37,6 +37,7 @@ func NewAPI(panelVersion string, url ...string) *API {
|
||||
client.SetTimeout(10 * time.Second)
|
||||
client.SetBaseURL(url[0])
|
||||
client.SetHeader("User-Agent", fmt.Sprintf("rat-panel/%s %s/%s", panelVersion, hostInfo.Platform, hostInfo.PlatformVersion))
|
||||
client.SetQueryParam("locale", locale)
|
||||
|
||||
return &API{
|
||||
panelVersion: panelVersion,
|
||||
|
||||
@@ -13,7 +13,7 @@ type APITestSuite struct {
|
||||
|
||||
func TestAPITestSuite(t *testing.T) {
|
||||
suite.Run(t, &APITestSuite{
|
||||
api: NewAPI("2.3.0"),
|
||||
api: NewAPI("2.3.0", "en"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user