github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/gateway/config.go (about)

     1  package gateway
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  
     7  	"github.com/celestiaorg/celestia-node/libs/utils"
     8  )
     9  
    10  type Config struct {
    11  	Address string
    12  	Port    string
    13  	Enabled bool
    14  }
    15  
    16  func DefaultConfig() Config {
    17  	return Config{
    18  		Address: defaultBindAddress,
    19  		// do NOT expose the same port as celestia-core by default so that both can run on the same machine
    20  		Port:    defaultPort,
    21  		Enabled: false,
    22  	}
    23  }
    24  
    25  func (cfg *Config) Validate() error {
    26  	sanitizedAddress, err := utils.ValidateAddr(cfg.Address)
    27  	if err != nil {
    28  		return fmt.Errorf("gateway: invalid address: %w", err)
    29  	}
    30  	cfg.Address = sanitizedAddress
    31  
    32  	_, err = strconv.Atoi(cfg.Port)
    33  	if err != nil {
    34  		return fmt.Errorf("gateway: invalid port: %s", err.Error())
    35  	}
    36  	return nil
    37  }