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:
@@ -3,24 +3,23 @@ package services
|
||||
import "CatsOfMastodonBotGo/internal/config"
|
||||
|
||||
type ImgKitHelper struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
var ImgKitHelperInstance *ImgKitHelper
|
||||
|
||||
func InitImgKitHelper() {
|
||||
ImgKitHelperInstance = &ImgKitHelper{}
|
||||
func NewImgKitHelper(cfg *config.Config) *ImgKitHelper {
|
||||
return &ImgKitHelper{cfg: cfg}
|
||||
}
|
||||
|
||||
func GetPreviewUrl(url string) string {
|
||||
if config.Config.ImageKitId == "" {
|
||||
func (ikh *ImgKitHelper) GetPreviewUrl(url string) string {
|
||||
if ikh.cfg.ImageKitId == "" {
|
||||
return url
|
||||
}
|
||||
return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:w-500,h-500,c-at_max,f-webp,q-50/" + url
|
||||
return "https://ik.imagekit.io/" + ikh.cfg.ImageKitId + "/tr:w-500,h-500,c-at_max,f-webp,q-50/" + url
|
||||
}
|
||||
|
||||
func GetRemoteUrl(url string) string {
|
||||
if config.Config.ImageKitId == "" {
|
||||
func (ikh *ImgKitHelper) GetRemoteUrl(url string) string {
|
||||
if ikh.cfg.ImageKitId == "" {
|
||||
return url
|
||||
}
|
||||
return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:q-70,dpr-auto,f-webp/" + url
|
||||
}
|
||||
return "https://ik.imagekit.io/" + ikh.cfg.ImageKitId + "/tr:q-70,dpr-auto,f-webp/" + url
|
||||
}
|
||||
Reference in New Issue
Block a user