-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (67 loc) · 1.76 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
package main
import (
"app/config"
"app/database"
"app/modules"
"app/routes"
"fmt"
"log"
"os"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"flag"
)
// @title Demo CSV API
// @version 1.0
// @description Language: Golang. Core: Fiber
// @contact.name CubeSystem Viet Nam
// @contact.url https://vn-cubesystem.com/
// @contact.email info@vn-cubesystem.com
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name x-csv-key
// @securityDefinitions.apikey ApiTokenAuth
// @in header
// @name x-csv-token
func main() {
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowMethods: "GET,POST,PATCH,PUT,DELETE",
}))
// Static folder
app.Static("/assets", "./assets")
// Connect Database
if !database.Connect() || !modules.MigrateModule() {
return
}
// Init router
routes.InitRoutes(app)
modules.InitRoutes(app)
// Handle Error
dirPath := "./assets/log/system"
fileName := fmt.Sprintf("%s/%s.txt", dirPath, time.Now().Format("2006-01-02"))
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
// dir_path does not exist
os.MkdirAll(dirPath, os.ModePerm)
}
file, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
panic(err)
}
defer file.Close()
app.Use(logger.New(logger.Config{
Format: "${time} | ${ip} | ${method} | ${status} - ${error} | ${path} \n",
TimeFormat: "2006-01-02 15:04:05",
TimeZone: config.Config("APP_TIME_ZONE"),
Output: file,
}))
// Run app
// port := config.Config("ENV_PORT")
// addr := flag.String("addr", ":"+port, "http service address")
addr := flag.String("addr", "192.168.11.162:8080", "http service address")
flag.Parse()
log.Fatal(app.Listen(*addr))
}