diff --git a/ezbookkeeping.go b/ezbookkeeping.go index f1276cd7..4d5515a5 100644 --- a/ezbookkeeping.go +++ b/ezbookkeeping.go @@ -10,7 +10,7 @@ import ( "github.com/urfave/cli/v3" "github.com/mayswind/ezbookkeeping/cmd" - "github.com/mayswind/ezbookkeeping/pkg/settings" + "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/utils" ) @@ -26,9 +26,9 @@ var ( ) func main() { - settings.Version = Version - settings.CommitHash = CommitHash - settings.BuildTime = BuildUnixTime + core.Version = Version + core.CommitHash = CommitHash + core.BuildTime = BuildUnixTime cmd := &cli.Command{ Name: "ezBookkeeping", diff --git a/pkg/api/healths.go b/pkg/api/healths.go index f4ff50bd..ec761d29 100644 --- a/pkg/api/healths.go +++ b/pkg/api/healths.go @@ -3,7 +3,6 @@ package api import ( "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" - "github.com/mayswind/ezbookkeeping/pkg/settings" ) // HealthsApi represents health api @@ -18,8 +17,8 @@ var ( func (a *HealthsApi) HealthStatusHandler(c *core.WebContext) (any, *errs.Error) { result := make(map[string]string) - result["version"] = settings.Version - result["commit"] = settings.CommitHash + result["version"] = core.Version + result["commit"] = core.CommitHash result["status"] = "ok" return result, nil diff --git a/pkg/api/model_context_protocols.go b/pkg/api/model_context_protocols.go index 1cfc82ac..531ecd59 100644 --- a/pkg/api/model_context_protocols.go +++ b/pkg/api/model_context_protocols.go @@ -103,7 +103,7 @@ func (a *ModelContextProtocolAPI) InitializeHandler(c *core.WebContext, jsonRPCR ServerInfo: &mcp.MCPImplementation{ Name: mcpServerName, Title: core.ApplicationName, - Version: settings.Version, + Version: core.Version, }, } diff --git a/pkg/api/systems.go b/pkg/api/systems.go index 7b926867..3b50e991 100644 --- a/pkg/api/systems.go +++ b/pkg/api/systems.go @@ -3,7 +3,6 @@ package api import ( "github.com/mayswind/ezbookkeeping/pkg/core" "github.com/mayswind/ezbookkeeping/pkg/errs" - "github.com/mayswind/ezbookkeeping/pkg/settings" ) // SystemsApi represents system api @@ -18,11 +17,11 @@ var ( func (a *SystemsApi) VersionHandler(c *core.WebContext) (any, *errs.Error) { result := make(map[string]string) - result["version"] = settings.Version - result["commitHash"] = settings.CommitHash + result["version"] = core.Version + result["commitHash"] = core.CommitHash - if settings.BuildTime != "" { - result["buildTime"] = settings.BuildTime + if core.BuildTime != "" { + result["buildTime"] = core.BuildTime } return result, nil diff --git a/pkg/auth/oauth2/oauth2_authentication.go b/pkg/auth/oauth2/oauth2_authentication.go index d18c45e7..701e86d4 100644 --- a/pkg/auth/oauth2/oauth2_authentication.go +++ b/pkg/auth/oauth2/oauth2_authentication.go @@ -67,7 +67,7 @@ func InitializeOAuth2Provider(config *settings.Config) error { Container.current = oauth2Provider 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 return nil diff --git a/pkg/core/application.go b/pkg/core/application.go index 0e89ac96..24efbcc0 100644 --- a/pkg/core/application.go +++ b/pkg/core/application.go @@ -1,4 +1,21 @@ package core +import "fmt" + // ApplicationName represents the application name 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) +} diff --git a/pkg/exchangerates/common_http_exchange_rates_data_provider.go b/pkg/exchangerates/common_http_exchange_rates_data_provider.go index 846db5bf..1dddfb7b 100644 --- a/pkg/exchangerates/common_http_exchange_rates_data_provider.go +++ b/pkg/exchangerates/common_http_exchange_rates_data_provider.go @@ -108,6 +108,6 @@ func (e *CommonHttpExchangeRatesDataProvider) GetLatestExchangeRates(c core.Cont func newCommonHttpExchangeRatesDataProvider(config *settings.Config, dataSource HttpExchangeRatesDataSource) *CommonHttpExchangeRatesDataProvider { return &CommonHttpExchangeRatesDataProvider{ 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), } } diff --git a/pkg/llm/provider/common/common_http_large_language_model_provider.go b/pkg/llm/provider/common/common_http_large_language_model_provider.go index a791f957..1852bc92 100644 --- a/pkg/llm/provider/common/common_http_large_language_model_provider.go +++ b/pkg/llm/provider/common/common_http_large_language_model_provider.go @@ -83,6 +83,6 @@ func (p *CommonHttpLargeLanguageModelProvider) getTextualResponse(c core.Context func NewCommonHttpLargeLanguageModelProvider(llmConfig *settings.LLMConfig, enableResponseLog bool, adapter HttpLargeLanguageModelAdapter) *CommonHttpLargeLanguageModelProvider { return &CommonHttpLargeLanguageModelProvider{ 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), } } diff --git a/pkg/settings/setting_container.go b/pkg/settings/setting_container.go index f9ad1c6f..996c37e5 100644 --- a/pkg/settings/setting_container.go +++ b/pkg/settings/setting_container.go @@ -1,11 +1,5 @@ package settings -import ( - "fmt" - - "github.com/mayswind/ezbookkeeping/pkg/core" -) - // ConfigContainer contains the current setting config type ConfigContainer struct { current *Config @@ -13,10 +7,7 @@ type ConfigContainer struct { // Initialize a config container singleton instance var ( - Version string - CommitHash string - BuildTime string - Container = &ConfigContainer{} + Container = &ConfigContainer{} ) // SetCurrentConfig sets the current config by a given config @@ -28,11 +19,3 @@ func SetCurrentConfig(config *Config) { func (c *ConfigContainer) GetCurrentConfig() *Config { return c.current } - -func GetUserAgent() string { - if Version == "" { - return core.ApplicationName - } - - return fmt.Sprintf("%s/%s", core.ApplicationName, Version) -} diff --git a/pkg/storage/webdav_storage.go b/pkg/storage/webdav_storage.go index f4144124..24d5e216 100644 --- a/pkg/storage/webdav_storage.go +++ b/pkg/storage/webdav_storage.go @@ -26,7 +26,7 @@ func NewWebDAVObjectStorage(config *settings.Config, pathPrefix string) (*WebDAV webDavConfig := config.WebDAVConfig 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, rootPath: webDavConfig.RootPath, }