Documentation ¶
Index ¶
- Constants
- Variables
- func GetConfigDir() string
- func SetServerContextToCache(s ServerContext) error
- type CommonConfig
- type Config
- func (c *Config) CheckReachable() (err error)
- func (c *Config) DoRequest(req *http.Request) (*http.Response, error)
- func (c *Config) DoRequestWithTimeout(req *http.Request, timeout time.Duration) (*http.Response, error)
- func (c *Config) HttpClient(timeout time.Duration) *http.Client
- func (c *Config) ServerVersion() (*Version, error)
- func (c *Config) SetHeaders(req *http.Request)
- func (c *Config) SetHost(req *http.Request) error
- func (c *Config) ValidateAndSetup() (err error)
- type ScopeContext
- type ServerContext
- func (c *ServerContext) AddFlags(cmd *cobra.Command)
- func (c *ServerContext) ContextExisted(name string) bool
- func (c *ServerContext) Inject(cmd *cobra.Command) error
- func (c *ServerContext) InjectFields() []string
- func (c *ServerContext) InjectURI(uri, name string) string
- func (c *ServerContext) Merge(ns ServerContext, flags *pflag.FlagSet) ServerContext
- func (c *ServerContext) OpenAPIURL() (*url.URL, error)
- type Version
Constants ¶
const ( FlagNameProject = "project" FlagNameEnvironment = "environment" )
Flags for scope context.
const ( FlagNameServer = "server" FlagNameAPIKey = "api-key" FlagNameInsecure = "insecure" )
Flags for server context.
Variables ¶
var InjectFields = []string{"project", "environment"}
Functions ¶
func SetServerContextToCache ¶ added in v0.5.0
func SetServerContextToCache(s ServerContext) error
SetServerContextToCache set context to cache.
Types ¶
type CommonConfig ¶
type CommonConfig struct {
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`
}
CommonConfig indicate the common CLI command config.
type Config ¶
type Config struct { CommonConfig `json:",inline" yaml:",inline" mapstructure:",squash"` ServerContext `json:",inline" yaml:",inline" mapstructure:",squash"` }
Config include the common config and server context config.
func (*Config) CheckReachable ¶ added in v0.5.0
func (*Config) DoRequestWithTimeout ¶ added in v0.5.0
func (c *Config) DoRequestWithTimeout(req *http.Request, timeout time.Duration) (*http.Response, error)
DoRequestWithTimeout send request to server with timeout.
func (*Config) HttpClient ¶ added in v0.5.0
HttpClient generate http client base on context config.
func (*Config) ServerVersion ¶ added in v0.5.0
func (*Config) SetHeaders ¶ added in v0.5.0
SetHeaders set default headers.
func (*Config) ValidateAndSetup ¶
ValidateAndSetup validate and setup the context.
type ScopeContext ¶ added in v0.5.0
type ScopeContext struct { // Project name. Project string `json:"project,omitempty" survey:"project"` // Environment name. Environment string `json:"environment,omitempty" survey:"environment"` }
func (*ScopeContext) AddFlags ¶ added in v0.5.0
func (c *ScopeContext) AddFlags(cmd *cobra.Command)
func (*ScopeContext) FlagsData ¶ added in v0.5.0
func (c *ScopeContext) FlagsData() map[string]any
type ServerContext ¶
type ServerContext struct { // Scope context. ScopeContext // Server config. Server string `json:"server" survey:"server"` APIKey string `json:"api-key" survey:"api-key"` Insecure bool `json:"insecure" survey:"insecure"` // Reachable. Reachable bool }
ServerContext contains the server config.
func GetServerContextFromCache ¶ added in v0.5.0
func GetServerContextFromCache() (*ServerContext, error)
GetServerContextFromCache load context from cache.
func InitConfig ¶ added in v0.5.0
func InitConfig() (*ServerContext, error)
InitConfig init config dir and load server context from cache.
func (*ServerContext) AddFlags ¶ added in v0.5.0
func (c *ServerContext) AddFlags(cmd *cobra.Command)
func (*ServerContext) ContextExisted ¶
func (c *ServerContext) ContextExisted(name string) bool
ContextExisted check whether the value already existed in the context.
func (*ServerContext) Inject ¶
func (c *ServerContext) Inject(cmd *cobra.Command) error
Inject update the flags base on the context.
func (*ServerContext) InjectFields ¶
func (c *ServerContext) InjectFields() []string
InjectFields config the fields need to inject.
func (*ServerContext) InjectURI ¶
func (c *ServerContext) InjectURI(uri, name string) string
InjectURI update the uri base on the context.
func (*ServerContext) Merge ¶
func (c *ServerContext) Merge(ns ServerContext, flags *pflag.FlagSet) ServerContext
Merge generate new server context base on old context, new context and flags.
func (*ServerContext) OpenAPIURL ¶
func (c *ServerContext) OpenAPIURL() (*url.URL, error)
OpenAPIURL generate OpenAPI url.