Skip to content

Commit

Permalink
The DataserverIp func created in api client
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-scherba committed Nov 20, 2023
1 parent ef5395d commit 4332b5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
42 changes: 26 additions & 16 deletions api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"net"

"github.com/kirill-scherba/bslice"
)
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion teonet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit 4332b5b

Please sign in to comment.