12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package main
- import (
- "embed"
- "flag"
- "log"
- "net/http"
- "github.com/gin-gonic/gin"
- swaggerFiles "github.com/swaggo/files"
- ginSwagger "github.com/swaggo/gin-swagger"
- "github.com/jianboy/filecloud/internal/database"
- "github.com/jianboy/filecloud/internal/handler"
- _ "github.com/jianboy/filecloud/docs"
- )
- var (
- configPath = flag.String("file", "./config.toml", "config file")
- )
- //go:embed public/*
- var publicFS embed.FS
- // @title FileCloud API
- // @version 1.0
- // @description FileCloud API documentation
- // @host localhost:8080
- // @BasePath /api
- func main() {
- flag.Parse()
- logger := service.InitLogger("log", "filecloud")
- service.LoadConfig(*configPath)
- // Initialize database
- if err := database.InitDB(); err != nil {
- log.Fatal(err)
- }
- r := gin.Default()
- // Serve static files from embedded frontend
- r.StaticFS("/", http.FS(publicFS))
- // 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))
- service.Launch()
- logger.Info("stop")
- service.Stop()
- log.Fatal(r.Run(":8080"))
- }
|