http.go
1.23 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 service
import (
"math/rand"
"pro2d/common"
"pro2d/common/components"
"pro2d/common/db/mongoproxy"
"pro2d/common/db/redisproxy"
"pro2d/models"
"time"
)
type AccountServer struct {
components.IHttp
Sconf *common.SConf
}
func NewAccountServer(version string, port ...string) *AccountServer {
return &AccountServer{IHttp: components.NewHttpServer(version, port...)}
}
func (s *AccountServer) Init(sconf *common.SConf) error {
s.Sconf = sconf
//mgo init
err := mongoproxy.ConnectMongo(sconf.MongoConf, sconf.ID)
//redis init
if err = redisproxy.ConnectRedis(sconf.RedisConf.DB, sconf.RedisConf.Auth, sconf.RedisConf.Address); err != nil {
return err
}
models.NewDBSeed(sconf.ID).InitServerDatabase(models.AccountModels())
models.DBSeedS().InitAutoIncreUidTable(models.AccountModels())
return nil
}
func (s *AccountServer) TimeOut() {
models.DBSeedS().SaveAutoincrementTimer(models.AccountModels())
components.TimeOut(1*time.Second, s.TimeOut)
}
func (s *AccountServer) Start() error {
if err := s.Init(common.GlobalConf.AccountConf); err != nil {
return err
}
//设置随机种子
rand.Seed(time.Now().Unix())
//开始定时器
s.TimeOut()
return s.IHttp.Start()
}
func (s *AccountServer) Stop() {
s.IHttp.Stop()
}