2019-07-03 16:59:49 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
// Root is starting point of the config
|
|
|
|
type Root struct {
|
2019-07-04 12:04:39 +00:00
|
|
|
API API
|
|
|
|
Libp2p Libp2p
|
2019-07-03 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// API contains configs for API endpoint
|
|
|
|
type API struct {
|
|
|
|
ListenAddress string
|
|
|
|
Timeout Duration
|
|
|
|
}
|
|
|
|
|
2019-07-04 12:04:39 +00:00
|
|
|
// Libp2p contains configs for libp2p
|
|
|
|
type Libp2p struct {
|
|
|
|
ListenAddresses []string
|
|
|
|
}
|
|
|
|
|
2019-07-03 16:59:49 +00:00
|
|
|
// Default returns the default config
|
|
|
|
func Default() *Root {
|
|
|
|
def := Root{
|
|
|
|
API: API{
|
|
|
|
ListenAddress: "/ip6/::1/tcp/1234/http",
|
|
|
|
Timeout: Duration(30 * time.Second),
|
|
|
|
},
|
2019-07-04 12:04:39 +00:00
|
|
|
Libp2p: Libp2p{
|
|
|
|
ListenAddresses: []string{
|
2019-07-09 13:46:55 +00:00
|
|
|
"/ip4/0.0.0.0/tcp/0",
|
|
|
|
"/ip6/::/tcp/0",
|
2019-07-04 12:04:39 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-03 16:59:49 +00:00
|
|
|
}
|
|
|
|
return &def
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration is a wrapper type for time.Duration for decoding it from TOML
|
|
|
|
type Duration time.Duration
|
|
|
|
|
|
|
|
// UnmarshalText implements interface for TOML decoding
|
|
|
|
func (dur *Duration) UnmarshalText(text []byte) error {
|
|
|
|
d, err := time.ParseDuration(string(text))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*dur = Duration(d)
|
|
|
|
return err
|
|
|
|
}
|