-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·72 lines (61 loc) · 1.84 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
package main
import (
"os"
"strings"
"github.com/thedevsir/frame-backend/config"
"github.com/thedevsir/frame-backend/config/database"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/thedevsir/frame-backend/config/mail"
_ "github.com/thedevsir/frame-backend/docs"
"github.com/thedevsir/frame-backend/routes"
"github.com/thedevsir/frame-backend/services/storage"
"github.com/thedevsir/frame-backend/services/validation"
validator "gopkg.in/go-playground/validator.v9"
)
func init() {
config.Composer(".env")
db := &database.Composer{
Locals: "resource/locals/locals.json",
Addrs: strings.Split(config.DBAddress, ","),
Database: config.DBName,
Username: config.DBUsername,
Password: config.DBPassword,
Source: config.DBSource,
}
db.Shoot()
storage.Composer()
mail.Composer()
}
// @title Frame
// @version 1.0.0
// @description A user system API starter.
// @contact.name Amir Irani
// @contact.email [email protected]
// @license.name MIT
// @license.url https://opensource.org/licenses/MIT
// @host localhost:3500
// @BasePath /endpoint
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
// @securityDefinitions.apikey AdminApiKeyAuth
// @in header
// @name AdminAuthorization
func main() {
Run := routes.Composer()
Run.Use(middleware.Logger())
Run.Use(middleware.Recover())
Run.Use(middleware.BodyLimit(config.RoutesBodyLimit))
Run.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: strings.Split(config.CorsAllowOrigins, ","),
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
if os.Getenv("MODE") != "DEV" {
Run.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 5,
}))
}
Run.Validator = &validation.DataValidator{ValidatorData: validator.New()}
Run.Logger.Fatal(Run.Start(config.Port))
}