-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (49 loc) · 1.26 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
package main
import (
"fmt"
"os"
uuid "github.com/twinj/uuid"
"github.com/varunbhayana/gin-ratelimiter/route"
"github.com/gin-gonic/gin"
)
//RequestIDMiddleware ...
//Generate a unique ID and attach it to each request for future reference or use
func RequestIDMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
uuid := uuid.NewV4()
c.Writer.Header().Set("X-Request-Id", uuid.String())
c.Next()
}
}
// var auth = new(controllers.AuthController)
//TokenAuthMiddleware ...
//JWT Authentication middleware attached to each request that needs to be authenitcated to validate the access_token in the header
func TokenAuthMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
// auth.TokenValid(c)
c.Next()
}
}
func main() {
//Start the default gin server
r := gin.Default()
//Load the .env file
route.Settle(r)
fmt.Println("SSL", os.Getenv("SSL"))
port := os.Getenv("PORT")
if os.Getenv("ENV") == "PRODUCTION" {
gin.SetMode(gin.ReleaseMode)
}
if os.Getenv("SSL") == "TRUE" {
SSLKeys := &struct {
CERT string
KEY string
}{}
//Generated using sh generate-certificate.sh
SSLKeys.CERT = "./cert/myCA.cer"
SSLKeys.KEY = "./cert/myCA.key"
r.RunTLS(":"+port, SSLKeys.CERT, SSLKeys.KEY)
} else {
r.Run(":" + port)
}
}