mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-24 09:24:36 +00:00
Merge pull request #2839 from nspcc-dev/port-string
config: use string type for Port
This commit is contained in:
commit
bbb35f52e3
4 changed files with 8 additions and 8 deletions
|
@ -2,7 +2,6 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// BasicService is used as a simple base for node services like Pprof, RPC or
|
// BasicService is used as a simple base for node services like Pprof, RPC or
|
||||||
|
@ -12,7 +11,7 @@ type BasicService struct {
|
||||||
// Deprecated: please, use Addresses section instead. This field will be removed later.
|
// Deprecated: please, use Addresses section instead. This field will be removed later.
|
||||||
Address *string `yaml:"Address,omitempty"`
|
Address *string `yaml:"Address,omitempty"`
|
||||||
// Deprecated: please, use Addresses section instead. This field will be removed later.
|
// Deprecated: please, use Addresses section instead. This field will be removed later.
|
||||||
Port *uint16 `yaml:"Port,omitempty"`
|
Port *string `yaml:"Port,omitempty"`
|
||||||
// Addresses holds the list of bind addresses in the form of "address:port".
|
// Addresses holds the list of bind addresses in the form of "address:port".
|
||||||
Addresses []string `yaml:"Addresses"`
|
Addresses []string `yaml:"Addresses"`
|
||||||
}
|
}
|
||||||
|
@ -25,7 +24,7 @@ func (s BasicService) GetAddresses() []string {
|
||||||
if s.Address != nil || s.Port != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
|
if s.Address != nil || s.Port != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
|
||||||
var (
|
var (
|
||||||
addr string
|
addr string
|
||||||
port uint16
|
port string
|
||||||
)
|
)
|
||||||
if s.Address != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
|
if s.Address != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
|
||||||
addr = *s.Address //nolint:staticcheck // SA1019: s.Address is deprecated
|
addr = *s.Address //nolint:staticcheck // SA1019: s.Address is deprecated
|
||||||
|
@ -33,7 +32,7 @@ func (s BasicService) GetAddresses() []string {
|
||||||
if s.Port != nil { //nolint:staticcheck // SA1019: s.Port is deprecated
|
if s.Port != nil { //nolint:staticcheck // SA1019: s.Port is deprecated
|
||||||
port = *s.Port //nolint:staticcheck // SA1019: s.Port is deprecated
|
port = *s.Port //nolint:staticcheck // SA1019: s.Port is deprecated
|
||||||
}
|
}
|
||||||
addrs = append(addrs, net.JoinHostPort(addr, strconv.FormatUint(uint64(port), 10)))
|
addrs = append(addrs, net.JoinHostPort(addr, port))
|
||||||
}
|
}
|
||||||
return addrs
|
return addrs
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
func TestBasicService_GetAddresses(t *testing.T) {
|
func TestBasicService_GetAddresses(t *testing.T) {
|
||||||
addr := "1.2.3.4"
|
addr := "1.2.3.4"
|
||||||
port := uint16(1234)
|
port := "1234"
|
||||||
s := BasicService{
|
s := BasicService{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
Address: &addr,
|
Address: &addr,
|
||||||
|
|
|
@ -3,6 +3,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
@ -66,8 +67,8 @@ func LoadFile(configPath string) (Config, error) {
|
||||||
config := Config{
|
config := Config{
|
||||||
ApplicationConfiguration: ApplicationConfiguration{
|
ApplicationConfiguration: ApplicationConfiguration{
|
||||||
P2P: P2P{
|
P2P: P2P{
|
||||||
PingInterval: 30,
|
PingInterval: 30 * time.Second,
|
||||||
PingTimeout: 30,
|
PingTimeout: 90 * time.Second,
|
||||||
},
|
},
|
||||||
RPC: RPC{
|
RPC: RPC{
|
||||||
MaxIteratorResultItems: DefaultMaxIteratorResultItems,
|
MaxIteratorResultItems: DefaultMaxIteratorResultItems,
|
||||||
|
|
|
@ -20,5 +20,5 @@ MaxGasInvoke: 15
|
||||||
err := yaml.Unmarshal([]byte(data), &cfg)
|
err := yaml.Unmarshal([]byte(data), &cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, cfg.Enabled)
|
require.True(t, cfg.Enabled)
|
||||||
require.Equal(t, uint16(10332), *cfg.Port)
|
require.Equal(t, "10332", *cfg.Port)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue