-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (45 loc) · 1.47 KB
/
main.go
File metadata and controls
58 lines (45 loc) · 1.47 KB
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 (
"os"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-playground/validator/v10"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/arayofcode/tokeniser/src/cipher"
"github.com/arayofcode/tokeniser/src/common"
"github.com/arayofcode/tokeniser/src/database"
"github.com/arayofcode/tokeniser/src/handler"
"github.com/arayofcode/tokeniser/src/router"
)
func init() {
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger()
if validate, ok := binding.Validator.Engine().(*validator.Validate); ok {
err := validate.RegisterValidation("expirydate", common.ExpiryDateMMYY)
if err != nil {
log.Fatal().Err(err).Msg("Failed to register 'expirydate' validation")
}
err = validate.RegisterValidation("notallzero", common.NotAllZero)
if err != nil {
log.Fatal().Err(err).Msg("Failed to register 'notallzero' validation")
}
}
}
func main() {
gin.SetMode(gin.ReleaseMode)
dbURL := common.GetDbURL()
if dbURL == "" {
log.Fatal().Msg("Database URL is not configured")
}
db := database.DatabaseInit(dbURL)
log.Info().Msg("Database connection successful")
passphrase := common.GetPassphrase()
if passphrase == "" {
log.Fatal().Msg("Encryption passphrase is not configured")
}
cipherModule := cipher.Init(passphrase)
dbHandler := handler.NewHandler(db)
apiRouter := router.NewRouter(dbHandler, cipherModule)
log.Info().Msg("Starting the API")
apiRouter.StartAPI()
}