-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
86 lines (72 loc) · 2.19 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"log"
"os"
"time"
"github.com/gin-gonic/gin"
"github.com/AlperRehaYAZGAN/temp-file-transfer-app/config"
docs "github.com/AlperRehaYAZGAN/temp-file-transfer-app/docs"
"github.com/AlperRehaYAZGAN/temp-file-transfer-app/handlers"
plugins "github.com/AlperRehaYAZGAN/temp-file-transfer-app/plugins"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// Path: temp-upload-service
// @Title Temp File Upload Service API
// @Description alya.temp-file.upload-service : microservice for temporary upload and retrieve file operations.
// @Version 1.0.0
// @Schemes http https
// @BasePath /api/v1
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
const (
// server name
APP_NAME = "alya.temp-file.upload-service"
// server description
APP_DESCRIPTION = "alya.temp-file.upload-service : microservice for temporary upload and retrieve file operations."
)
func main() {
// parse application envs
dir, err := os.Getwd()
if err != nil {
log.Fatal("INIT: Cannot get current working directory os.Getwd()")
}
config.ReadConfig(dir)
config.Pwd = dir
// init env
env := config.C.App.Env
port := config.C.App.Port
// log env and port like "alya.temp-file.upload-service env: dev, port: 9097"
log.Printf("INIT: %s env: %s, port: %s", APP_NAME, env, port)
// create 3th party connections
inAppCache := plugins.NewInAppCacheStore(time.Minute)
// create application service
uploadsvc := handlers.NewUploadService(
inAppCache,
)
// check env and set gin mode
gin.SetMode(gin.ReleaseMode)
if env == "prod" || env == "production" {
gin.SetMode(gin.ReleaseMode)
} else {
gin.SetMode(gin.DebugMode)
}
router := gin.New()
router.Use(gin.Recovery())
uploadsvc.InitRouter(router)
uploadsvc.InitUploadsOldFileCleaner()
// check env and set swagger
// if !(env == "prod" || env == "production") {
docs.SwaggerInfo.BasePath = "/api/v1/"
router.GET("/docs/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
// }
// start server
port = os.Getenv("PORT")
if port == "" {
port = "9090"
}
log.Println("INIT: Application " + APP_NAME + " started on port " + port)
// fatal if error
log.Fatal(router.Run(":" + port))
}