liuyuqi-cnb 2 months ago
parent
commit
8e8375466f
4 changed files with 35 additions and 33 deletions
  1. 2 30
      back-go/cmd/filecloud.go
  2. 2 2
      back-go/config.toml
  3. 28 1
      back-go/service/config.go
  4. 3 0
      back-go/service/service.go

+ 2 - 30
back-go/cmd/filecloud.go

@@ -3,25 +3,14 @@ package main
 import (
 	"flag"
 	"log"
-
-	"github.com/gin-gonic/gin"
-	swaggerFiles "github.com/swaggo/files"
-	ginSwagger "github.com/swaggo/gin-swagger"
 	"filecloud/internal/database"
-	"filecloud/internal/handler"
 	"filecloud/service"
-	_ "filecloud/docs"  // 取消注释,启用 Swagger 文档
 )
 
 var (
 	configPath = flag.String("file", "./config.toml", "config file")
 )
 
-// @title FileCloud API
-// @version 1.0
-// @description FileCloud API documentation
-// @host localhost:8080
-// @BasePath /api
 func main() {
 	flag.Parse()
 
@@ -33,25 +22,8 @@ func main() {
 		log.Fatal(err)
 	}
 
-	r := gin.Default()
-
-	// 静态文件服务用 /static 前缀
-	r.Static("/static", "./public")
-
-	// API routes
-	api := r.Group("/api")
-	{
-		api.POST("/files", handler.UploadFile)
-		api.GET("/files", handler.ListFiles)
-	}
-
-	// Swagger documentation
-	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
-
+	// 启动 Web 服务(所有路由、静态、API、Swagger 都在 service.Launch 里)
 	service.Launch()
 
-	logger.Info("stop")
-	service.Stop()
-
-	log.Fatal(r.Run(":8080"))
+	logger.Info("Server started")
 }

+ 2 - 2
back-go/config.toml

@@ -1,5 +1,5 @@
-WebAddr   = "127.0.0.1:8080"            # web 地址
-WebIndex  = "./dist"      # web html目录
+WebAddr   = "127.0.0.1:8081"            # web 地址
+WebIndex  = "./public"      # web html目录
 
 # 阿里云盘token
 REFRESH_TOKENS = ""

+ 28 - 1
back-go/service/config.go

@@ -1,6 +1,7 @@
 package service
 
 import (
+	"os"
 	"github.com/BurntSushi/toml"
 )
 
@@ -32,5 +33,31 @@ func LoadConfig(path string) *Config {
 
 // todo
 func saveConfig()  {
-	
+	// sava config to file
+	conf := &Config{}
+	conf.WebAddr = config.WebAddr
+	conf.WebIndex = config.WebIndex
+	conf.REFRESH_TOKENS = config.REFRESH_TOKENS
+	conf.PUSHPLUS_TOKEN = config.PUSHPLUS_TOKEN
+	conf.EmailUser = config.EmailUser
+	conf.EmailPwd = config.EmailPwd
+	conf.EmailSmtp = config.EmailSmtp
+	conf.EmailTls = config.EmailTls
+	conf.Username = config.Username
+	conf.Password = config.Password
+
+	// save to file config.toml
+	file, err := os.Create("config.toml")
+	if err != nil {
+		panic(err)
+	}
+	defer file.Close()
+		
+	encoder := toml.NewEncoder(file)
+	err = encoder.Encode(conf)
+	if err != nil {
+		panic(err)
+	}
+
+	logger.Info("config saved to file config.toml")
 }

+ 3 - 0
back-go/service/service.go

@@ -20,6 +20,9 @@ var (
 func Launch() {
 	taskQueue = task.NewTaskPool(1, 1024)
 
+	// 初始化任务队列
+	logger.Info("Task queue initialized")
+
 	app = gin.New()
 	app.Use(gin.Logger(), gin.Recovery())