()
| 44 | ) |
| 45 | |
| 46 | func main() { |
| 47 | app := fiber.New(fiber.Config{ |
| 48 | BodyLimit: 10 * 1024 * 1024, // 10 MB |
| 49 | AppName: "FolderHost", |
| 50 | DisableStartupMessage: true, |
| 51 | }) |
| 52 | |
| 53 | app.Use(compress.New(compress.Config{ |
| 54 | Level: compress.LevelBestSpeed, |
| 55 | Next: func(c *fiber.Ctx) bool { |
| 56 | skipRoutes := []string{ |
| 57 | "/api/explorer/download", |
| 58 | "/api/upload", |
| 59 | "/api/raw", |
| 60 | } |
| 61 | for _, route := range skipRoutes { |
| 62 | if strings.HasPrefix(c.Path(), route) { |
| 63 | return true |
| 64 | } |
| 65 | } |
| 66 | return false |
| 67 | }, |
| 68 | })) |
| 69 | |
| 70 | app.Use(cors.New()) |
| 71 | |
| 72 | utils.Setup() |
| 73 | utils.GetConfig() |
| 74 | initialize.InitializeDatabase() |
| 75 | |
| 76 | go cache.ListenDirectorySetCacheEvents() |
| 77 | go tasks.AutoClearOldLogs() |
| 78 | |
| 79 | config := &config.Config |
| 80 | var portInt int = config.Port |
| 81 | if portInt == 0 || !utils.IsPortAvailable(portInt) { |
| 82 | log.Printf("Your port %d is busy! Searching for another port...", portInt) |
| 83 | var err error |
| 84 | portInt, err = utils.FindAvailablePort(5000, 6000) |
| 85 | if err != nil { |
| 86 | log.Printf("%v", err) |
| 87 | } |
| 88 | } |
| 89 | var PORT string = fmt.Sprintf(":%d", portInt) |
| 90 | var skipServices bool = false |
| 91 | |
| 92 | serviceutils.GlobalServiceManager = serviceutils.NewServiceManager() |
| 93 | |
| 94 | err := serviceutils.GlobalServiceManager.LoadConfig("services.yml") |
| 95 | if err != nil { |
| 96 | log.Printf("Warning: Can't load services.yml: %v", err) |
| 97 | skipServices = true // Services are optional |
| 98 | } |
| 99 | |
| 100 | c := make(chan os.Signal, 1) |
| 101 | signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) |
| 102 | |
| 103 | go func() { |
nothing calls this directly
no test coverage detected