config

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 11 Imported by: 5

Documentation

Index

Constants

View Source
const AltiEmail = "ALTI_EMAIL"

AltiEmail is the key of environment variable of user email.

View Source
const AltiEndpoint = "ALTI_ENDPOINT"

AltiEndpoint is the key of environment variable of endpoint.

View Source
const AltiKey = "ALTI_KEY"

AltiKey is the key of environment variable of app key.

View Source
const AltiName = "ALTI_NAME"

AltiName is the key of environment variable of user name.

View Source
const AltiToken = "ALTI_TOKEN"

AltiToken is the key of environment variable of user token.

View Source
const DefaultAppKey = "Ah8bOakrkmSl2FA9OCbT8EnFOUrPwOOZ7HQxZm6"

DefaultAppKey is the default app key used by this cli.

View Source
const DefaultEndpoint = "https://api.altizure.com"

DefaultEndpoint is the default api endpoint.

View Source
const DefaultHostName1 = "api.altizure.com"

DefaultHostName1 is the default public international api hostname.

View Source
const DefaultHostName2 = "api.altizure.cn"

DefaultHostName2 is the default public api hostname in China.

View Source
const DefaultProfileID = "default"

DefaultProfileID is the default profile id.

View Source
const DefaultScope = "https://api*altizure*com"

DefaultScope is the default api scope.

Variables

This section is empty.

Functions

func EnvOrDefault

func EnvOrDefault(envKey, defaultVal string) string

EnvOrDefault loads env var if any, otherwise reuturn default string.

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the path of the config directory that contains the config.yaml file.

Types

type APoint

type APoint struct {
	Endpoint string `yaml:"endpoint" json:"endpoint"`
	Name     string `yaml:"name" json:"name"`
	Email    string `yaml:"email" json:"email"`
	Key      string `yaml:"key" json:"key"`
	Token    string `yaml:"token" json:"token"`
}

APoint represents the active endping and profile.

type Config

type Config struct {
	Scopes map[string]Scope `yaml:"scopes"`
	Active string           `yaml:"active"` // active profile id
}

Config represents everything in the config stored by viper.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default endpoint and api key.

func FromEnv

func FromEnv() (Config, bool)

FromEnv loads config from env vars, and return if the config is valid. Otherwise, return the default config.

func Load

func Load() Config

Load loads config from env var first. If not exists, load from default path. If not found in default path, load from default config.

func (*Config) AddProfile

func (c *Config) AddProfile(ap APoint) error

AddProfile adds a profile under its endpoint and set it as active. Existing values would be replaced.

func (*Config) ClearActiveToken

func (c *Config) ClearActiveToken(save bool) error

ClearActiveToken clears the token of active profile.

func (Config) GetActive

func (c Config) GetActive() APoint

GetActive returns the active endpoint and profile of current config.

func (Config) GetProfile

func (c Config) GetProfile(id string) (*Profile, error)

GetProfile finds the closest profile that matches the given id. If no match, return ErrProfileNotFound

func (Config) RemoveProfile

func (c Config) RemoveProfile(id string, save bool) (*APoint, error)

RemoveProfile removes the closest profile that matches the given id. If no match, return ErrProfileNotFound If active profile is removed, default profile will be set as active. Default profile could not be removed. Return the removed APoint if succeed.

func (Config) Save

func (c Config) Save() error

Save saves the config in default path: '~/.altizure/config'.

func (*Config) SetActiveUserInfo

func (c *Config) SetActiveUserInfo(name, email string, save bool) error

SetActiveUserInfo sets the username of the active profile.

func (*Config) Size

func (c *Config) Size() int

Size counts the number of profiles.

func (Config) String

func (c Config) String() string

type Profile

type Profile struct {
	ID    string `yaml:"id"`
	Name  string `yaml:"name"`
	Email string `yaml:"email"`
	Key   string `yaml:"key"`
	Token string `yaml:"token"`
}

Profile represents the login profile of a user of a certain endpoint.

func (Profile) Equal

func (p Profile) Equal(o Profile) bool

Equal commpares if two profiles are equal, ignoring id.

type Scope

type Scope struct {
	Endpoint string    `yaml:"endpoint"`
	Profiles []Profile `yaml:"profiles"`
}

Scope represents a certain endpint and a list of profiles. An endpoint is the main domain without sub-path, e.g. api.altizure.com or 127.0.0.1:8082

func (*Scope) Add

func (s *Scope) Add(p Profile) Profile

Add adds a profile in this scope. Return the newly added or existing profile.

Jump to

Keyboard shortcuts

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