-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (44 loc) · 971 Bytes
/
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
package main
import (
"fmt"
"io"
"os"
"time"
"github.com/gin-gonic/gin"
"github.com/nitishkumar71/gcp-cleaner/pkg/services"
)
func main() {
fmt.Println("This is GCP Cleaner!!")
r := setupRouter()
port := os.Getenv("PORT")
fmt.Println("Port: ", port)
if port == "" {
port = "8080"
}
port = ":" + port
r.Run(port)
}
func setupRouter() *gin.Engine {
r := gin.Default()
f, _ := os.Create("gin.log")
gin.DefaultWriter = io.MultiWriter(f, os.Stdout)
r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
param.ClientIP,
param.TimeStamp.Format(time.RFC1123),
param.Method,
param.Path,
param.Request.Proto,
param.StatusCode,
param.Latency,
param.Request.UserAgent(),
param.ErrorMessage,
)
}))
r.Use(gin.Recovery())
setRoutes(r)
return r
}
func setRoutes(r *gin.Engine) {
r.POST("/cloudrun", services.DeleteCloudRunRevisionsPost)
}