Refactor: Implement uber-go/fx dependency injection
- Replace global variable pattern with proper dependency injection - Add uber-go/fx for automatic dependency resolution - Refactor all services and handlers to use constructor injection - Eliminate fragile initialization order dependencies - Improve testability and modularity - Add structured logging with zap Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
+12
-20
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
type Config struct {
|
||||
AdminPassword string
|
||||
Instance string
|
||||
Tag string
|
||||
@@ -26,15 +26,13 @@ type config struct {
|
||||
|
||||
ImageKitId string
|
||||
|
||||
GiteaOauthInstance string
|
||||
GiteaOauthClientID string
|
||||
GiteaOauthClientSecret string
|
||||
GiteaOauthAllowedEmails []string
|
||||
GiteaOauthInstance string
|
||||
GiteaOauthClientID string
|
||||
GiteaOauthClientSecret string
|
||||
GiteaOauthAllowedEmails []string
|
||||
}
|
||||
|
||||
var Config *config
|
||||
|
||||
func Load() *config {
|
||||
func Load() *Config {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
slog.Warn("Error loading .env file - Using environment variables instead")
|
||||
@@ -104,8 +102,8 @@ func Load() *config {
|
||||
if imageKitId == "" {
|
||||
slog.Info("No imagekit id provided, not using imagekit.io")
|
||||
}
|
||||
// Inititlize AppContext
|
||||
var appContext = &config{
|
||||
// Initialize AppContext
|
||||
return &Config{
|
||||
AdminPassword: adminPassword,
|
||||
Instance: instance,
|
||||
Tag: tag,
|
||||
@@ -123,15 +121,9 @@ func Load() *config {
|
||||
|
||||
ImageKitId: imageKitId,
|
||||
|
||||
GiteaOauthInstance: giteaOauthInstance,
|
||||
GiteaOauthClientID: giteaOauthClientID,
|
||||
GiteaOauthClientSecret: giteaOauthClientSecret,
|
||||
GiteaOauthInstance: giteaOauthInstance,
|
||||
GiteaOauthClientID: giteaOauthClientID,
|
||||
GiteaOauthClientSecret: giteaOauthClientSecret,
|
||||
GiteaOauthAllowedEmails: giteaOauthAllowedEmailsParsed,
|
||||
}
|
||||
return appContext
|
||||
|
||||
}
|
||||
|
||||
func Init() {
|
||||
Config = Load()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user