generated from root/miduo_server
110 lines
3.1 KiB
Go
110 lines
3.1 KiB
Go
package netutil
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/text/gstr"
|
|
"gmanager/common"
|
|
"gmanager/library/thrift"
|
|
"net"
|
|
"os"
|
|
)
|
|
|
|
type Gmcmd struct {
|
|
ServerIp string
|
|
ServerPort string
|
|
Cmd string
|
|
UserId string
|
|
Args string
|
|
}
|
|
|
|
func (gmcmd *Gmcmd) SendGM() int32 {
|
|
transportFactory := thrift.NewTTransportFactory()
|
|
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
|
|
transport, err := thrift.NewTSocket(net.JoinHostPort(gmcmd.ServerIp, gmcmd.ServerPort))
|
|
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "error resolving address:", err)
|
|
//os.Exit(1)
|
|
return -100
|
|
}
|
|
|
|
useTransport := transportFactory.GetTransport(transport)
|
|
client := common.NewRPCRequestGMIFaceClientFactory(useTransport, protocolFactory)
|
|
if err := transport.Open(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Error opening socket to server", " ", err)
|
|
//os.Exit(1)
|
|
return -101
|
|
}
|
|
defer transport.Close()
|
|
|
|
//for i := 0; i < 2; i++ {
|
|
arges := gmcmd.Args
|
|
if gstr.Equal("sendmail", gmcmd.Cmd) {
|
|
arges = gmcmd.UserId + " " + arges
|
|
} else if gstr.Equal("modifyitem", gmcmd.Cmd) {
|
|
arges = gmcmd.UserId + " " + arges
|
|
}
|
|
cmd := gmcmd.Cmd + " " + gmcmd.UserId + " " + arges
|
|
fmt.Println("cmd "+cmd)
|
|
r1, e1 := client.IdipGm(gmcmd.Cmd, cmd)
|
|
fmt.Println("Call->", r1, e1)
|
|
return *r1.ResultCode
|
|
//}
|
|
}
|
|
|
|
func (gmcmd *Gmcmd) SendGMAll() int32 {
|
|
transportFactory := thrift.NewTTransportFactory()
|
|
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
|
|
transport, err := thrift.NewTSocket(net.JoinHostPort(gmcmd.ServerIp, gmcmd.ServerPort))
|
|
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "error resolving address:", err)
|
|
//os.Exit(1)
|
|
return -100
|
|
}
|
|
|
|
useTransport := transportFactory.GetTransport(transport)
|
|
client := common.NewRPCRequestGMIFaceClientFactory(useTransport, protocolFactory)
|
|
if err := transport.Open(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Error opening socket to server", " ", err)
|
|
//os.Exit(1)
|
|
return -101
|
|
}
|
|
defer transport.Close()
|
|
|
|
cmd := gmcmd.Cmd + " " + g.Config().GetString("userId") + " " + gmcmd.Args
|
|
//cmd := gmcmd.Cmd + " " + gmcmd.Args
|
|
//fmt.Println("cmd==========================================",cmd)
|
|
r1, e1 := client.IdipGm(gmcmd.Cmd, cmd)
|
|
fmt.Println("Call->", r1, e1)
|
|
return *r1.ResultCode
|
|
}
|
|
|
|
func (gmcmd *Gmcmd) Creatcdk() int32 {
|
|
transportFactory := thrift.NewTTransportFactory()
|
|
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
|
|
transport, err := thrift.NewTSocket(net.JoinHostPort(gmcmd.ServerIp, gmcmd.ServerPort))
|
|
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "error resolving address:", err)
|
|
//os.Exit(1)
|
|
return -100
|
|
}
|
|
|
|
useTransport := transportFactory.GetTransport(transport)
|
|
client := common.NewRPCRequestGMIFaceClientFactory(useTransport, protocolFactory)
|
|
if err := transport.Open(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Error opening socket to server", " ", err)
|
|
//os.Exit(1)
|
|
return -101
|
|
}
|
|
defer transport.Close()
|
|
|
|
cmd := gmcmd.Cmd + " " + gmcmd.Args
|
|
//fmt.Println("cmd==========================================",cmd)
|
|
r1, e1 := client.IdipGm(gmcmd.Cmd, cmd)
|
|
fmt.Println("Call->", r1, e1)
|
|
return *r1.ResultCode
|
|
}
|