Select Git revision
generate-stackbrew-library.sh
config.go 4.29 KiB
// package config implements the ipfs config file datastructures and utilities.
package config
import (
"bytes"
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/mitchellh/go-homedir"
)
// Config is used to load ipfs config files.
type Config struct {
Identity Identity // local node's peer identity
Datastore Datastore // local node's storage
Addresses Addresses // local node's addresses
Mounts Mounts // local node's mount points
Discovery Discovery // local node's discovery mechanisms
Routing Routing // local node's routing settings
Ipns Ipns // Ipns settings
Bootstrap []string // local nodes's bootstrap peer addresses
Gateway Gateway // local node's gateway server options
API API // local node's API settings
Swarm SwarmConfig
AutoNAT AutoNATConfig
Pubsub PubsubConfig
Peering Peering
DNS DNS
Migration Migration
Provider Provider
Reprovider Reprovider
Experimental Experiments
Plugins Plugins
Pinning Pinning
Internal Internal // experimental/unstable options
}
const (
// DefaultPathName is the default config dir name
DefaultPathName = ".ipfs"
// DefaultPathRoot is the path to the default config dir location.
DefaultPathRoot = "~/" + DefaultPathName
// DefaultConfigFile is the filename of the configuration file
DefaultConfigFile = "config"
// EnvDir is the environment variable used to change the path root.
EnvDir = "IPFS_PATH"
)
// PathRoot returns the default configuration root directory
func PathRoot() (string, error) {
dir := os.Getenv(EnvDir)
var err error
if len(dir) == 0 {
dir, err = homedir.Expand(DefaultPathRoot)
}
return dir, err
}
// Path returns the path `extension` relative to the configuration root. If an
// empty string is provided for `configroot`, the default root is used.
func Path(configroot, extension string) (string, error) {
if len(configroot) == 0 {
dir, err := PathRoot()
if err != nil {
return "", err