environment

package
v0.0.0-...-7f57805 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 10 Imported by: 14

Documentation

Index

Constants

View Source
const DefaultConfigFilename = "config.yaml"

DefaultConfigFilename is the default config filename

View Source
const DefaultHome = Home("${HOME}/.fabric")

DefaultHome is the default cli home directory

Variables

View Source
var DefaultStreams = Streams{
	In:  os.Stdin,
	Out: os.Stdout,
	Err: os.Stderr,
}

DefaultStreams contains the default io streams

Functions

This section is empty.

Types

type Action

type Action func(c *Config)

Action is used to modify config

func DeleteContext

func DeleteContext(name string) Action

DeleteContext deletes a specified context

func DeleteNetwork

func DeleteNetwork(name string) Action

DeleteNetwork deletes the specified network

func SetContext

func SetContext(name string, context *Context) Action

SetContext adds or updates the specified context

func SetCurrentContext

func SetCurrentContext(context string) Action

SetCurrentContext updates the current context

func SetNetwork

func SetNetwork(name string, network *Network) Action

SetNetwork adds or updates the specified network

type Config

type Config struct {
	Networks       map[string]*Network `yaml:",omitempty"`
	Contexts       map[string]*Context `yaml:",omitempty"`
	CurrentContext string              `yaml:"current-context,omitempty"`
}

Config contains information needed to manage fabric networks

func NewConfig

func NewConfig() *Config

NewConfig returns a new config

func (*Config) AddFlags

func (c *Config) AddFlags(fs *pflag.FlagSet)

AddFlags appeneds config flags onto an existing flag set

func (*Config) GetCurrentContext

func (c *Config) GetCurrentContext() (*Context, error)

GetCurrentContext returns the current context

func (*Config) GetCurrentContextNetwork

func (c *Config) GetCurrentContextNetwork() (*Network, error)

GetCurrentContextNetwork returns the current network

func (*Config) LoadFromFile

func (c *Config) LoadFromFile(path string) error

LoadFromFile populates config based on the specified path

func (*Config) Save

func (c *Config) Save(path string) error

Save writes the current config value to the specified path

type Context

type Context struct {
	Network      string   `yaml:",omitempty"`
	Organization string   `yaml:",omitempty"`
	User         string   `yaml:",omitempty"`
	Channel      string   `yaml:",omitempty"`
	Orderers     []string `yaml:",omitempty"`
	Peers        []string `yaml:",omitempty"`
}

Context contains network interaction parameters

func (*Context) String

func (c *Context) String() string

type Home

type Home string

Home is the location of the configuration files By default, the files are stored in ~/.fabric

func (Home) Init

func (h Home) Init() error

Init creates a home directory if it does not already exist

func (Home) Path

func (h Home) Path(components ...string) string

Path appends compoenents to home and returns it as a string

func (Home) Plugins

func (h Home) Plugins() string

Plugins returns the path to the plugins directory

func (Home) String

func (h Home) String() string

String resolves variables and returns home as a string

type Network

type Network struct {
	// path to fabric go sdk config file
	ConfigPath string `yaml:"path,omitempty"`
}

Network contains a fabric network's configurations

func (*Network) String

func (n *Network) String() string

type Settings

type Settings struct {
	Home           Home
	Streams        Streams
	DisablePlugins bool
	Config         *Config
	// contains filtered or unexported fields
}

Settings contains environment configuration details

func NewDefaultSettings

func NewDefaultSettings() *Settings

NewDefaultSettings returns settings populated with default values

func (*Settings) AddFlags

func (s *Settings) AddFlags(fs *pflag.FlagSet)

AddFlags appeneds settings flags onto an existing flag set

func (*Settings) Init

func (s *Settings) Init(fs *pflag.FlagSet) error

Init populates the settings based on a precedence:

Flag > Env > Config File > Defaults

func (*Settings) ModifyConfig

func (s *Settings) ModifyConfig(actions ...Action) error

ModifyConfig loads the config file and updates it based on actions

func (*Settings) SetupPluginEnvironment

func (s *Settings) SetupPluginEnvironment()

SetupPluginEnvironment sets the environment variables that are important to plugins This is needed because environment variables are not populated with defaults

type Streams

type Streams struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
}

Streams contains io stream configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL