-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (46 loc) · 1.66 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
package main
import (
"log"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
"github.com/vano2903/service-template/config"
"github.com/vano2903/service-template/controller"
"github.com/vano2903/service-template/handlers/httpserver"
"github.com/vano2903/service-template/model"
"github.com/vano2903/service-template/pkg/logger"
"github.com/vano2903/service-template/providers/logo"
"github.com/vano2903/service-template/repo/mock"
)
func main() {
conf, err := config.NewConfig()
if err != nil {
panic(err)
}
l := logger.NewLogger(conf.Log.Level, conf.Log.Type)
l.Debug("initizalized logger")
if conf.Database.Driver != "mock" {
log.Fatal("only mock database is supported in this example")
}
//creating the instances for the application
repo := mock.NewRepo()
logoService := logo.NewServiceLogo(conf.Services.Logo.ApiKey, conf.Services.Logo.BaseUrl)
//creating the controller
c := controller.NewUserController(repo, logoService, l)
GenerateExampleEntries(l, c)
//creating the http server
e := echo.New()
httpserver.InitRouter(e, l, c, conf)
//starting the server
e.Logger.Fatal(e.Start(":" + conf.HTTP.Port))
}
func GenerateExampleEntries(l *logrus.Logger, c *controller.User) {
if _, err := c.CreateUser("Davide", "Vanoncini", "[email protected]", "password", model.RoleAdmin); err != nil {
l.Fatal("unable to create test user")
}
if _, err := c.CreateUser("John", "Doe", "[email protected]", "123secure", model.RoleUser); err != nil {
l.Fatal("unable to create test user")
}
if _, err := c.CreateUser("Foo", "Bar", "[email protected]", "psw1", model.RoleUnupdatable); err != nil {
l.Fatal("unable to create test user")
}
}