ing
This commit is contained in:
45
central/api/module/noauthprobe.go
Normal file
45
central/api/module/noauthprobe.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package module
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
NoAuthProbeHeader_NoAuthID = "overFlow-NoAuth-ID"
|
||||
NoAuthProbeHeader_NoAuthRegist = "overFlow-NoAuth-Regist"
|
||||
NoAuthProbeHeader_SetNoAuthID = "overFlow-Set-NoAuth-ID"
|
||||
)
|
||||
|
||||
type NoAuthProbe struct {
|
||||
ID uint64 `json:"id"`
|
||||
Description string `json:"description"`
|
||||
TempProbeKey string `json:"tempProbeKey"`
|
||||
CreateDate time.Time `json:"createDate"`
|
||||
APIKey string `json:"apiKey"`
|
||||
}
|
||||
|
||||
const (
|
||||
NoAuthProbeService_Regist = "NoAuthProbeService.regist"
|
||||
NoAuthProbeService_AcceptNoAuthProbe = "NoAuthProbeService.acceptNoAuthProbe"
|
||||
NoAuthProbeService_DenyNoauthProbe = "NoAuthProbeService.denyNoauthProbe"
|
||||
)
|
||||
|
||||
type NoAuthProbeDescription struct {
|
||||
Host NoAuthProbeDescriptionHost `json:"host"`
|
||||
Network NoAuthProbeDescriptionNetwork `json:"network"`
|
||||
}
|
||||
|
||||
type NoAuthProbeDescriptionHost struct {
|
||||
Name string `json:"name"`
|
||||
OS string `json:"os"`
|
||||
Platform string `json:"paltform"`
|
||||
PlatformFamily string `json:"platformFamily"`
|
||||
PlatformVersion string `json:"platformVersion"`
|
||||
KernelVersion string `json:"kernelVersion"`
|
||||
HostID string `json:"hostID"`
|
||||
}
|
||||
|
||||
type NoAuthProbeDescriptionNetwork struct {
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Gateway string `json:"gateway"`
|
||||
MacAddress string `json:"macAddress"`
|
||||
}
|
||||
@@ -20,6 +20,7 @@ const (
|
||||
|
||||
type (
|
||||
OnNotifyFunc func(method string, params interface{})
|
||||
OnCloseFunc func(code int, text string)
|
||||
)
|
||||
|
||||
type ServerError string
|
||||
@@ -54,6 +55,7 @@ type Client interface {
|
||||
Call(method string, args interface{}, result interface{}) error
|
||||
Notify(method string, args interface{}) error
|
||||
OnNotify(method string, cb OnNotifyFunc)
|
||||
OnClose(cb OnCloseFunc)
|
||||
Shutdown(ctx context.Context) error
|
||||
}
|
||||
|
||||
@@ -68,6 +70,7 @@ type client struct {
|
||||
closing bool // user has called Close
|
||||
shutdown bool // server has told us to stop
|
||||
onNotifyHandlers map[string][]OnNotifyFunc
|
||||
onCloseHandlers []OnCloseFunc
|
||||
}
|
||||
|
||||
func New() Client {
|
||||
@@ -75,6 +78,7 @@ func New() Client {
|
||||
requestID: 0,
|
||||
pending: make(map[uint64]*Call),
|
||||
onNotifyHandlers: make(map[string][]OnNotifyFunc),
|
||||
onCloseHandlers: make([]OnCloseFunc, 1),
|
||||
}
|
||||
|
||||
return c
|
||||
@@ -93,6 +97,8 @@ func (c *client) Dial(url string, header http.Header, readBufSize int, writeBufS
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.conn.SetCloseHandler(c.connCloseHandler)
|
||||
|
||||
go c.input()
|
||||
|
||||
return res, nil
|
||||
@@ -128,6 +134,10 @@ func (c *client) OnNotify(method string, cb OnNotifyFunc) {
|
||||
hs = append(hs, cb)
|
||||
}
|
||||
|
||||
func (c *client) OnClose(cb OnCloseFunc) {
|
||||
c.onCloseHandlers = append(c.onCloseHandlers, cb)
|
||||
}
|
||||
|
||||
func (c *client) Shutdown(ctx context.Context) error {
|
||||
c.mutex.Lock()
|
||||
if c.closing {
|
||||
@@ -292,3 +302,11 @@ func (c *client) onNotification(noti protocol.Notification) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *client) connCloseHandler(code int, text string) error {
|
||||
for _, h := range c.onCloseHandlers {
|
||||
h(code, text)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user