diff --git a/addresses.go b/addresses.go index 22c5306..512e2dc 100644 --- a/addresses.go +++ b/addresses.go @@ -1,10 +1,29 @@ package config +import ( + "encoding/json" +) + +// Strings is a helper type that can decode a single string into a string slice. +type Strings []string + +func (o *Strings) UnmarshalJSON(data []byte) error { + if data[0] == '[' { + return json.Unmarshal(data, (*[]string)(o)) + } + var value string + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *o = []string{value} + return nil +} + // Addresses stores the (string) multiaddr addresses for the node. type Addresses struct { Swarm []string // addresses for the swarm to listen on Announce []string // swarm addresses to announce to the network NoAnnounce []string // swarm addresses not to announce to the network - API string // address for the local API (RPC) - Gateway string // address to listen on for IPFS HTTP object gateway + API Strings // address for the local API (RPC) + Gateway Strings // address to listen on for IPFS HTTP object gateway } diff --git a/init.go b/init.go index c4ea9e4..f45bf56 100644 --- a/init.go +++ b/init.go @@ -105,8 +105,8 @@ func addressesConfig() Addresses { }, Announce: []string{}, NoAnnounce: []string{}, - API: "/ip4/127.0.0.1/tcp/5001", - Gateway: "/ip4/127.0.0.1/tcp/8080", + API: Strings{"/ip4/127.0.0.1/tcp/5001"}, + Gateway: Strings{"/ip4/127.0.0.1/tcp/8080"}, } } diff --git a/profile.go b/profile.go index d3f1b42..d23cadc 100644 --- a/profile.go +++ b/profile.go @@ -66,8 +66,8 @@ profile, enables discovery in local networks.`, is useful when using the daemon in test environments.`, Transform: func(c *Config) error { - c.Addresses.API = "/ip4/127.0.0.1/tcp/0" - c.Addresses.Gateway = "/ip4/127.0.0.1/tcp/0" + c.Addresses.API = Strings{"/ip4/127.0.0.1/tcp/0"} + c.Addresses.Gateway = Strings{"/ip4/127.0.0.1/tcp/0"} c.Addresses.Swarm = []string{ "/ip4/127.0.0.1/tcp/0", }