提交 38efe89d 编写于 作者: J Jason

小修改

上级 f6e7e623
......@@ -20,7 +20,10 @@ func NewChannel(channel *types.Channel) (Channel, error) {
if channel.Role == "client" {
return &Client{
baseChannel: baseChannel{
Channel: *channel,
ChannelExt: types.ChannelExt{
Channel: *channel,
Online: true,
},
},
}, nil
} else if channel.Role == "server" {
......@@ -28,13 +31,19 @@ func NewChannel(channel *types.Channel) (Channel, error) {
case "tcp", "tcp4", "tcp6", "unix":
return &Server{
baseChannel: baseChannel{
Channel: *channel,
ChannelExt: types.ChannelExt{
Channel: *channel,
Online: true,
},
},
}, nil
case "udp", "udp4", "udp6", "unixgram":
return &PacketServer{
baseChannel: baseChannel{
Channel: *channel,
ChannelExt: types.ChannelExt{
Channel: *channel,
Online: true,
},
},
}, nil
default:
......@@ -46,12 +55,9 @@ func NewChannel(channel *types.Channel) (Channel, error) {
}
type baseChannel struct {
types.Channel
types.ChannelExt
clients sync.Map
Rx int `json:"rx"`
Tx int `json:"tx"`
}
func (c *baseChannel) GetChannel() *types.Channel {
......
......@@ -13,10 +13,7 @@ import (
)
type Link struct {
types.Link
Rx int
Tx int
types.LinkExt
//设备连接
conn net.Conn
......@@ -116,14 +113,13 @@ func (l *Link) storeError(err error) error {
func newLink(ch Channel, conn net.Conn) *Link {
c := ch.GetChannel()
return &Link{
Link: types.Link{
Role: c.Role,
Net: c.Net,
Addr: conn.RemoteAddr().String(),
ChannelId: c.Id,
//PluginId: c.PluginId,
LinkExt: types.LinkExt{
Link: types.Link{
Net: c.Net,
Addr: conn.RemoteAddr().String(),
ChannelId: c.Id,
},
Online: true,
OnlineAt: time.Now(),
},
conn: conn,
cache: make([][]byte, 0),
......@@ -133,14 +129,13 @@ func newLink(ch Channel, conn net.Conn) *Link {
func newPacketLink(ch Channel, conn net.PacketConn, addr net.Addr) *Link {
c := ch.GetChannel()
return &Link{
Link: types.Link{
Role: c.Role,
Net: c.Net,
Addr: addr.String(),
ChannelId: c.Id,
//PluginId: c.PluginId,
LinkExt: types.LinkExt{
Link: types.Link{
Net: c.Net,
Addr: addr.String(),
ChannelId: c.Id,
},
Online: true,
OnlineAt: time.Now(),
},
conn: base.NewPackConn(conn, addr),
cache: make([][]byte, 0),
......
......@@ -2,6 +2,11 @@ package types
import "time"
type Statistic struct {
Rx int `json:"rx"`
Tx int `json:"tx"`
}
type Channel struct {
Id int `json:"id" storm:"id,increment"`
Name string `json:"name"`
......@@ -24,6 +29,33 @@ type Channel struct {
HeartBeatIsHex bool `json:"heart_beat_is_hex"`
//PluginId int `json:"plugin_id"`
//TODO 默认模型
CreatedAt time.Time `json:"created_at"`
}
type ChannelExt struct {
Channel `storm:"inline"`
Statistic
Links int `json:"links"`
Online bool `json:"online"`
}
type Link struct {
Id int `json:"id" storm:"id,increment"`
Name string `json:"name"`
Error string `json:"error"`
Serial string `json:"serial" storm:"index"`
Net string `json:"net"`
Addr string `json:"addr"`
ChannelId int `json:"channel_id"`
CreatedAt time.Time `json:"created_at"`
}
type LinkExt struct {
Link `storm:"inline"`
Statistic
Online bool `json:"online"`
}
package types
import (
"time"
)
type Link struct {
Id int `json:"id" storm:"id,increment"`
Name string `json:"name"`
Error string `json:"error"`
Serial string `json:"serial" storm:"index"`
Role string `json:"role"`
Net string `json:"net"`
Addr string `json:"addr"`
ChannelId int `json:"channel_id"`
//PluginId int `json:"plugin_id"` //插件ID
Online bool `json:"online"`
OnlineAt time.Time `json:"online_at"`
CreatedAt time.Time `json:"created_at"`
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册