move the variables set during the building process into the core package
This commit is contained in:
+4
-4
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/urfave/cli/v3"
|
"github.com/urfave/cli/v3"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/cmd"
|
"github.com/mayswind/ezbookkeeping/cmd"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/settings"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,9 +26,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
settings.Version = Version
|
core.Version = Version
|
||||||
settings.CommitHash = CommitHash
|
core.CommitHash = CommitHash
|
||||||
settings.BuildTime = BuildUnixTime
|
core.BuildTime = BuildUnixTime
|
||||||
|
|
||||||
cmd := &cli.Command{
|
cmd := &cli.Command{
|
||||||
Name: "ezBookkeeping",
|
Name: "ezBookkeeping",
|
||||||
|
|||||||
+2
-3
@@ -3,7 +3,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/settings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HealthsApi represents health api
|
// HealthsApi represents health api
|
||||||
@@ -18,8 +17,8 @@ var (
|
|||||||
func (a *HealthsApi) HealthStatusHandler(c *core.WebContext) (any, *errs.Error) {
|
func (a *HealthsApi) HealthStatusHandler(c *core.WebContext) (any, *errs.Error) {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
|
|
||||||
result["version"] = settings.Version
|
result["version"] = core.Version
|
||||||
result["commit"] = settings.CommitHash
|
result["commit"] = core.CommitHash
|
||||||
result["status"] = "ok"
|
result["status"] = "ok"
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func (a *ModelContextProtocolAPI) InitializeHandler(c *core.WebContext, jsonRPCR
|
|||||||
ServerInfo: &mcp.MCPImplementation{
|
ServerInfo: &mcp.MCPImplementation{
|
||||||
Name: mcpServerName,
|
Name: mcpServerName,
|
||||||
Title: core.ApplicationName,
|
Title: core.ApplicationName,
|
||||||
Version: settings.Version,
|
Version: core.Version,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-5
@@ -3,7 +3,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/settings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SystemsApi represents system api
|
// SystemsApi represents system api
|
||||||
@@ -18,11 +17,11 @@ var (
|
|||||||
func (a *SystemsApi) VersionHandler(c *core.WebContext) (any, *errs.Error) {
|
func (a *SystemsApi) VersionHandler(c *core.WebContext) (any, *errs.Error) {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
|
|
||||||
result["version"] = settings.Version
|
result["version"] = core.Version
|
||||||
result["commitHash"] = settings.CommitHash
|
result["commitHash"] = core.CommitHash
|
||||||
|
|
||||||
if settings.BuildTime != "" {
|
if core.BuildTime != "" {
|
||||||
result["buildTime"] = settings.BuildTime
|
result["buildTime"] = core.BuildTime
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func InitializeOAuth2Provider(config *settings.Config) error {
|
|||||||
|
|
||||||
Container.current = oauth2Provider
|
Container.current = oauth2Provider
|
||||||
Container.usePKCE = config.OAuth2UsePKCE
|
Container.usePKCE = config.OAuth2UsePKCE
|
||||||
Container.oauth2HttpClient = httpclient.NewHttpClient(config.OAuth2RequestTimeout, config.OAuth2Proxy, config.OAuth2SkipTLSVerify, settings.GetUserAgent(), config.EnableDebugLog)
|
Container.oauth2HttpClient = httpclient.NewHttpClient(config.OAuth2RequestTimeout, config.OAuth2Proxy, config.OAuth2SkipTLSVerify, core.GetOutgoingUserAgent(), config.EnableDebugLog)
|
||||||
Container.externalUserAuthType = externalUserAuthType
|
Container.externalUserAuthType = externalUserAuthType
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,4 +1,21 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// ApplicationName represents the application name
|
// ApplicationName represents the application name
|
||||||
const ApplicationName = "ezBookkeeping"
|
const ApplicationName = "ezBookkeeping"
|
||||||
|
|
||||||
|
// Version, CommitHash and BuildTime are set at build
|
||||||
|
var (
|
||||||
|
Version string
|
||||||
|
CommitHash string
|
||||||
|
BuildTime string
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetOutgoingUserAgent() string {
|
||||||
|
if Version == "" {
|
||||||
|
return ApplicationName
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s/%s", ApplicationName, Version)
|
||||||
|
}
|
||||||
|
|||||||
@@ -108,6 +108,6 @@ func (e *CommonHttpExchangeRatesDataProvider) GetLatestExchangeRates(c core.Cont
|
|||||||
func newCommonHttpExchangeRatesDataProvider(config *settings.Config, dataSource HttpExchangeRatesDataSource) *CommonHttpExchangeRatesDataProvider {
|
func newCommonHttpExchangeRatesDataProvider(config *settings.Config, dataSource HttpExchangeRatesDataSource) *CommonHttpExchangeRatesDataProvider {
|
||||||
return &CommonHttpExchangeRatesDataProvider{
|
return &CommonHttpExchangeRatesDataProvider{
|
||||||
dataSource: dataSource,
|
dataSource: dataSource,
|
||||||
httpClient: httpclient.NewHttpClient(config.ExchangeRatesRequestTimeout, config.ExchangeRatesProxy, config.ExchangeRatesSkipTLSVerify, settings.GetUserAgent(), config.EnableDebugLog),
|
httpClient: httpclient.NewHttpClient(config.ExchangeRatesRequestTimeout, config.ExchangeRatesProxy, config.ExchangeRatesSkipTLSVerify, core.GetOutgoingUserAgent(), config.EnableDebugLog),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,6 @@ func (p *CommonHttpLargeLanguageModelProvider) getTextualResponse(c core.Context
|
|||||||
func NewCommonHttpLargeLanguageModelProvider(llmConfig *settings.LLMConfig, enableResponseLog bool, adapter HttpLargeLanguageModelAdapter) *CommonHttpLargeLanguageModelProvider {
|
func NewCommonHttpLargeLanguageModelProvider(llmConfig *settings.LLMConfig, enableResponseLog bool, adapter HttpLargeLanguageModelAdapter) *CommonHttpLargeLanguageModelProvider {
|
||||||
return &CommonHttpLargeLanguageModelProvider{
|
return &CommonHttpLargeLanguageModelProvider{
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
httpClient: httpclient.NewHttpClient(llmConfig.LargeLanguageModelAPIRequestTimeout, llmConfig.LargeLanguageModelAPIProxy, llmConfig.LargeLanguageModelAPISkipTLSVerify, settings.GetUserAgent(), enableResponseLog),
|
httpClient: httpclient.NewHttpClient(llmConfig.LargeLanguageModelAPIRequestTimeout, llmConfig.LargeLanguageModelAPIProxy, llmConfig.LargeLanguageModelAPISkipTLSVerify, core.GetOutgoingUserAgent(), enableResponseLog),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
package settings
|
package settings
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ConfigContainer contains the current setting config
|
// ConfigContainer contains the current setting config
|
||||||
type ConfigContainer struct {
|
type ConfigContainer struct {
|
||||||
current *Config
|
current *Config
|
||||||
@@ -13,9 +7,6 @@ type ConfigContainer struct {
|
|||||||
|
|
||||||
// Initialize a config container singleton instance
|
// Initialize a config container singleton instance
|
||||||
var (
|
var (
|
||||||
Version string
|
|
||||||
CommitHash string
|
|
||||||
BuildTime string
|
|
||||||
Container = &ConfigContainer{}
|
Container = &ConfigContainer{}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,11 +19,3 @@ func SetCurrentConfig(config *Config) {
|
|||||||
func (c *ConfigContainer) GetCurrentConfig() *Config {
|
func (c *ConfigContainer) GetCurrentConfig() *Config {
|
||||||
return c.current
|
return c.current
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserAgent() string {
|
|
||||||
if Version == "" {
|
|
||||||
return core.ApplicationName
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("%s/%s", core.ApplicationName, Version)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func NewWebDAVObjectStorage(config *settings.Config, pathPrefix string) (*WebDAV
|
|||||||
webDavConfig := config.WebDAVConfig
|
webDavConfig := config.WebDAVConfig
|
||||||
|
|
||||||
storage := &WebDAVObjectStorage{
|
storage := &WebDAVObjectStorage{
|
||||||
httpClient: httpclient.NewHttpClient(webDavConfig.RequestTimeout, webDavConfig.Proxy, webDavConfig.SkipTLSVerify, settings.GetUserAgent(), false),
|
httpClient: httpclient.NewHttpClient(webDavConfig.RequestTimeout, webDavConfig.Proxy, webDavConfig.SkipTLSVerify, core.GetOutgoingUserAgent(), false),
|
||||||
webDavConfig: webDavConfig,
|
webDavConfig: webDavConfig,
|
||||||
rootPath: webDavConfig.RootPath,
|
rootPath: webDavConfig.RootPath,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user