Documentation ¶
Index ¶
- Constants
- func EnvOrDefault(envKey, defaultVal string) string
- func GetConfigDir() (string, error)
- type APoint
- type Config
- func (c *Config) AddProfile(ap APoint) error
- func (c *Config) ClearActiveToken(save bool) error
- func (c Config) GetActive() APoint
- func (c Config) GetProfile(id string) (*Profile, error)
- func (c Config) RemoveProfile(id string, save bool) (*APoint, error)
- func (c Config) Save() error
- func (c *Config) SetActiveUserInfo(name, email string, save bool) error
- func (c *Config) Size() int
- func (c Config) String() string
- type Profile
- type Scope
Constants ¶
const AltiEmail = "ALTI_EMAIL"
AltiEmail is the key of environment variable of user email.
const AltiEndpoint = "ALTI_ENDPOINT"
AltiEndpoint is the key of environment variable of endpoint.
const AltiKey = "ALTI_KEY"
AltiKey is the key of environment variable of app key.
const AltiName = "ALTI_NAME"
AltiName is the key of environment variable of user name.
const AltiToken = "ALTI_TOKEN"
AltiToken is the key of environment variable of user token.
const DefaultAppKey = "Ah8bOakrkmSl2FA9OCbT8EnFOUrPwOOZ7HQxZm6"
DefaultAppKey is the default app key used by this cli.
const DefaultEndpoint = "https://api.altizure.com"
DefaultEndpoint is the default api endpoint.
const DefaultHostName1 = "api.altizure.com"
DefaultHostName1 is the default public international api hostname.
const DefaultHostName2 = "api.altizure.cn"
DefaultHostName2 is the default public api hostname in China.
const DefaultProfileID = "default"
DefaultProfileID is the default profile id.
const DefaultScope = "https://api*altizure*com"
DefaultScope is the default api scope.
Variables ¶
This section is empty.
Functions ¶
func EnvOrDefault ¶
EnvOrDefault loads env var if any, otherwise reuturn default string.
func GetConfigDir ¶
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 ¶
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 ¶
AddProfile adds a profile under its endpoint and set it as active. Existing values would be replaced.
func (*Config) ClearActiveToken ¶
ClearActiveToken clears the token of active profile.
func (Config) GetProfile ¶
GetProfile finds the closest profile that matches the given id. If no match, return ErrProfileNotFound
func (Config) RemoveProfile ¶
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) SetActiveUserInfo ¶
SetActiveUserInfo sets the username of the active profile.
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.