-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
42 lines (33 loc) · 1.06 KB
/
factory.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
package factory
import (
gosql "database/sql"
http_post "github.com/mcustiel/go-blog/pkg/interface/http/post"
"github.com/mcustiel/go-blog/pkg/logic/facade"
"github.com/mcustiel/go-blog/pkg/persistence"
"github.com/mcustiel/go-blog/pkg/persistence/sql"
repository_post "github.com/mcustiel/go-blog/pkg/repository/post"
"github.com/mcustiel/gorro"
_ "github.com/mattn/go-sqlite3"
)
var connCache persistence.ConnectionManager[gosql.Result] = nil
func CreateDbConnectionManager() persistence.ConnectionManager[gosql.Result] {
if connCache == nil {
connCache = sql.NewDefaultConnectionManager()
}
return connCache
}
func CreatePostDao() repository_post.PostDao {
conn := CreateDbConnectionManager().GetConnection()
return repository_post.NewSqlPostDao(conn.(*sql.SqlConnection))
}
func CreatePostFacade() facade.PostFacade {
dao := CreatePostDao()
return facade.CreatePostFacade(dao)
}
func CreatePostHandler() *http_post.PostHandler {
f := CreatePostFacade()
return http_post.NewPostHandler(f)
}
func CreateRouter() gorro.Router {
return gorro.NewRouter()
}