-
Notifications
You must be signed in to change notification settings - Fork 0
/
minitwit.go
78 lines (61 loc) · 2.16 KB
/
minitwit.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
package main
import (
"flag"
"github.com/ContainerMaintainers/MiniTwit-Golang/controllers"
"github.com/ContainerMaintainers/MiniTwit-Golang/database"
"github.com/ContainerMaintainers/MiniTwit-Golang/monitoring"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
latest = -1
testFlag = flag.Bool("t", false, "Whether or not to use test database")
user = -1
)
func metricsHandler() gin.HandlerFunc {
reg := prometheus.NewRegistry()
monitoring.NewMetrics(reg)
h := promhttp.HandlerFor(reg, promhttp.HandlerOpts{})
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}
func SetupRouter() *gin.Engine {
router := gin.Default()
router.LoadHTMLGlob("templates/*")
router.Static("/static", "./static/")
router.GET("/metrics", metricsHandler())
router.GET("/ping", controllers.Ping)
router.GET("/", controllers.IndexTimeline)
router.GET("/public", controllers.Timeline)
router.GET("/:username", controllers.UserTimeline)
router.GET("/:username/follow", controllers.UsernameFollow)
router.GET("/:username/unfollow", controllers.UsernameUnfollow)
router.POST("/register", controllers.Register_user)
router.GET("/register", controllers.Register)
router.POST("/add_message", controllers.AddMessage)
router.POST("/login", controllers.Login_user)
router.GET("/login", controllers.Loginf)
router.GET("/logout", controllers.Logout_user)
router.GET("/sim/latest", controllers.SimLatest)
router.POST("/sim/register", controllers.SimRegister)
router.GET("/sim/msgs", controllers.SimMsgs)
router.POST("/sim/msgs/:username", controllers.SimPostUserMsg)
router.GET("/sim/msgs/:username", controllers.SimGetUserMsg)
router.POST("/sim/fllws/:username", controllers.SimPostUserFllws)
router.GET("/sim/fllws/:username", controllers.SimGetUserFllws)
return router
}
func main() {
flag.Parse()
if *testFlag {
database.ConnectToTestDatabase()
} else {
database.ConnectToDatabase()
}
database.MigrateEntities()
database.SeedDatabase()
router := SetupRouter()
router.Run() // port 8080
}