update
This commit is contained in:
parent
25fab39b1e
commit
3048233bf2
12
cmd/ptt/lib/common/constant.go
Normal file
12
cmd/ptt/lib/common/constant.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
type (
|
||||||
|
WindowAspect int64
|
||||||
|
WindowMode int64
|
||||||
|
WindowAction int64
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
WindowAspect_Normal WindowAspect = iota
|
||||||
|
WindowAspect_FullScreen
|
||||||
|
)
|
25
cmd/ptt/lib/common/lang_en.go
Normal file
25
cmd/ptt/lib/common/lang_en.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
const (
|
||||||
|
//button
|
||||||
|
BUTTON_LOGIN = "login"
|
||||||
|
BUTTON_REGISTE = "registe"
|
||||||
|
BUTTON_RANDOM = "random"
|
||||||
|
BUTTON_OK = "ok"
|
||||||
|
BUTTON_CANCEL = "cancel"
|
||||||
|
|
||||||
|
//label
|
||||||
|
LABEL_WELCOME = "welcom,The service you choose is "
|
||||||
|
LABEL_NICKNAME = "nickname"
|
||||||
|
LABEL_ACCOUNT = "account"
|
||||||
|
|
||||||
|
// form title
|
||||||
|
FORM_TITLE_CREATEROLE = "create role"
|
||||||
|
FORM_TITLE_LOGIN = "login"
|
||||||
|
|
||||||
|
// info
|
||||||
|
INFO_WAIT = "Please wait"
|
||||||
|
|
||||||
|
// menu
|
||||||
|
MENU_FILE = "file"
|
||||||
|
)
|
24
cmd/ptt/lib/common/sec.go
Normal file
24
cmd/ptt/lib/common/sec.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/cmd/ptt/model"
|
||||||
|
"go_dreamfactory/utils"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
"github.com/nacos-group/nacos-sdk-go/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BuildSecStr(sid int32, account string) string {
|
||||||
|
jsonByte, _ := jsoniter.Marshal(&model.LoginParam{
|
||||||
|
Account: account,
|
||||||
|
ServerId: sid,
|
||||||
|
TimeStamp: time.Now().Unix(),
|
||||||
|
})
|
||||||
|
jsonBase64 := utils.Base64Encode(jsonByte)
|
||||||
|
// log.Printf("client base64:%s", jsonBase64)
|
||||||
|
clientMd5key := util.Md5(jsonBase64)
|
||||||
|
// log.Printf("client md5:%s", clientMd5key)
|
||||||
|
return fmt.Sprintf("CE:%s%s", clientMd5key, jsonBase64)
|
||||||
|
}
|
72
cmd/ptt/main.go
Normal file
72
cmd/ptt/main.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/cmd/ptt/service"
|
||||||
|
"go_dreamfactory/cmd/ptt/ui"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2/app"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
connService service.ConnService
|
||||||
|
pttService service.PttService
|
||||||
|
logger *logrus.Logger
|
||||||
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
func init() {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// initialize logger
|
||||||
|
if err = setupLogger(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = setupWsConn(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = setupPtt(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
logrus.Info("Starting...")
|
||||||
|
|
||||||
|
// create a new ui
|
||||||
|
appUI := ui.NewUI(app.NewWithID("protocol-test-tool"), connService, pttService)
|
||||||
|
mainWindow := ui.NewMainWindow(appUI)
|
||||||
|
|
||||||
|
mainWindow.CreateWindow("协议测试工具", 1366, 768, true)
|
||||||
|
|
||||||
|
appUI.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupPtt() (err error) {
|
||||||
|
pttService = service.NewPttService(connService)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupWsConn() (err error) {
|
||||||
|
connService = service.NewConnService()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupLogger() (err error) {
|
||||||
|
logrus.SetFormatter(&logrus.TextFormatter{
|
||||||
|
DisableColors: true,
|
||||||
|
FullTimestamp: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
logrus.SetOutput(os.Stdout)
|
||||||
|
//TODO
|
||||||
|
return nil
|
||||||
|
}
|
7
cmd/ptt/model/login.go
Normal file
7
cmd/ptt/model/login.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type LoginParam struct {
|
||||||
|
Account string `json:"account"`
|
||||||
|
ServerId int32 `json:"serverId"`
|
||||||
|
TimeStamp int64 `json:"timestamp"`
|
||||||
|
}
|
83
cmd/ptt/service/connService.go
Normal file
83
cmd/ptt/service/connService.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConnService interface {
|
||||||
|
Connect(wsUrl string) error
|
||||||
|
SendMsg(msg *pb.UserMessage, rsp proto.Message) (err error)
|
||||||
|
ReceiveMsg() (code pb.ErrorCode, msg *pb.UserMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConnServiceImpl struct {
|
||||||
|
ws *websocket.Conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConnService() ConnService {
|
||||||
|
return &ConnServiceImpl{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// connect ...
|
||||||
|
func (c *ConnServiceImpl) Connect(wsUrl string) error {
|
||||||
|
ws, _, err := websocket.DefaultDialer.Dial(wsUrl, nil)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("websocket conn err:%v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.ws = ws
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendMsg ....
|
||||||
|
func (c *ConnServiceImpl) SendMsg(msg *pb.UserMessage, rsp proto.Message) (err error) {
|
||||||
|
// msg.Sec = r.BuildSecStr()
|
||||||
|
if comm.ProtoMarshal(rsp, msg) {
|
||||||
|
if data, err := proto.Marshal(msg); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
return c.ws.WriteMessage(websocket.BinaryMessage, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReceiveMsg ....
|
||||||
|
func (c *ConnServiceImpl) ReceiveMsg() (code pb.ErrorCode, msg *pb.UserMessage) {
|
||||||
|
msg = &pb.UserMessage{}
|
||||||
|
_, data, err := c.ws.ReadMessage()
|
||||||
|
if err != nil {
|
||||||
|
code = pb.ErrorCode_SystemError
|
||||||
|
logrus.Errorf("readMessage err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if code = c.handleNotify(msg); code != pb.ErrorCode_Success {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// err notify
|
||||||
|
func (c *ConnServiceImpl) handleNotify(msg *pb.UserMessage) (code pb.ErrorCode) {
|
||||||
|
if msg.MainType == "notify" && msg.SubType == "errornotify" {
|
||||||
|
rsp := &pb.NotifyErrorNotifyPush{}
|
||||||
|
if !comm.ProtoUnmarshal(msg, rsp) {
|
||||||
|
code = pb.ErrorCode_PbError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
code = rsp.Code
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
109
cmd/ptt/service/pttService.go
Normal file
109
cmd/ptt/service/pttService.go
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/cmd/ptt/lib/common"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/modules/user"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PttService interface {
|
||||||
|
Login(sid int32, account string) (code pb.ErrorCode, rsp *pb.UserLoginResp)
|
||||||
|
CreateRole(nickName string) (code pb.ErrorCode, rsp *pb.UserCreateResp)
|
||||||
|
GetUser() *UserInfo
|
||||||
|
SetUser(dbUser *pb.DBUser, dbUserExpand *pb.DBUserExpand)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PttServiceImpl struct {
|
||||||
|
connService ConnService
|
||||||
|
user *UserInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserInfo struct {
|
||||||
|
DbUser *pb.DBUser
|
||||||
|
DbUserExpand *pb.DBUserExpand
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPttService(connService ConnService) PttService {
|
||||||
|
return &PttServiceImpl{
|
||||||
|
connService: connService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PttServiceImpl) GetUser() *UserInfo {
|
||||||
|
return p.user
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PttServiceImpl) SetUser(dbUser *pb.DBUser, dbUserExpand *pb.DBUserExpand) {
|
||||||
|
p.user = &UserInfo{DbUser: dbUser, DbUserExpand: dbUserExpand}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Login
|
||||||
|
func (p *PttServiceImpl) Login(sid int32, account string) (code pb.ErrorCode, rsp *pb.UserLoginResp) {
|
||||||
|
head := &pb.UserMessage{MainType: string(comm.ModuleUser), SubType: user.UserSubTypeLogin}
|
||||||
|
head.Sec = common.BuildSecStr(sid, account)
|
||||||
|
if err := p.connService.SendMsg(head, &pb.UserLoginReq{
|
||||||
|
Account: account,
|
||||||
|
Sid: sid,
|
||||||
|
}); err != nil {
|
||||||
|
code = pb.ErrorCode_SystemError
|
||||||
|
logrus.WithField("err", err).Error("Login")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//respone
|
||||||
|
for {
|
||||||
|
if cd, msg := p.connService.ReceiveMsg(); cd != pb.ErrorCode_Success {
|
||||||
|
code = cd
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
//suc
|
||||||
|
rsp = &pb.UserLoginResp{}
|
||||||
|
if msg.MainType == string(comm.ModuleUser) && msg.SubType == user.UserSubTypeLogin {
|
||||||
|
if !comm.ProtoUnmarshal(msg, rsp) {
|
||||||
|
code = pb.ErrorCode_PbError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// create role
|
||||||
|
func (p *PttServiceImpl) CreateRole(nickName string) (code pb.ErrorCode, rsp *pb.UserCreateResp) {
|
||||||
|
head := &pb.UserMessage{MainType: string(comm.ModuleUser), SubType: user.UserSubTypeCreate}
|
||||||
|
head.Sec = common.BuildSecStr(p.user.DbUser.Sid, p.user.DbUser.Binduid)
|
||||||
|
if err := p.connService.SendMsg(head, &pb.UserCreateReq{
|
||||||
|
NickName: nickName,
|
||||||
|
}); err != nil {
|
||||||
|
code = pb.ErrorCode_SystemError
|
||||||
|
logrus.WithField("err", err).Error("CreateRole")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//response
|
||||||
|
for {
|
||||||
|
if cd, msg := p.connService.ReceiveMsg(); cd != pb.ErrorCode_Success {
|
||||||
|
code = cd
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
rsp = &pb.UserCreateResp{}
|
||||||
|
if msg.MainType == string(comm.ModuleUser) && msg.SubType == user.UserSubTypeCreate {
|
||||||
|
if !comm.ProtoUnmarshal(msg, rsp) {
|
||||||
|
code = pb.ErrorCode_PbError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logrus.
|
||||||
|
WithFields(logrus.Fields{"nickname": nickName}).
|
||||||
|
WithFields(logrus.Fields{"rsp": rsp.IsSucc}).
|
||||||
|
Debug("response create role")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
21
cmd/ptt/ui/app_container.go
Normal file
21
cmd/ptt/ui/app_container.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import "fyne.io/fyne/v2/container"
|
||||||
|
|
||||||
|
type appContainer struct {
|
||||||
|
container.DocTabs
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAppContainer() *appContainer {
|
||||||
|
at := &appContainer{}
|
||||||
|
|
||||||
|
return at
|
||||||
|
}
|
||||||
|
|
||||||
|
func (at *appContainer) openApp(app appInterface) error{
|
||||||
|
// for _, appItem := range at.Items {
|
||||||
|
// if appItem.Text ==
|
||||||
|
// }
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
4
cmd/ptt/ui/app_interface.go
Normal file
4
cmd/ptt/ui/app_interface.go
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
type appInterface interface {
|
||||||
|
}
|
10
cmd/ptt/ui/basewindow.go
Normal file
10
cmd/ptt/ui/basewindow.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import "go_dreamfactory/cmd/ptt/lib/common"
|
||||||
|
|
||||||
|
type WindowDefaultOptions struct {
|
||||||
|
windowAction common.WindowAction
|
||||||
|
windowMode common.WindowMode
|
||||||
|
windowAspect common.WindowAspect
|
||||||
|
windowVisible bool
|
||||||
|
}
|
57
cmd/ptt/ui/cz_box_layout.go
Normal file
57
cmd/ptt/ui/cz_box_layout.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Declare conformity with Layout interface
|
||||||
|
var _ fyne.Layout = (*CZBoxLayout)(nil)
|
||||||
|
|
||||||
|
// CZBoxLayout is a grid layout that support custom size of object
|
||||||
|
// Now only support vertical mode
|
||||||
|
type CZBoxLayout struct {
|
||||||
|
vertical bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVCZBoxLayout() fyne.Layout {
|
||||||
|
return &CZBoxLayout{vertical: true}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CZBoxLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
|
||||||
|
pos := fyne.NewPos(0, 0)
|
||||||
|
for _, child := range objects {
|
||||||
|
if !child.Visible() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
child.Move(pos)
|
||||||
|
size := child.Size()
|
||||||
|
if c.vertical {
|
||||||
|
pos = pos.Add(fyne.NewPos(0, size.Height+theme.Padding()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CZBoxLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
|
||||||
|
minSize := fyne.NewSize(0, 0)
|
||||||
|
addPadding := false
|
||||||
|
for _, child := range objects {
|
||||||
|
if !child.Visible() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.vertical {
|
||||||
|
size := child.Size()
|
||||||
|
minSize.Width = fyne.Max(size.Width, minSize.Width)
|
||||||
|
minSize.Height += size.Height
|
||||||
|
if addPadding {
|
||||||
|
minSize.Height += theme.Padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addPadding = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return minSize
|
||||||
|
}
|
17
cmd/ptt/ui/main_menu.go
Normal file
17
cmd/ptt/ui/main_menu.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import "fyne.io/fyne/v2"
|
||||||
|
|
||||||
|
type mainMenu struct {
|
||||||
|
*fyne.MainMenu
|
||||||
|
|
||||||
|
helpMenu *fyne.Menu
|
||||||
|
|
||||||
|
aboutSelf *fyne.MenuItem
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMainMenu() *mainMenu{
|
||||||
|
var mm mainMenu
|
||||||
|
|
||||||
|
return &mm
|
||||||
|
}
|
261
cmd/ptt/ui/mainwindow.go
Normal file
261
cmd/ptt/ui/mainwindow.go
Normal file
@ -0,0 +1,261 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/cmd/ptt/lib/common"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/dialog"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"github.com/Pallinder/go-randomdata"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cast"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MainWindow interface {
|
||||||
|
WindowInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
type MainWindowImpl struct {
|
||||||
|
UIImpl
|
||||||
|
WindowDefaultOptions
|
||||||
|
w fyne.Window
|
||||||
|
|
||||||
|
tb *toolBar
|
||||||
|
toys *toys
|
||||||
|
sb *statusBar
|
||||||
|
at *appContainer //tabs
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMainWindow(ui *UIImpl) MainWindow {
|
||||||
|
return &MainWindowImpl{
|
||||||
|
UIImpl: *ui,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// createWindowContainer create a container with the window content
|
||||||
|
func (ui *MainWindowImpl) createWindowContainer() {
|
||||||
|
// create main layout
|
||||||
|
|
||||||
|
// status bar
|
||||||
|
ui.sb = newStatusBar()
|
||||||
|
|
||||||
|
// tool bar
|
||||||
|
ui.tb = newToolBar()
|
||||||
|
|
||||||
|
// Fun Toys
|
||||||
|
ui.toys = newToys()
|
||||||
|
|
||||||
|
// main app tabs
|
||||||
|
ui.at = newAppContainer()
|
||||||
|
content := container.NewBorder(ui.tb.toolbar, ui.sb.widget, nil, ui.toys.widget, ui.at)
|
||||||
|
ui.w.SetContent(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateWindow ....
|
||||||
|
func (ui *MainWindowImpl) CreateWindow(title string, width, height float32, _ bool) {
|
||||||
|
// init window
|
||||||
|
w := ui.app.NewWindow(title)
|
||||||
|
ui.AddWindow("main", w)
|
||||||
|
ui.w = w
|
||||||
|
|
||||||
|
if ui.windowAspect == common.WindowAspect_FullScreen {
|
||||||
|
w.SetFullScreen(true)
|
||||||
|
} else {
|
||||||
|
w.Resize(fyne.NewSize(width, height))
|
||||||
|
}
|
||||||
|
|
||||||
|
// create main window menu
|
||||||
|
w.SetMainMenu(ui.createMainWindowMenu())
|
||||||
|
|
||||||
|
// create window container
|
||||||
|
// mainLayout := ui.createWindowContainer()
|
||||||
|
|
||||||
|
w.SetMaster()
|
||||||
|
// w.Show()
|
||||||
|
// w.SetContent(mainLayout)
|
||||||
|
w.CenterOnScreen()
|
||||||
|
_ = ui.createChooseServerPopUp(w)
|
||||||
|
}
|
||||||
|
|
||||||
|
// createChooseServerPopUp
|
||||||
|
func (ui *MainWindowImpl) createChooseServerPopUp(w fyne.Window) error {
|
||||||
|
ch := make(chan int32)
|
||||||
|
|
||||||
|
selServerWin := ui.createChooseServerWindow("选服", ch)
|
||||||
|
go func() {
|
||||||
|
sid := <-ch
|
||||||
|
selServerWin.Hide()
|
||||||
|
ui.NewWelcomeLabel(sid)
|
||||||
|
ui.w.Show()
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// createChooseServerWindow
|
||||||
|
func (ui *MainWindowImpl) createChooseServerWindow(
|
||||||
|
title string,
|
||||||
|
ch chan int32) fyne.Window {
|
||||||
|
|
||||||
|
makeButton := func(sid int32, w fyne.Window) *widget.Button {
|
||||||
|
serverName := "service " + cast.ToString(sid)
|
||||||
|
btn := widget.NewButton(serverName, func() {
|
||||||
|
d := dialog.NewInformation("req", common.INFO_WAIT, w)
|
||||||
|
d.SetDismissText(common.BUTTON_CANCEL)
|
||||||
|
d.Show()
|
||||||
|
defer d.Hide()
|
||||||
|
|
||||||
|
logrus.WithField("server", serverName).Debug("choose server")
|
||||||
|
//conn server
|
||||||
|
if err := ui.connService.Connect("ws://localhost:7891/gateway"); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
derr := errors.New("conn err")
|
||||||
|
dialog.ShowError(derr, w)
|
||||||
|
} else {
|
||||||
|
ch <- sid
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
//other btn setting
|
||||||
|
return btn
|
||||||
|
}
|
||||||
|
|
||||||
|
w := ui.app.NewWindow(title)
|
||||||
|
box1 := makeButton(1, w)
|
||||||
|
box2 := makeButton(2, w)
|
||||||
|
box3 := makeButton(3, w)
|
||||||
|
box4 := makeButton(4, w)
|
||||||
|
|
||||||
|
w.SetContent(container.NewGridWithColumns(2, box1, box2, box3, box4))
|
||||||
|
w.SetFixedSize(true)
|
||||||
|
w.Resize(fyne.NewSize(500, 200))
|
||||||
|
w.Show()
|
||||||
|
w.CenterOnScreen()
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
|
// createLoginWin
|
||||||
|
func (ui *MainWindowImpl) createLoginWin(sid int32) {
|
||||||
|
//form
|
||||||
|
account := widget.NewEntry()
|
||||||
|
// account.Validator = validation.NewRegexp(`^(\s*)$`, "account required")
|
||||||
|
// password := widget.NewPasswordEntry()
|
||||||
|
items := []*widget.FormItem{
|
||||||
|
widget.NewFormItem(common.LABEL_ACCOUNT, account),
|
||||||
|
// widget.NewFormItem("password", password),
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.ShowForm(common.FORM_TITLE_LOGIN, common.BUTTON_LOGIN, common.BUTTON_CANCEL, items, func(b bool) {
|
||||||
|
if !b {
|
||||||
|
logrus.Debug("cancel login")
|
||||||
|
} else {
|
||||||
|
if account.Text != "" {
|
||||||
|
logrus.WithField("account", account.Text).Debug("submit login")
|
||||||
|
if code, rsp := ui.pttService.Login(sid, account.Text); code != pb.ErrorCode_Success {
|
||||||
|
err := fmt.Errorf("login err: %v[%d]", code, int32(code))
|
||||||
|
dialog.ShowError(err, ui.w)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//show mainwindow
|
||||||
|
logrus.Debug(rsp)
|
||||||
|
ui.pttService.SetUser(rsp.Data, rsp.Ex)
|
||||||
|
// TODO isCreateRole
|
||||||
|
if rsp.Data.Created {
|
||||||
|
// ui.renderUserContainer()
|
||||||
|
ui.createWindowContainer()
|
||||||
|
} else {
|
||||||
|
ui.createRoleWindowPopUp()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}, ui.w)
|
||||||
|
}
|
||||||
|
|
||||||
|
// createMainWindowMenu create the main window menu
|
||||||
|
func (ui *MainWindowImpl) createMainWindowMenu() *fyne.MainMenu {
|
||||||
|
|
||||||
|
menuItems := []*fyne.MenuItem{}
|
||||||
|
|
||||||
|
menu := fyne.Menu{
|
||||||
|
Label: common.MENU_FILE,
|
||||||
|
Items: menuItems,
|
||||||
|
}
|
||||||
|
return fyne.NewMainMenu(&menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
// createRoleWindowPopUp
|
||||||
|
func (ui *MainWindowImpl) createRoleWindowPopUp() {
|
||||||
|
nickname := widget.NewEntry()
|
||||||
|
c := container.NewHBox(
|
||||||
|
nickname,
|
||||||
|
widget.NewButton(common.BUTTON_RANDOM, func() {
|
||||||
|
nickname.SetText(randomdata.SillyName())
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
items := []*widget.FormItem{
|
||||||
|
widget.NewFormItem(common.LABEL_NICKNAME, c),
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.ShowForm(common.FORM_TITLE_CREATEROLE, common.BUTTON_OK, common.BUTTON_CANCEL, items, func(b bool) {
|
||||||
|
if !b {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if nickname.Text != "" {
|
||||||
|
logrus.WithField("nickname", nickname.Text).Debug("submit crete role")
|
||||||
|
if code, rsp := ui.pttService.CreateRole(nickname.Text); code != pb.ErrorCode_Success {
|
||||||
|
err := fmt.Errorf("login err: %v[%d]", code, int32(code))
|
||||||
|
dialog.ShowError(err, ui.w)
|
||||||
|
} else {
|
||||||
|
if rsp.IsSucc {
|
||||||
|
user := ui.pttService.GetUser()
|
||||||
|
logrus.WithField("uid", user.DbUser.Uid).Debug("create role succ")
|
||||||
|
} else {
|
||||||
|
logrus.Error("create role failure")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, ui.w)
|
||||||
|
}
|
||||||
|
|
||||||
|
// renderUserContainer fill userinfo in container
|
||||||
|
func (ui *MainWindowImpl) renderUserContainer() {
|
||||||
|
userInfo := ui.pttService.GetUser()
|
||||||
|
var (
|
||||||
|
nickname string
|
||||||
|
)
|
||||||
|
|
||||||
|
if userInfo != nil && userInfo.DbUser != nil {
|
||||||
|
nickname = userInfo.DbUser.Name
|
||||||
|
}
|
||||||
|
c := container.NewCenter(container.NewHBox(
|
||||||
|
widget.NewLabelWithStyle(common.LABEL_NICKNAME+nickname,
|
||||||
|
fyne.TextAlignCenter,
|
||||||
|
fyne.TextStyle{Bold: true}),
|
||||||
|
))
|
||||||
|
ui.w.SetContent(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWelcomeLabel
|
||||||
|
func (ui *MainWindowImpl) NewWelcomeLabel(sid int32) {
|
||||||
|
c := container.NewCenter(container.NewVBox(
|
||||||
|
widget.NewLabelWithStyle(common.LABEL_WELCOME+cast.ToString(sid),
|
||||||
|
fyne.TextAlignCenter,
|
||||||
|
fyne.TextStyle{Bold: true}),
|
||||||
|
container.NewCenter(container.NewHBox(
|
||||||
|
widget.NewButton(common.BUTTON_LOGIN, func() {
|
||||||
|
ui.createLoginWin(sid)
|
||||||
|
}),
|
||||||
|
widget.NewButton(common.BUTTON_REGISTE, func() {
|
||||||
|
logrus.Debug("registe")
|
||||||
|
}),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
ui.w.SetContent(c)
|
||||||
|
}
|
22
cmd/ptt/ui/status_bar.go
Normal file
22
cmd/ptt/ui/status_bar.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/layout"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
)
|
||||||
|
|
||||||
|
type statusBar struct {
|
||||||
|
msgLabel *widget.Label
|
||||||
|
widget *fyne.Container
|
||||||
|
}
|
||||||
|
|
||||||
|
func newStatusBar() *statusBar {
|
||||||
|
var sb statusBar
|
||||||
|
sb.msgLabel = widget.NewLabel("")
|
||||||
|
sb.widget = container.New(layout.NewHBoxLayout(),
|
||||||
|
sb.msgLabel,
|
||||||
|
layout.NewSpacer())
|
||||||
|
return &sb
|
||||||
|
}
|
24
cmd/ptt/ui/tool_bar.go
Normal file
24
cmd/ptt/ui/tool_bar.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/theme"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
)
|
||||||
|
|
||||||
|
type toolBar struct {
|
||||||
|
toolbar *widget.Toolbar
|
||||||
|
}
|
||||||
|
|
||||||
|
func newToolBar() *toolBar {
|
||||||
|
var tb toolBar
|
||||||
|
|
||||||
|
tb.toolbar = widget.NewToolbar(
|
||||||
|
widget.NewToolbarAction(theme.ResourceWelIcon, func() {
|
||||||
|
|
||||||
|
}),
|
||||||
|
widget.NewToolbarSeparator(),
|
||||||
|
widget.NewToolbarAction(theme.ResourceAboutIcon, func() {}),
|
||||||
|
)
|
||||||
|
return &tb
|
||||||
|
}
|
17
cmd/ptt/ui/toys.go
Normal file
17
cmd/ptt/ui/toys.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
)
|
||||||
|
|
||||||
|
type toys struct {
|
||||||
|
widget *fyne.Container
|
||||||
|
}
|
||||||
|
|
||||||
|
func newToys() *toys {
|
||||||
|
var t toys
|
||||||
|
|
||||||
|
t.widget = container.New(NewVCZBoxLayout())
|
||||||
|
return &t
|
||||||
|
}
|
51
cmd/ptt/ui/ui.go
Normal file
51
cmd/ptt/ui/ui.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/cmd/ptt/service"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UI interface {
|
||||||
|
AddWindow(name string, w fyne.Window)
|
||||||
|
Run()
|
||||||
|
Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
type UIImpl struct {
|
||||||
|
app fyne.App
|
||||||
|
windows map[string]fyne.Window
|
||||||
|
winMux *sync.Mutex
|
||||||
|
connService service.ConnService
|
||||||
|
pttService service.PttService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUI(
|
||||||
|
app fyne.App,
|
||||||
|
connService service.ConnService,
|
||||||
|
pttService service.PttService,
|
||||||
|
) *UIImpl {
|
||||||
|
// app.Settings().SetTheme(theme.DarkTheme())
|
||||||
|
return &UIImpl{
|
||||||
|
app: app,
|
||||||
|
windows: make(map[string]fyne.Window),
|
||||||
|
winMux: &sync.Mutex{},
|
||||||
|
connService: connService,
|
||||||
|
pttService: pttService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *UIImpl) AddWindow(name string, w fyne.Window) {
|
||||||
|
ui.winMux.Lock()
|
||||||
|
defer ui.winMux.Unlock()
|
||||||
|
ui.windows[name] = w
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *UIImpl) Run() {
|
||||||
|
ui.app.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *UIImpl) Stop() {
|
||||||
|
ui.app.Quit()
|
||||||
|
}
|
5
cmd/ptt/ui/windowInterface.go
Normal file
5
cmd/ptt/ui/windowInterface.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
type WindowInterface interface {
|
||||||
|
CreateWindow(title string,width,height float32, visible bool)
|
||||||
|
}
|
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,41 +0,0 @@
|
|||||||
package font
|
|
||||||
|
|
||||||
import (
|
|
||||||
"image/color"
|
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
|
||||||
"fyne.io/fyne/v2/theme"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MyTheme struct{}
|
|
||||||
|
|
||||||
var _ fyne.Theme = (*MyTheme)(nil)
|
|
||||||
|
|
||||||
func (*MyTheme) Font(s fyne.TextStyle) fyne.Resource {
|
|
||||||
if s.Monospace {
|
|
||||||
return theme.DefaultTheme().Font(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.Bold {
|
|
||||||
if s.Italic {
|
|
||||||
return theme.DefaultTheme().Font(s)
|
|
||||||
}
|
|
||||||
return resourceMsyhbdTtc
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.Italic {
|
|
||||||
return theme.DefaultTheme().Font(s)
|
|
||||||
}
|
|
||||||
return resourceMsyhTtc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*MyTheme) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
|
|
||||||
return theme.DefaultTheme().Color(n, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*MyTheme) Icon(n fyne.ThemeIconName) fyne.Resource {
|
|
||||||
return theme.DefaultTheme().Icon(n)
|
|
||||||
}
|
|
||||||
func (*MyTheme) Size(n fyne.ThemeSizeName) float32 {
|
|
||||||
return theme.DefaultTheme().Size(n)
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go_dreamfactory/cmd/win/assets/font"
|
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
|
||||||
"fyne.io/fyne/v2/app"
|
|
||||||
"fyne.io/fyne/v2/widget"
|
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MyApp struct {
|
|
||||||
app fyne.App
|
|
||||||
ws *websocket.Conn
|
|
||||||
opts *Options
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewApp() *MyApp {
|
|
||||||
a := app.NewWithID("dreamfactory")
|
|
||||||
a.Settings().SetTheme(&font.MyTheme{})
|
|
||||||
return &MyApp{app: a}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *MyApp) Run() {
|
|
||||||
// connect
|
|
||||||
opts := DefaultOpts()
|
|
||||||
ws, _, err := websocket.DefaultDialer.Dial(opts.WsUrl, nil)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Fatalf("websocket conn err:%v", err)
|
|
||||||
}
|
|
||||||
this.ws = ws
|
|
||||||
|
|
||||||
this.ShowLoginWin()
|
|
||||||
this.app.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 登录窗口
|
|
||||||
func (this *MyApp) ShowLoginWin() {
|
|
||||||
accountEntry := widget.NewEntry()
|
|
||||||
accountEntry.TextStyle = fyne.TextStyle{Bold: true}
|
|
||||||
accountEntry.SetPlaceHolder("输入账号")
|
|
||||||
accountEntry.Text = "user7273"
|
|
||||||
// accountEntry.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "username can only contain letters, numbers, '_', and '-'")
|
|
||||||
sidEntry := widget.NewEntry()
|
|
||||||
sidEntry.Text = "0"
|
|
||||||
// password.Validator = validation.NewRegexp(`^[A-Za-z0-9_-]+$`, "password can only contain letters, numbers, '_', and '-'")
|
|
||||||
|
|
||||||
items := []*widget.FormItem{
|
|
||||||
widget.NewFormItem("账号", accountEntry),
|
|
||||||
widget.NewFormItem("区服", sidEntry),
|
|
||||||
}
|
|
||||||
|
|
||||||
loginWin := fyne.CurrentApp().NewWindow("登录")
|
|
||||||
loginForm := widget.NewForm(items...)
|
|
||||||
loginForm.SubmitText = "登录"
|
|
||||||
loginForm.OnSubmit = func() {
|
|
||||||
if accountEntry.Text != "" {
|
|
||||||
loginWin.Close()
|
|
||||||
|
|
||||||
//
|
|
||||||
// opts := robot.DefaultOpts()
|
|
||||||
// opts.Account = accountEntry.Text
|
|
||||||
// opts.ServerId = cast.ToInt32(sidEntry.Text)
|
|
||||||
// robot.NewRobot(opts).Run()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
loginWin.Resize(fyne.Size{300, 160})
|
|
||||||
loginWin.SetFixedSize(true)
|
|
||||||
loginWin.SetContent(loginForm)
|
|
||||||
loginWin.CenterOnScreen()
|
|
||||||
loginWin.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 主窗口
|
|
||||||
func (this *MyApp) ShowMainWin() {
|
|
||||||
// this.mainWin = this.app.NewWindow("昊天锤")
|
|
||||||
// this.mainWin.Resize(fyne.NewSize(1366, 768))
|
|
||||||
// this.mainWin.CenterOnScreen()
|
|
||||||
// this.mainWin.SetOnClosed(func() {
|
|
||||||
// cnf := dialog.NewConfirm("退出", "确定退出程序吗?", func(b bool) {
|
|
||||||
// if !b {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// }, this.mainWin)
|
|
||||||
// cnf.SetConfirmText("确定")
|
|
||||||
// cnf.SetDismissText("取消")
|
|
||||||
// cnf.Show()
|
|
||||||
// })
|
|
||||||
// top_left := widget.NewMultiLineEntry()
|
|
||||||
// top_right := widget.NewMultiLineEntry()
|
|
||||||
// bottom := widget.NewMultiLineEntry()
|
|
||||||
// top := container.NewHSplit(top_left, top_right)
|
|
||||||
// cont := container.NewVSplit(top, bottom)
|
|
||||||
// this.mainWin.SetContent(cont)
|
|
||||||
// this.mainWin.Show()
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
|
||||||
logrus.SetFormatter(&logrus.TextFormatter{})
|
|
||||||
|
|
||||||
//设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
|
|
||||||
file, err := os.OpenFile("gui.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
|
||||||
writers := []io.Writer{
|
|
||||||
file,
|
|
||||||
os.Stdout}
|
|
||||||
|
|
||||||
//同时写文件和屏幕
|
|
||||||
fileAndStdoutWriter := io.MultiWriter(writers...)
|
|
||||||
if err == nil {
|
|
||||||
logrus.SetOutput(fileAndStdoutWriter)
|
|
||||||
} else {
|
|
||||||
logrus.Info("failed to log to file.")
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package core
|
|
||||||
|
|
||||||
type Options struct {
|
|
||||||
WsUrl string //客户端访问网关的ws接口地址
|
|
||||||
RegUrl string //账号注册接口地址
|
|
||||||
Account string //玩家账号
|
|
||||||
Create bool
|
|
||||||
Secretkey string //秘钥串
|
|
||||||
ServerId int32 //区服ID
|
|
||||||
Role bool //是否创角
|
|
||||||
}
|
|
||||||
|
|
||||||
func DefaultOpts() *Options {
|
|
||||||
return &Options{
|
|
||||||
WsUrl: "ws://localhost:7891/gateway",
|
|
||||||
RegUrl: "http://localhost:8000/register",
|
|
||||||
ServerId: 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Option func(*Options)
|
|
||||||
|
|
||||||
func WithWsUrl(addr string) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.WsUrl = addr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithAccount(account string) Option {
|
|
||||||
return func(o *Options) {
|
|
||||||
o.Account = account
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package handle
|
|
||||||
|
|
||||||
type Handle struct{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func login() {
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go_dreamfactory/cmd/win/core"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
app := core.NewApp()
|
|
||||||
app.Run()
|
|
||||||
}
|
|
@ -2,11 +2,11 @@ package comm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/log"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
@ -69,7 +69,7 @@ type IUserSession interface {
|
|||||||
func ProtoUnmarshal(msg *pb.UserMessage, req proto.Message) (ok bool) {
|
func ProtoUnmarshal(msg *pb.UserMessage, req proto.Message) (ok bool) {
|
||||||
err := msg.Data.UnmarshalTo(req)
|
err := msg.Data.UnmarshalTo(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("UnmarshalTo %s.%s %v", msg.MainType, msg.SubType, err)
|
fmt.Printf("UnmarshalTo %s.%s %v\n", msg.MainType, msg.SubType, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -79,7 +79,7 @@ func ProtoUnmarshal(msg *pb.UserMessage, req proto.Message) (ok bool) {
|
|||||||
func ProtoMarshal(rsp proto.Message, msg *pb.UserMessage) (ok bool) {
|
func ProtoMarshal(rsp proto.Message, msg *pb.UserMessage) (ok bool) {
|
||||||
any, err := anypb.New(rsp)
|
any, err := anypb.New(rsp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Any New %s.%s %v", msg.MainType, msg.SubType, err)
|
fmt.Printf("Any New %s.%s %v", msg.MainType, msg.SubType, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
msg.Data = any
|
msg.Data = any
|
||||||
|
Loading…
Reference in New Issue
Block a user