This repository has been archived by the owner on Nov 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·89 lines (70 loc) · 2.38 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
87
88
89
package main
import (
"os"
mAdmin "github.com/Gommunity/GoWithWith/app/model/admin"
mAuthAttempt "github.com/Gommunity/GoWithWith/app/model/authAttempt"
mSession "github.com/Gommunity/GoWithWith/app/model/session"
mUser "github.com/Gommunity/GoWithWith/app/model/user"
"github.com/Gommunity/GoWithWith/config/database"
"github.com/Gommunity/GoWithWith/config/mail"
_ "github.com/Gommunity/GoWithWith/docs"
"github.com/Gommunity/GoWithWith/routes"
"github.com/Gommunity/GoWithWith/services/utility"
"github.com/Gommunity/GoWithWith/services/validation"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/zebresel-com/mongodm"
validator "gopkg.in/go-playground/validator.v9"
)
func init() {
utility.LoadEnvironmentVariables(".env")
db := &database.Composer{
Locals: "resource/locals/locals.json",
Addrs: []string{os.Getenv("DBAddrs")},
Database: os.Getenv("DBName"),
Username: os.Getenv("DBUsername"),
Password: os.Getenv("DBPassword"),
Source: os.Getenv("DBSource"),
}
db.Shoot(map[string]mongodm.IDocumentBase{
"authAttempts": &mAuthAttempt.AuthAttempt{},
"sessions": &mSession.Session{},
"users": &mUser.User{},
"admin": &mAdmin.Admin{},
})
mail.Composer()
}
// @title GoWithWith
// @version 1.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
func main() {
Run := routes.Composer()
Run.Use(middleware.Logger())
Run.Use(middleware.Recover())
Run.Use(middleware.BodyDump(func(c echo.Context, reqBody, resBody []byte) {}))
Run.Use(middleware.BodyLimit("10K"))
Run.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
Run.Validator = &validation.DataValidator{ValidatorData: validator.New()}
// Gzip Middleware
// has conflict with swagger
// Run.Use(middleware.GzipWithConfig(middleware.GzipConfig{
// Level: 5,
// }))
// Run.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
// StackSize: 1 << 10, // 1 KB
// }))
// Run.Pre(middleware.HTTPSNonWWWRedirect())
Run.Logger.Fatal(Run.Start(os.Getenv("PORT")))
}