Documentation ¶
Index ¶
- Constants
- Variables
- func AnalysisMessage(dp *DataPacket) bool
- func CreateTopicName(sAPI string, sUserID string, sServiceID string, sVersionID string) string
- func LoadServerConfig() error
- func PacketHeartBeat(sID string) []byte
- func PacketPushLog(SAPI string, sUserID string, sServiceID string, sVersion string, sLog string, ...) []byte
- func PacketResponse(sResponse string, sIDAck string, nErrorCode int) []byte
- func PacketWatchLog(SAPI string, sUserID string, sServiceID string, sVersion string, ...) []byte
- func PushTopic(wss *WSSession, pWatchLog *WatchLogPacket)
- func StartServer() (err error)
- type DataPacket
- func (p *DataPacket) GetData() []byte
- func (p *DataPacket) GetLength() int
- func (p *DataPacket) GetReceiveFrom() string
- func (p *DataPacket) GetSendTo() string
- func (p *DataPacket) SetData(byrFrame []byte)
- func (p *DataPacket) SetLength(nLen int)
- func (p *DataPacket) SetReceiveFrom(sReceiveFrom string)
- func (p *DataPacket) SetSendTo(sSendTo string)
- type HeartBeatPacket
- type IDataPacket
- type ISession
- type MsgHandler
- type PushLogPacket
- type ResponsePacket
- type ServerConfig
- type SessionList
- type WSSession
- func (wss *WSSession) ClearTopicEnable()
- func (wss *WSSession) GetSessionID() string
- func (wss *WSSession) GetTopicEnable(sTopic string) bool
- func (wss *WSSession) OnClosed()
- func (wss *WSSession) OnReceive(iData IDataPacket) bool
- func (wss *WSSession) OnStart(sSessionID string)
- func (wss *WSSession) Send(iData IDataPacket)
- func (wss *WSSession) SessionTimeoverCheck() bool
- func (wss *WSSession) SetTopicEnable(sTopic string, bEnable bool)
- func (wss *WSSession) UpdateActiveTime()
- type WatchLogPacket
- type WorkerPushLogPacket
Constants ¶
const ( // Localhost is the ip of localhost. Localhost = "127.0.0.1" // WSServerPort is the port of websocket server. WSServerPort = 8000 // MaxConnectionNumber is the default maximum number of connections. MaxConnectionNumber = 4096 // IdleSessionTimeOut is the default timeout for idle sessions. IdleSessionTimeOut = 120 // IdleCheckInterval is the default interval for idle checks. IdleCheckInterval = 30 )
const ( Error_Code_Successful = 0 Error_Code_Failure = 4001 )
const (
DOCKER_IMAGE_LOG_FLAG = "layer"
)
Variables ¶
var ErrorMsgMap = map[int]string{
0: "successful",
4001: "failure",
}
ErrorMsgMap is the map from status code to error message.
var MsgHandlerMap = map[string]MsgHandler{
"watch_log": watchLogHandler,
"heart_beat": heartBeatHandler,
"worker_push_log": workerPushLogHandler,
}
MsgHandlerMap is the map of web client message handler
Functions ¶
func AnalysisMessage ¶
func AnalysisMessage(dp *DataPacket) bool
AnalysisMessage analysis message receive from the web client.
func CreateTopicName ¶
CreateTopicName creat topic name as: api__userid__serviceid__versionid
func LoadServerConfig ¶
func LoadServerConfig() error
LoadServerConfig load config of push-log websocket server
func PacketHeartBeat ¶
PacketHeartBeat packet the data frame of heart beat
func PacketPushLog ¶
func PacketPushLog(SAPI string, sUserID string, sServiceID string, sVersion string, sLog string, sID string) []byte
PacketPushLog packet the data frame of push log
func PacketResponse ¶
PacketResponse packet the data frame of response
func PacketWatchLog ¶
func PacketWatchLog(SAPI string, sUserID string, sServiceID string, sVersion string, sOperation string, sID string) []byte
PacketWatchLog packet the data frame of watch log
func PushTopic ¶
func PushTopic(wss *WSSession, pWatchLog *WatchLogPacket)
PushTopic push log from special topic to web client
Types ¶
type DataPacket ¶
type DataPacket struct {
// contains filtered or unexported fields
}
DataPacket is the type for data packet.
func (*DataPacket) GetData ¶
func (p *DataPacket) GetData() []byte
GetData gets date from data packet.
func (*DataPacket) GetLength ¶
func (p *DataPacket) GetLength() int
GetLength gets the length of data.
func (*DataPacket) GetReceiveFrom ¶
func (p *DataPacket) GetReceiveFrom() string
GetReceiveFrom gets the session id of the date receive from.
func (*DataPacket) GetSendTo ¶
func (p *DataPacket) GetSendTo() string
GetSendTo gets the session id of the date need send to.
func (*DataPacket) SetData ¶
func (p *DataPacket) SetData(byrFrame []byte)
SetData sets data in data packet.
func (*DataPacket) SetLength ¶
func (p *DataPacket) SetLength(nLen int)
SetLength sets length of data.
func (*DataPacket) SetReceiveFrom ¶
func (p *DataPacket) SetReceiveFrom(sReceiveFrom string)
SetReceiveFrom sets the session id of the date receive from.
func (*DataPacket) SetSendTo ¶
func (p *DataPacket) SetSendTo(sSendTo string)
SetSendTo sets the session id of the date need send to.
type HeartBeatPacket ¶
HeartBeatPacket is the type for heart_beat packet.
type IDataPacket ¶
type IDataPacket interface { GetLength() int GetData() []byte GetSendTo() string GetReceiveFrom() string }
IDataPacket is the interface for data packet.
type ISession ¶
type ISession interface { OnClosed() OnStart(sSessionID string) OnReceive(datapacket IDataPacket) bool Send(datapacket IDataPacket) GetSessionID() string }
ISession is the interface for session.
type MsgHandler ¶
MsgHandler is the type for message handler.
type PushLogPacket ¶
type PushLogPacket struct { Action string `json:"action"` Api string `json:"api"` UserId string `json:"user_id"` ServiceId string `json:"service_id"` VersionId string `json:"version_id"` Log string `json:"log"` Id string `json:"id"` }
PushLogPacket is the type for push_log packet.
type ResponsePacket ¶
type ResponsePacket struct { Action string `json:"action"` Response string `json:"response"` IdAck string `json:"id_ack"` ErrorCode int `json:"error_code"` ErrorMsg string `json:"error_msg"` }
ResponsePacket is the type for response packet.
type ServerConfig ¶
type ServerConfig struct { // ServerIP is the IP of server. ServerIP string `yml:"ServerIp"` // Port is the port of server. Port int `yml:"ServerPort"` // MaxConnectionNumber is maximum number of connections. MaxConnectionNumber int `yml:"MaxConnectionNumber"` // IdleSessionTimeOut is the timeout for idle sessions. IdleSessionTimeOut int64 `yml:"IdleSessionTimeOut"` // IdleCheckInterval is the interval for idle checks. IdleCheckInterval int `yml:"IdleCheckInterval"` // ServerCertificate is the certificate of server. ServerCertificate string `yml:"ServerCertificate"` // ServerKey is the key of server. ServerKey string `yml:"ServerKey"` }
ServerConfig is the config of push-log websocket server
type SessionList ¶
SessionList is the type for session list.
func (*SessionList) GetSession ¶
func (sl *SessionList) GetSession(sSessionID string) ISession
GetSession get one session from web client session list by sessionid
type WSSession ¶
type WSSession struct { //sync log for tapic enable flags sync.RWMutex // contains filtered or unexported fields }
WSSession is the type for web socket session.
func CreateWSSession ¶
CreateWSSession create new session and incert it to sessionlist
func (*WSSession) ClearTopicEnable ¶
func (wss *WSSession) ClearTopicEnable()
ClearTopicEnable clear the map of tapic enable flags
func (*WSSession) GetSessionID ¶
GetSessionID get the session id
func (*WSSession) GetTopicEnable ¶
GetTopicEnable get sepcial topic enable flag
func (*WSSession) OnClosed ¶
func (wss *WSSession) OnClosed()
OnClosed handle something when the session close remove session from sessionlist close websocket link clear member var
func (*WSSession) OnReceive ¶
func (wss *WSSession) OnReceive(iData IDataPacket) bool
OnReceive handle something when the session receive message analysis the message
func (*WSSession) Send ¶
func (wss *WSSession) Send(iData IDataPacket)
Send sends data packet to web client
func (*WSSession) SessionTimeoverCheck ¶
SessionTimeoverCheck check timeout if unreceive vaild message from web cliet
func (*WSSession) SetTopicEnable ¶
SetTopicEnable set sepcial topic enable flag
func (*WSSession) UpdateActiveTime ¶
func (wss *WSSession) UpdateActiveTime()
UpdateActiveTime updates active time of this session.
type WatchLogPacket ¶
type WatchLogPacket struct { Action string `json:"action"` Api string `json:"api"` UserId string `json:"user_id"` ServiceId string `json:"service_id"` VersionId string `json:"version_id"` Operation string `json:"operation"` Id string `json:"id"` }
WatchLogPacket is the type for watch_log packet.
type WorkerPushLogPacket ¶
type WorkerPushLogPacket struct { Action string `json:"action"` Topic string `json:"topic"` Log string `json:"log"` }
WorkerPushLogPacket is the type for worker_push_log packet.