diff --git a/api_client.go b/api_client.go index 3e141aa..3847663 100644 --- a/api_client.go +++ b/api_client.go @@ -11,6 +11,7 @@ import ( "encoding/binary" "errors" "fmt" + "net" "github.com/kirill-scherba/bslice" ) @@ -247,22 +248,6 @@ func (api APIClient) AppName() string { return api.name } // AppLong returns application long name (description). func (api APIClient) AppLong() string { return api.long } -// apiData get return pointer to APIData by cmd number or name. -func (api *APIClient) apiData(command interface{}) (ret *APIData, ok bool) { - cmd, err := api.GetCmd(command) - if err != nil { - return - } - for i := range api.Apis { - if api.Apis[i].cmd == cmd { - ret = &api.Apis[i] - ok = true - return - } - } - return -} - // GetCmd check command type and return command number. func (api *APIClient) GetCmd(command interface{}) (cmd byte, err error) { switch v := command.(type) { @@ -283,6 +268,31 @@ func (api *APIClient) GetCmd(command interface{}) (cmd byte, err error) { return } +// DataserverIp gets dataserver ip address +func (api *APIClient) DataserverIp() (ip string) { + ch, ok := api.teo.channels.get(api.address) + if ok { + ip = ch.Channel().Addr().(*net.UDPAddr).IP.String() + } + return +} + +// apiData get return pointer to APIData by cmd number or name. +func (api *APIClient) apiData(command interface{}) (ret *APIData, ok bool) { + cmd, err := api.GetCmd(command) + if err != nil { + return + } + for i := range api.Apis { + if api.Apis[i].cmd == cmd { + ret = &api.Apis[i] + ok = true + return + } + } + return +} + // getApi send cmdAPI command and get answer with APIDataAr: all API definition. func (api *APIClient) getApi() (err error) { api.SendTo(api.cmdAPI, nil) diff --git a/teonet.go b/teonet.go index 2d80775..887da39 100644 --- a/teonet.go +++ b/teonet.go @@ -18,7 +18,7 @@ import ( "github.com/teonet-go/tru/teolog" ) -const Version = "0.6.5" +const Version = "0.6.6" // Reset random and use rnd instead var rnd = rand.New(rand.NewSource(time.Now().Unix()))