-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
33 lines (25 loc) · 692 Bytes
/
main.go
File metadata and controls
33 lines (25 loc) · 692 Bytes
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
package main
import (
"log"
"github.com/gin-gonic/gin"
"github.com/yusianglin11010/url-shortner/config"
"github.com/yusianglin11010/url-shortner/handler"
"github.com/yusianglin11010/url-shortner/store"
)
func main() {
r := gin.Default()
config := config.NewConfig()
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "Hello URL Shortner"})
})
r.POST("/url", func(c *gin.Context) {
handler.CreateShortUrl(c, config.Rest.Host, config.Rest.Port)
})
r.GET("/:url", func(c *gin.Context) {
handler.HandleShortUrlRedirect(c)
})
store.InitializeStore(config.Redis.Host, config.Redis.Port)
if err := r.Run(config.Rest.Port); err != nil {
log.Print(err)
}
}