func init() { chat.Init() peony.OnServerInit(func(s *peony.Server) { SetOfflineRedisPool(chat.GetOfflineRedisPool()) }) }
func init() { gob.Register((*peony.Session)(nil)) peony.OnServerInit(func(s *peony.Server) { sec := s.App.Security encoding = base64.NewEncoding(sec) s.RegisterSessionManager(&SimpleSessionManager{}) CookieHttpOnly = s.App.GetBoolConfig("CookieHttpOnly", false) CookieSecure = s.App.GetBoolConfig("CookieSecure", false) SessionTimeout = s.App.GetIntConfig("SessionTimeout", 30) }) }
func init() { peony.OnServerInit(func(s *peony.Server) { sm := &MemSessionManager{} sm.list = list.New() sm.sessions = make(map[string]*item) go func(sm *MemSessionManager) { sm.clearTask() }(sm) s.RegisterSessionManager(sm) CookieHttpOnly = s.App.GetBoolConfig("CookieHttpOnly", false) CookieSecure = s.App.GetBoolConfig("CookieSecure", false) SessionTimeout = s.App.GetIntConfig("SessionTimeout", 30) }) }
func init() { go func() { for { var memstats runtime.MemStats runtime.ReadMemStats(&memstats) fmt.Printf(statusFmt, runtime.NumGoroutine(), memstats.Alloc, memstats.Sys, memstats.TotalAlloc, memstats.HeapAlloc, memstats.HeapSys, memstats.HeapInuse) time.Sleep(60 * time.Second) } }() peony.OnServerInit(func(s *peony.Server) { pushsvr := s.App.GetStringConfig("push.url", "") pushnum := s.App.GetStringConfig("push.num", "") groupServer := s.App.GetStringConfig("group.server", "") groupPasswd := s.App.GetStringConfig("group.passwd", "") rangeVal := s.App.GetIntConfig("range", 1024*1024) tokenServer := s.App.GetStringConfig("token.server", "") tokenPasswd := s.App.GetStringConfig("token.passwd", "") whoami := s.App.GetStringConfig("whoami", "") offlineRange := s.App.GetStringConfig("offlineRange", "") offlineStorePath := s.App.GetStringConfig("offlineStorePath", "") clusterCfg := s.App.GetStringConfig("cluster", "") clusterMap := map[string]string{} clusters := strings.Split(clusterCfg, ",") //hook log hookLog() if groupServer != "" { groupRedisPool = newPool(groupServer, groupPasswd) rconn := groupRedisPool.Get() if _, err := rconn.Do("ping"); err != nil { panic(err) } rconn.Close() } if tokenServer != "" { tokenRedisPool = newPool(tokenServer, tokenPasswd) rconn := tokenRedisPool.Get() if _, err := rconn.Do("ping"); err != nil { panic(err) } rconn.Close() } cfg := &pmsg.MsgHubFileStoreOfflineCenterConfig{} cfg.MaxRange = uint32(rangeVal) for _, v := range clusters { kv := strings.Split(v, "->") if len(kv) != 2 { continue } if kv[0] == whoami { if i, err := strconv.Atoi(whoami); err != nil { panic(err) } else { cfg.Id = i cfg.ServAddr = kv[1] } } else { clusterMap[kv[0]] = kv[1] } } rangeStr := strings.Split(offlineRange, "-") if i, err := strconv.Atoi(rangeStr[0]); err != nil { panic(err) } else { cfg.OfflineRangeStart = uint64(i) } if pushsvr != "" && pushnum != "" { var num int if i, err := strconv.Atoi(pushnum); err != nil { panic(err) } else { num = i } pusher = NewPusher(num, pushsvr) } if i, err := strconv.Atoi(rangeStr[1]); err != nil { panic(err) } else { cfg.OfflineRangeEnd = uint64(i) } cfg.OfflinePath = offlineStorePath hub = pmsg.NewMsgHubWithFileStoreOfflineCenter(cfg) for k, v := range clusterMap { var i int var err error if i, err = strconv.Atoi(k); err != nil { panic(err) } hub.AddOtherHub(i, v) hubAddrs[i] = v } hub.AddOfflineMsgFilter(sendNotify) go hub.ListenAndServe() }) }
func Init() { go func() { for { var memstats runtime.MemStats runtime.ReadMemStats(&memstats) fmt.Printf(statusFmt, runtime.NumGoroutine(), memstats.Alloc, memstats.Sys, memstats.TotalAlloc, memstats.HeapAlloc, memstats.HeapSys, memstats.HeapInuse) time.Sleep(60 * time.Second) } }() peony.OnServerInit(func(s *peony.Server) { pushsvr := s.App.GetStringConfig("push.url", "") pushnum := s.App.GetStringConfig("push.num", "") userServer := s.App.GetStringConfig("user.server", "") userPasswd := s.App.GetStringConfig("user.passwd", "") rangeVal := s.App.GetIntConfig("range", 1024*1024) tokenServer := s.App.GetStringConfig("token.server", "") tokenPasswd := s.App.GetStringConfig("token.passwd", "") whoamiRaw := s.App.GetStringConfig("whoami", "") offlineServer := s.App.GetStringConfig("offline.server", "") offlinePasswd := s.App.GetStringConfig("offline.passwd", "") clusterCfg := s.App.GetStringConfig("cluster", "") clusterMap := map[string]string{} clusters := strings.Split(clusterCfg, ",") //hook log hookLog() if offlineServer != "" { offlineRedisPool = newPool(offlineServer, offlinePasswd) rconn := offlineRedisPool.Get() if _, err := rconn.Do("ping"); err != nil { panic(err) } rconn.Close() } if userServer != "" { userRedisPool = newPool(userServer, userPasswd) rconn := userRedisPool.Get() if _, err := rconn.Do("ping"); err != nil { panic(err) } rconn.Close() } if tokenServer != "" { tokenRedisPool = newPool(tokenServer, tokenPasswd) rconn := tokenRedisPool.Get() if _, err := rconn.Do("ping"); err != nil { panic(err) } rconn.Close() } offlineCenter := pmsg.NewRedisClientOfflineCenter(offlineRedisPool) var serverAddr string var whoami int for _, v := range clusters { kv := strings.Split(v, "->") if len(kv) != 2 { continue } if kv[0] == whoamiRaw { if i, err := strconv.Atoi(whoamiRaw); err != nil { panic(err) } else { serverAddr = kv[1] whoami = i } } else { clusterMap[kv[0]] = kv[1] } } hub = pmsg.NewMsgHubWithOfflineCenter(whoami, uint32(rangeVal), serverAddr, offlineCenter) if pushsvr != "" && pushnum != "" { var num int if i, err := strconv.Atoi(pushnum); err != nil { panic(err) } else { num = i } pusher = NewPusher(num, pushsvr) } for k, v := range clusterMap { var i int var err error if i, err = strconv.Atoi(k); err != nil { panic(err) } hub.AddOtherHub(i, v) hubAddrs[i] = v } //hub.AddOfflineMsgFilter(sendNotify) go hub.ListenAndServe() }) }