-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.go
63 lines (50 loc) · 1.46 KB
/
application.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
58
59
60
61
62
63
package sand
import (
"fmt"
"io/ioutil"
json "github.com/json-iterator/go"
"github.com/silverswords/sand/core"
"github.com/silverswords/sand/services"
)
var application *core.Application
type Config struct {
Host string
Port string
Database string
UserName string
Password string
Charset string
}
func init() {
c := &Config{}
data, err := ioutil.ReadFile("../config/sql.json")
if err != nil {
panic(err)
}
if err = json.Unmarshal(data, c); err != nil {
panic(err)
}
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=%s&parseTime=%t&loc=%s",
c.UserName, c.Password, c.Host, c.Port, c.Database, c.Charset, true, "Local")
config := &core.Config{
Dsn: dsn,
}
application = core.CreateApplication(config)
usersService := services.CreateUsersService(application)
productsService := services.CreateProductsService(application)
categoryService := services.CreateCategoryService(application)
ordersService := services.CreateOrdersService(application)
shoppingCartsService := services.CreateCartsService(application)
virtualStore := services.CreateVirtualStoreService(application)
weChat := services.CreateWeChatService()
sign := services.CreateSignService()
if err != nil {
panic(err)
}
service := services.CreateService(usersService, productsService, categoryService,
ordersService, shoppingCartsService, virtualStore, weChat, sign)
application.SetServices(&service)
}
func GetApplication() *core.Application {
return application
}