This commit is contained in:
crusader 2017-09-28 15:53:04 +09:00
parent b1eb6aa5f6
commit 6e88452b1b
5 changed files with 14 additions and 15 deletions

View File

@ -9,7 +9,7 @@ import (
"git.loafle.net/overflow/overflow_probes/central/api/module" "git.loafle.net/overflow/overflow_probes/central/api/module"
) )
func (h *authHandlers) onNotify(method string, params interface{}) { func (h *authHandlers) onNotify(method string, params []string) {
switch method { switch method {
case module.NoAuthProbeService_AcceptNoAuthProbe: case module.NoAuthProbeService_AcceptNoAuthProbe:
h.onNoAuthProbeAccept(params) h.onNoAuthProbeAccept(params)
@ -21,10 +21,9 @@ func (h *authHandlers) onNotify(method string, params interface{}) {
} }
func (h *authHandlers) onNoAuthProbeAccept(params interface{}) { func (h *authHandlers) onNoAuthProbeAccept(params []string) {
var err error var err error
ps := params.([]string) probeID := params[0]
probeID := ps[0]
if lfcc.Exists(h.probeConfigPath) { if lfcc.Exists(h.probeConfigPath) {
if err = lfcc.Load(&h.probeConfig, h.probeConfigPath); nil != err { if err = lfcc.Load(&h.probeConfig, h.probeConfigPath); nil != err {
@ -40,7 +39,7 @@ func (h *authHandlers) onNoAuthProbeAccept(params interface{}) {
h.acceptedChan <- true h.acceptedChan <- true
} }
func (h *authHandlers) onNoAuthProbeDeny(params interface{}) { func (h *authHandlers) onNoAuthProbeDeny(params []string) {
n := time.Now() n := time.Now()
h.noAuthConfig.DenyDate = &n h.noAuthConfig.DenyDate = &n
if err := lfcc.Save(h.noAuthConfig, h.noAuthConfigPath, true); nil != err { if err := lfcc.Save(h.noAuthConfig, h.noAuthConfigPath, true); nil != err {

View File

@ -19,7 +19,7 @@ const (
) )
type ( type (
OnNotifyFunc func(method string, params interface{}) OnNotifyFunc func(method string, params []string)
OnCloseFunc func(code int, text string) OnCloseFunc func(code int, text string)
) )
@ -33,7 +33,7 @@ var ErrShutdown = errors.New("connection is shut down")
type Call struct { type Call struct {
Method string // The name of the service and method to call. Method string // The name of the service and method to call.
Args interface{} // The argument to the function (*struct). Args []string // The argument to the function (*struct).
Result interface{} // The reply from the function (*struct). Result interface{} // The reply from the function (*struct).
Error error // After completion, the error status. Error error // After completion, the error status.
Done chan *Call // Strobes when call is complete. Done chan *Call // Strobes when call is complete.
@ -52,8 +52,8 @@ func (c *Call) done() {
type Client interface { type Client interface {
Dial(url string, header http.Header, readBufSize int, writeBufSize int) (*http.Response, error) Dial(url string, header http.Header, readBufSize int, writeBufSize int) (*http.Response, error)
Call(method string, args interface{}, result interface{}) error Call(method string, args []string, result interface{}) error
Notify(method string, args interface{}) error Notify(method string, args []string) error
OnNotify(cb OnNotifyFunc) OnNotify(cb OnNotifyFunc)
OnClose(cb OnCloseFunc) OnClose(cb OnCloseFunc)
Shutdown(ctx context.Context) error Shutdown(ctx context.Context) error
@ -103,12 +103,12 @@ func (c *client) Dial(url string, header http.Header, readBufSize int, writeBufS
return res, nil return res, nil
} }
func (c *client) Call(method string, args interface{}, result interface{}) error { func (c *client) Call(method string, args []string, result interface{}) error {
call := <-c.goCall(method, args, result, make(chan *Call, 1)).Done call := <-c.goCall(method, args, result, make(chan *Call, 1)).Done
return call.Error return call.Error
} }
func (c *client) Notify(method string, args interface{}) error { func (c *client) Notify(method string, args []string) error {
c.sendMutex.Lock() c.sendMutex.Lock()
defer c.sendMutex.Unlock() defer c.sendMutex.Unlock()
@ -146,7 +146,7 @@ func (c *client) Shutdown(ctx context.Context) error {
// the invocation. The done channel will signal when the call is complete by returning // the invocation. The done channel will signal when the call is complete by returning
// the same Call object. If done is nil, Go will allocate a new channel. // the same Call object. If done is nil, Go will allocate a new channel.
// If non-nil, done must be buffered or Go will deliberately crash. // If non-nil, done must be buffered or Go will deliberately crash.
func (c *client) goCall(method string, args interface{}, result interface{}, done chan *Call) *Call { func (c *client) goCall(method string, args []string, result interface{}, done chan *Call) *Call {
call := new(Call) call := new(Call)
call.Method = method call.Method = method
call.Args = args call.Args = args

View File

@ -2,6 +2,6 @@ package protocol
type Notification struct { type Notification struct {
Header Header
Method string `json:"method"` Method string `json:"method"`
Params interface{} `json:"params,omitempty"` Params []string `json:"params,omitempty"`
} }

BIN
overflow_probes Executable file

Binary file not shown.

View File

@ -113,7 +113,7 @@ func (p *probe) connectToCentral() error {
return nil return nil
} }
func (p *probe) onNotify(method string, params interface{}) { func (p *probe) onNotify(method string, params []string) {
switch method { switch method {
case module.NoAuthProbeService_AcceptNoAuthProbe: case module.NoAuthProbeService_AcceptNoAuthProbe: