feat(login): 重构 login 服务启动方式
- 修改 login 服务端口配置,支持动态分配 - 优化 login 服务启动流程,增加信号处理 - 调整 ServerOption 类型,支持 int 类型端口 - 移除 CommendSvrInfo 相关代码,简化结构 - 更新 main 函数,采用新的服务启动方式
This commit is contained in:
@@ -28,6 +28,7 @@ func init() {
|
||||
cool.FillInitData(ctx, "base", &model.BaseSysDepartment{})
|
||||
cool.FillInitData(ctx, "base", &model.BaseSysRoleDepartment{})
|
||||
cool.FillInitData(ctx, "base", &model.BaseSysParam{})
|
||||
cool.FillInitData(ctx, "base", &model.BaseSysConf{})
|
||||
|
||||
g.Log().Debug(ctx, "module base init finished ...")
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
10
modules/base/resource/initjson/base_sys_conf.json
Normal file
10
modules/base/resource/initjson/base_sys_conf.json
Normal file
@@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"createTime": "2021-02-26 13:53:05.000000",
|
||||
"updateTime": "2021-03-03 17:50:04.000000",
|
||||
|
||||
"cKey": "server_ip",
|
||||
"cValue": "127.0.0.1"
|
||||
}
|
||||
]
|
||||
@@ -43,7 +43,10 @@ func (s *BaseSysConfService) UpdateValue(cKey, cValue string) error {
|
||||
|
||||
// GetValue 获取配置值
|
||||
func (s *BaseSysConfService) GetValue(cKey string) string {
|
||||
m := cool.DBM(s.Model).Where("cKey = ?", cKey)
|
||||
|
||||
// t1, _ := cool.DBM(s.Model).All()
|
||||
// fmt.Println(t1)
|
||||
m := cool.DBM(s.Model).Where("cKey", cKey)
|
||||
record, err := m.One()
|
||||
if err != nil {
|
||||
return ""
|
||||
|
||||
@@ -2,7 +2,6 @@ package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const TableNamePet = "pet"
|
||||
@@ -57,6 +56,11 @@ type PetInfo struct {
|
||||
FreedTime string `gorm:"comment:'放生时间'" json:"freed_time"`
|
||||
}
|
||||
|
||||
type PetSkillInfo struct {
|
||||
skill int32 `gorm:"not null;default:0;comment:'技能1'" json:"skill_1_id"`
|
||||
pp int16 `gorm:"not null;default:0;comment:'技能1PP'" json:"skill_1_pp"`
|
||||
}
|
||||
|
||||
// TableName Pet's table name
|
||||
func (*Pet) TableName() string {
|
||||
return TableNamePet
|
||||
@@ -76,6 +80,6 @@ func NewPet() *Pet {
|
||||
|
||||
// init 创建表
|
||||
func init() {
|
||||
err := cool.CreateTable(&Pet{})
|
||||
fmt.Println(err)
|
||||
_ = cool.CreateTable(&Pet{})
|
||||
// fmt.Println(err)
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@ const TableNameServerList = "server_list"
|
||||
// ServerList mapped from table <server_list>
|
||||
type ServerList struct {
|
||||
*cool.Model
|
||||
IP string `gorm:"type:varchar(16);comment:'服务器IP'" json:"ip"`
|
||||
Port uint16 `gorm:"comment:'端口号,通常是小整数'" json:"port"`
|
||||
IsOpen bool `gorm:"default:true;not null;comment:'服务器是否开启,默认为开启状态'" json:"is_open"`
|
||||
OnlineID uint32 `gorm:"column:online_id;comment:'在线ID';uniqueIndex" json:"online_id"`
|
||||
//IP string `gorm:"type:varchar(16);comment:'服务器IP'" json:"ip"`
|
||||
Port uint16 `gorm:"comment:'端口号,通常是小整数'" json:"port"`
|
||||
//IsOpen bool `gorm:"default:true;not null;comment:'服务器是否开启,默认为开启状态'" json:"is_open"`
|
||||
}
|
||||
|
||||
// TableName ServerList's table name
|
||||
|
||||
@@ -50,3 +50,24 @@ func (s *LoginService) GetSessionId(accountID uint) (string, string, error) {
|
||||
// /t1.
|
||||
// 以上过程只需全局一次,且应在生成ID之前完成。
|
||||
}
|
||||
func (s *LoginService) SetServerID(OnlineID uint32, Port uint16) error {
|
||||
|
||||
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
||||
|
||||
record, err := m.One()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if record == nil {
|
||||
//说明是新的服务器
|
||||
|
||||
_, err := m.InsertAndGetId(&model.ServerList{OnlineID: OnlineID, Port: Port})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = m.Data(&model.ServerList{OnlineID: OnlineID, Port: Port}).Where("online_id", OnlineID).Update()
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user