Files
go-123pan-pic/cmd/main.go
RainySY 7229dfa1b7 refactor: decouple services from global config and clean up structure
- Remove duplicate UploadBaseURL constant (identical to APIBaseURL)
- Pass parentFileID and customDomain into service constructors instead of
  reading from config.GlobalConfig at call time, eliminating hidden global
  state dependencies in the service layer
- Replace []interface{} response building in HandleList with a typed
  imageResponse struct for compile-time safety
- Extract inline CORS closure from main.go into handler.CORSMiddleware(),
  consistent with how AuthMiddleware is organized
- Remove narrating comments throughout; keep only the non-obvious one
  explaining why DoRawPUT omits auth headers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 14:48:11 +08:00

45 lines
1.1 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"github.com/gin-gonic/gin"
"imagehost/internal/config"
"imagehost/internal/handler"
"imagehost/internal/pan123"
"imagehost/internal/service"
)
func main() {
var cfgFlag string
flag.StringVar(&cfgFlag, "c", "conf/config.yaml", "指定配置文件路径")
flag.Parse()
config.InitConfig(cfgFlag)
cfg := config.GlobalConfig
client := pan123.NewClient(cfg.ClientID, cfg.ClientSecret)
uploadSvc := service.NewUploadService(client, cfg.ParentFileID, cfg.CustomDomain)
imageSvc := service.NewImageService(client, cfg.ParentFileID, cfg.CustomDomain)
uploadHandler := handler.NewUploadHandler(uploadSvc)
imageHandler := handler.NewImageHandler(imageSvc)
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
r.MaxMultipartMemory = 10 << 20
r.Use(handler.CORSMiddleware())
handler.ConfigureRoutes(r, imageHandler, uploadHandler)
addr := fmt.Sprintf(":%d", cfg.Port)
log.Printf("服务已启动,访问 http://localhost%s", addr)
if err := r.Run(addr); err != nil {
log.Fatalf("服务启动失败: %v", err)
}
}