rest/libp2p-http: address @zenground0 comments
License: MIT Signed-off-by: Hector Sanjuan <code@hector.link>
This commit is contained in:
parent
09f4c9fce3
commit
6777122abf
|
@ -89,6 +89,11 @@ func NewAPI(cfg *Config) (*API, error) {
|
|||
// NewAPIWithHost creates a new REST API component and enables
|
||||
// the libp2p-http endpoint using the given Host, if not nil.
|
||||
func NewAPIWithHost(cfg *Config, h host.Host) (*API, error) {
|
||||
err := cfg.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
s := &http.Server{
|
||||
ReadTimeout: cfg.ReadTimeout,
|
||||
|
@ -112,7 +117,7 @@ func NewAPIWithHost(cfg *Config, h host.Host) (*API, error) {
|
|||
api.addRoutes(router)
|
||||
|
||||
// Set up api.httpListener if enabled
|
||||
err := api.setupHTTP()
|
||||
err = api.setupHTTP()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -155,11 +160,8 @@ func (api *API) setupHTTP() error {
|
|||
}
|
||||
|
||||
func (api *API) setupLibp2p(ctx context.Context) error {
|
||||
if api.config.Libp2pListenAddr == nil && api.host == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Make new host. Override existing
|
||||
// Make new host. Override any provided existing one
|
||||
// iif we have config for a custom one,
|
||||
if api.config.Libp2pListenAddr != nil {
|
||||
h, err := libp2p.New(
|
||||
ctx,
|
||||
|
|
|
@ -76,12 +76,11 @@ func NewCluster(
|
|||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
if host == nil {
|
||||
h, err := NewClusterHost(ctx, cfg)
|
||||
host, err = NewClusterHost(ctx, cfg)
|
||||
if err != nil {
|
||||
cancel()
|
||||
return nil, err
|
||||
}
|
||||
host = h
|
||||
}
|
||||
|
||||
if c := Commit; len(c) >= 8 {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
ma "github.com/multiformats/go-multiaddr"
|
||||
)
|
||||
|
||||
// NewClusterHost creates a libp2p Host with the options in the from the
|
||||
// NewClusterHost creates a libp2p Host with the options from the
|
||||
// provided cluster configuration.
|
||||
func NewClusterHost(ctx context.Context, cfg *Config) (host.Host, error) {
|
||||
var prot ipnet.Protector
|
||||
|
|
Loading…
Reference in New Issue
Block a user