-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (35 loc) · 984 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"kvrest/api"
"kvrest/telegram_bot"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
func main() {
// Ensure the /data/ directory exists
dataDir := "./data/"
if _, err := os.Stat(dataDir); os.IsNotExist(err) {
log.Println("Creating /data/ directory...")
err := os.MkdirAll(dataDir, 0755)
if err != nil {
log.Fatalf("Failed to create /data/ directory: %s", err)
}
}
// Start the Telegram bot in a separate goroutine
if os.Getenv("BOT_TOKEN") != "" {
go telegram_bot.StartBot()
}
// Define the main router
router := mux.NewRouter()
// Define the subrouter for API with both middlewares
apiRouter := router.PathPrefix("/api").Subrouter()
api.RegisterRoutes(apiRouter)
apiRouter.Use(api.ApiKeyMiddleware)
apiRouter.Use(api.DisableSystemBucketMiddleware)
// Apply Logging Middleware to all routes
router.Use(api.LoggingMiddleware)
log.Println("Server running on port 8080")
log.Fatal(http.ListenAndServe(":8080", router))
}