-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathboostrap.go
More file actions
50 lines (39 loc) · 1.49 KB
/
boostrap.go
File metadata and controls
50 lines (39 loc) · 1.49 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
package bootstrap
import (
"database/sql"
"fmt"
"github.com/CodelyTV/go-hexagonal_http_api-course/04-03-command-bus/internal/fetching"
"github.com/CodelyTV/go-hexagonal_http_api-course/04-03-command-bus/internal/creating"
"github.com/CodelyTV/go-hexagonal_http_api-course/04-03-command-bus/internal/platform/bus/inmemory"
"github.com/CodelyTV/go-hexagonal_http_api-course/04-03-command-bus/internal/platform/server"
"github.com/CodelyTV/go-hexagonal_http_api-course/04-03-command-bus/internal/platform/storage/mysql"
_ "github.com/go-sql-driver/mysql"
)
const (
host = "localhost"
port = 8080
dbUser = "codely"
dbPass = "codely"
dbHost = "localhost"
dbPort = "3306"
dbName = "codely"
)
func Run() error {
mysqlURI := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", dbUser, dbPass, dbHost, dbPort, dbName)
db, err := sql.Open("mysql", mysqlURI)
if err != nil {
return err
}
var (
bus = inmemory.NewCommandBus()
)
courseRepository := mysql.NewCourseRepository(db)
creatingCourseService := creating.NewCourseService(courseRepository)
fetchingCourseService := fetching.NewCourseFetchingService(courseRepository)
createCourseCommandHandler := creating.NewCourseCommandHandler(creatingCourseService)
fetchingCourseQueryHandler := fetching.NewCourseQueryHandler(fetchingCourseService)
bus.RegisterCommandHandler(creating.CourseCommandType, createCourseCommandHandler)
bus.RegisterQueryHandler(fetching.CourseQueryType, fetchingCourseQueryHandler)
srv := server.New(host, port, bus)
return srv.Run()
}