-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
35 lines (27 loc) · 877 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
package main
import (
"github.com/gin-gonic/gin"
"github.com/prajnapras19/otpgeneratorwithrecoveryserver/client/mysql"
"github.com/prajnapras19/otpgeneratorwithrecoveryserver/config"
"github.com/prajnapras19/otpgeneratorwithrecoveryserver/sharedsecret"
"net/http"
)
func main() {
// config
cfg := config.Get()
// database
mySQLService := mysql.NewService(cfg.MySQLConfig)
// auto migrate
mySQLService.GetDB().AutoMigrate(&sharedsecret.SharedSecret{})
// repository
sharedSecretRepository := sharedsecret.NewRepository(mySQLService.GetDB())
// handler
sharedSecretHandler := sharedsecret.NewHandler(sharedSecretRepository)
r := gin.Default()
r.POST("/insert", sharedSecretHandler.Insert)
r.GET("/get/:client_id", sharedSecretHandler.Get)
r.GET("/_healthcheck", func(gc *gin.Context) {
gc.String(http.StatusOK, "OK")
})
r.Run(":" + cfg.RESTPort)
}