package
0.0.0-20240720025851-28b05a40bd25
Repository: https://github.com/openmesh-network/core.git
Documentation: pkg.go.dev
# README
Package Config
This directory is for supporting the configuration functionalities.
Add New Configurations
Step 1: Specify a configuration struct
anywhere like the struct below:
// P2pConfig is the configuration for libp2p-related instances
type P2pConfig struct {
Addr string `yaml:"addr"` // libp2p listening address (default: 0.0.0.0)
Port int `yaml:"port"` // libp2p listening port
GroupName string `yaml:"groupName"` // Name used for discovering nodes via mDNS
PeerLimit int `yaml:"peerLimit"` // Max number of peers this node can establish connection to
}
Requirements:
- This struct must be exported.
- All the fields in the struct must be exported.
- Use the
yaml
tag to specify the key for this config in the yml config file.
Step 2: Add this struct to the config
struct:
// config is the configuration structure for the whole Openmesh Core project
type config struct {
P2P P2pConfig `yaml:"p2p"`
}
Requirements:
- The field for this struct must be exported.
- Use the
yaml
tag to specify the key for this config in the yml config file.
Step 3: Add configurations in config.yml
(default configuration file) or other customised configuration file.
p2p:
# 0.0.0.0 = localhost
addr: 0.0.0.0
# 0 = random port
port: 0
groupName: xnode
peerLimit: 50
Step 4: Retrieve your configuration value from the config.Config
global variable:
limit := config.Config.P2P.PeerLimit