config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagNameProject     = "project"
	FlagNameEnvironment = "environment"
)

Flags for scope context.

View Source
const (
	FlagNameServer   = "server"
	FlagNameAPIKey   = "api-key"
	FlagNameInsecure = "insecure"
)

Flags for server context.

Variables

View Source
var InjectFields = []string{"project", "environment"}

Functions

func GetConfigDir added in v0.5.0

func GetConfigDir() string

GetConfigDir get config dir.

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 (c *Config) CheckReachable() (err error)

func (*Config) DoRequest

func (c *Config) DoRequest(req *http.Request) (*http.Response, error)

DoRequest send request to server.

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

func (c *Config) HttpClient(timeout time.Duration) *http.Client

HttpClient generate http client base on context config.

func (*Config) ServerVersion added in v0.5.0

func (c *Config) ServerVersion() (*Version, error)

func (*Config) SetHeaders added in v0.5.0

func (c *Config) SetHeaders(req *http.Request)

SetHeaders set default headers.

func (*Config) SetHost added in v0.5.0

func (c *Config) SetHost(req *http.Request) error

func (*Config) ValidateAndSetup

func (c *Config) ValidateAndSetup() (err error)

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.

type Version added in v0.5.0

type Version struct {
	Version string `json:"version" yaml:"version"`
	Commit  string `json:"commit" yaml:"commit"`
}

Version include the version and commit.

Jump to

Keyboard shortcuts

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