-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (53 loc) · 1.23 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
package main
import (
"log"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/iarsham/url-shortener/configs"
"github.com/iarsham/url-shortener/helpers"
"github.com/iarsham/url-shortener/routers"
)
func init() {
if gin.Mode() != gin.ReleaseMode {
err := godotenv.Load()
if err != nil {
log.Fatal("error in loading .env file")
}
}
lg := configs.NewLogger()
configs.GetDB(lg)
configs.GetRedis(lg)
}
// @title UrlShortener Swagger Document
// @version 1.0
// @termsOfService http://swagger.io/terms/
// @contact.email [email protected]
// @BasePath /api/
// @host localhost:8000
// @licence.Name MIT
// @licence.url https://www.mit.edu/~amini/LICENSE.md
// @schemes http https
// @securityDefinitions.apikey Authorization
// @in header
// @name Authorization
// @accept json
func main() {
server := gin.Default()
server.Use(cors.Default())
lg := configs.NewLogger()
routers.SetupRouters(configs.DB, configs.RDB, lg, server)
go func() {
ticker := time.NewTicker(time.Minute)
for {
select {
case <-ticker.C:
helpers.RemoveExpiredUrls(configs.DB)
}
}
}()
if err := server.Run(":8000"); err != nil {
lg.Logger.Fatal(err.Error())
}
}