Documentation ¶
Overview ¶
Package general provides the general utilities for the client.
Package general provides the general utilities for the client.
Package general provides the general utilities for the client.
Package general provides the general utilities for the client.
Package general provides the general utilities for the client.
Package general provides the general utilities for the client.
Package general provides the general utilities for the client.
Index ¶
- Constants
- func Capitalize(str string) string
- func CompareYamlNameKind(oldYaml, newYaml string) (*Spec, *Spec, error)
- func CreateExample(desc, command string) string
- func CreateMultiExample(examples []Example) string
- func CreateMultiLineExample(example string) string
- func DurationMostSignificantUnit(d time.Duration) string
- func ErrorMsg(action CmdType, err error, values ...string) error
- func ExitWithError(err error)
- func ExitWithErrorf(format string, a ...interface{})
- func Filter[T any](array []T, filter func(value T) bool) []T
- func Find[T any](array []T, find func(value T) bool) (*T, bool)
- func GenerateExampleFromChild(cmd *cobra.Command)
- func GetHTTPClient() (*http.Client, error)
- func HandleReqWithStreamResp(httpMethod string, path string, yamlBody []byte) (io.ReadCloser, error)
- func HandleRequest(httpMethod string, path string, yamlBody []byte) (body []byte, err error)
- func InAPIResource(arg string, r *api.APIResource) bool
- func Infof(format string, args ...interface{})
- func MakePath(urlTemplate string, a ...interface{}) string
- func MakeURL(path string) (string, error)
- func Map[T1 any, T2 any](array []T1, mapF func(value T1) T2) []T2
- func NewTabWriter() *tabwriter.Writer
- func PrintBody(body []byte)
- func PrintMapInterface(maps []map[string]interface{}, fronts []string, backs []string)
- func PrintTable(table [][]string)
- func PrintTableWithPrefix(table [][]string, prefix string)
- func SuccessMsg(action CmdType, values ...string) string
- func SuccessfulStatusCode(code int) bool
- func UnmarshalMapInterface(body []byte, listBody bool) ([]map[string]interface{}, error)
- func Warnf(format string, args ...interface{})
- func WriteConfig(config *Config) error
- type APIErr
- type ArgInfo
- type AuthInfo
- type Cluster
- type CmdType
- type Config
- type Context
- type CurrentConfig
- func (c *CurrentConfig) GetCertificateAuthority() string
- func (c *CurrentConfig) GetCertificateAuthorityData() []byte
- func (c *CurrentConfig) GetClientCertificate() string
- func (c *CurrentConfig) GetClientCertificateData() []byte
- func (c *CurrentConfig) GetClientKey() string
- func (c *CurrentConfig) GetClientKeyData() []byte
- func (c *CurrentConfig) GetPassword() string
- func (c *CurrentConfig) GetServer() string
- func (c *CurrentConfig) GetUsername() string
- func (c *CurrentConfig) UseHTTPS() bool
- type Example
- type GlobalFlags
- type NamedAuthInfo
- type NamedCluster
- type NamedContext
- type Spec
- type SpecVisitor
- type YAMLVisitor
Constants ¶
const ( // JSONFormat is the json format. JSONFormat string = "json" // YamlFormat is the yaml format. YamlFormat string = "yaml" // DefaultFormat is the default format. DefaultFormat string = "default" )
const ( // APIURL is the prefix of all API URLs. APIURL = "/apis/v2" // HealthURL is the URL of health check. HealthURL = APIURL + "/healthz" // MembersURL is the URL of members. MembersURL = APIURL + "/status/members" // MemberItemURL is the URL of a member. MemberItemURL = APIURL + "/status/members/%s" // ObjectsURL is the URL of objects. ObjectsURL = APIURL + "/objects" // ObjectItemURL is the URL of a object. ObjectItemURL = APIURL + "/objects/%s" // ObjectKindsURL is the URL of object kinds. ObjectKindsURL = APIURL + "/object-kinds" // ObjectTemplateURL is the URL of object template. ObjectTemplateURL = APIURL + "/objects-yaml/%s/%s" // ObjectAPIResources is the URL of object api resources. ObjectAPIResources = APIURL + "/object-api-resources" // StatusObjectsURL is the URL of status objects. StatusObjectsURL = APIURL + "/status/objects" // StatusObjectItemURL is the URL of a status object. StatusObjectItemURL = APIURL + "/status/objects/%s" // WasmCodeURL is the URL of wasm code. WasmCodeURL = APIURL + "/wasm/code" // WasmDataURL is the URL of wasm data. WasmDataURL = APIURL + "/wasm/data/%s/%s" // CustomDataKindURL is the URL of custom data kinds. CustomDataKindURL = APIURL + "/customdatakinds" // CustomDataKindItemURL is the URL of a custom data kind. CustomDataKindItemURL = APIURL + "/customdatakinds/%s" // CustomDataURL is the URL of custom data. CustomDataURL = APIURL + "/customdata/%s" // CustomDataItemURL is the URL of a custom data. CustomDataItemURL = APIURL + "/customdata/%s/%s" // ProfileURL is the URL of profile. ProfileURL = APIURL + "/profile" // ProfileStartURL is the URL of start profile. ProfileStartURL = APIURL + "/profile/start/%s" // ProfileStopURL is the URL of stop profile. ProfileStopURL = APIURL + "/profile/stop" // LogsURL is the URL of logs. LogsURL = APIURL + "/logs" // LogsLevelURL is the URL of logs level. LogsLevelURL = APIURL + "/logs/level" // MetricsURL is the URL of metrics. MetricsURL = APIURL + "/metrics" // HTTPProtocol is prefix for HTTP protocol HTTPProtocol = "http://" // HTTPSProtocol is prefix for HTTPS protocol HTTPSProtocol = "https://" )
Variables ¶
This section is empty.
Functions ¶
func Capitalize ¶
Capitalize capitalizes the first letter of the string.
func CompareYamlNameKind ¶ added in v2.6.1
CompareYamlNameKind compares the name and kind of two YAML strings
func CreateExample ¶
CreateExample creates cobra example by using one line example.
func CreateMultiExample ¶
CreateMultiExample creates cobra example by using multiple examples.
func CreateMultiLineExample ¶ added in v2.6.1
CreateMultiLineExample creates cobra example by using multiple lines.
func DurationMostSignificantUnit ¶
DurationMostSignificantUnit returns the most significant unit of the duration.
func ExitWithError ¶
func ExitWithError(err error)
ExitWithError exits with self-defined message not the one of cobra(such as usage).
func ExitWithErrorf ¶
func ExitWithErrorf(format string, a ...interface{})
ExitWithErrorf wraps ExitWithError with format.
func GenerateExampleFromChild ¶
GenerateExampleFromChild generates cobra example from child commands.
func GetHTTPClient ¶
GetHTTPClient is used to get HTTP client.
func HandleReqWithStreamResp ¶ added in v2.6.1
func HandleRequest ¶
HandleRequest used in cmd/client/resources. It will return the response body in yaml or json format.
func InAPIResource ¶
func InAPIResource(arg string, r *api.APIResource) bool
InAPIResource returns true if the arg is in the api resource.
func Infof ¶ added in v2.6.3
func Infof(format string, args ...interface{})
Infof prints the info message.
func NewTabWriter ¶
NewTabWriter returns a tabwriter.Writer. Remember to call Flush() after using it.
func PrintBody ¶
func PrintBody(body []byte)
PrintBody prints the response body in yaml or json format.
func PrintMapInterface ¶
PrintMapInterface prints the []map[string]interface{} in yaml format. Specials are the keys print in front of other part. Use "" in specials to print a blank line. For example, if specials is ["name", "kind", "", "filters"] then, "name", "kind" will in group one, and "filters" will in group two, others will in group three.
func PrintTableWithPrefix ¶
PrintTableWithPrefix prints the table with prefix.
func SuccessMsg ¶
SuccessMsg returns the success message.
func SuccessfulStatusCode ¶
SuccessfulStatusCode returns true if the status code is successful.
func UnmarshalMapInterface ¶
UnmarshalMapInterface unmarshals the body to []map[string]interface{}.
Types ¶
type ArgInfo ¶
ArgInfo is used to store the information of arguments.
func (*ArgInfo) ContainName ¶
ContainName returns true if the arguments contain name.
func (*ArgInfo) ContainOther ¶
ContainOther returns true if the arguments contain other.
func (*ArgInfo) ContainResource ¶
ContainResource returns true if the arguments contain resource.
type AuthInfo ¶
type AuthInfo struct { ClientCertificate string `json:"client-certificate,omitempty"` ClientCertificateData []byte `json:"client-certificate-data,omitempty"` ClientKey string `json:"client-key,omitempty"` ClientKeyData []byte `json:"client-key-data,omitempty"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` }
AuthInfo is the user configuration.
type Cluster ¶
type Cluster struct { Server string `json:"server"` CertificateAuthority string `json:"certificate-authority,omitempty"` CertificateAuthorityData []byte `json:"certificate-authority-data,omitempty"` }
Cluster is the cluster configuration.
type CmdType ¶
type CmdType string
CmdType is the type of command.
const ( // GetCmd is the get command. GetCmd CmdType = "get" // EditCmd is the edit command. EditCmd CmdType = "edit" // CreateCmd is the create command. CreateCmd CmdType = "create" // ApplyCmd is the apply command. ApplyCmd CmdType = "apply" // DeleteCmd is the delete command. DeleteCmd CmdType = "delete" // DescribeCmd is the describe command. DescribeCmd CmdType = "describe" // StartCmd is the start command. StartCmd CmdType = "start" // StopCmd is the stop command. StopCmd CmdType = "stop" )
type Config ¶
type Config struct { Kind string `json:"kind"` Clusters []NamedCluster `json:"clusters"` AuthInfos []NamedAuthInfo `json:"users"` Contexts []NamedContext `json:"contexts"` CurrentContext string `json:"current-context"` }
Config is the configuration of egctl.
func GetRedactedConfig ¶
GetRedactedConfig returns the config with sensitive data redacted.
type CurrentConfig ¶
type CurrentConfig struct { CurrentContext string `json:"current-context"` Context NamedContext `json:"context"` Cluster NamedCluster `json:"cluster"` AuthInfo NamedAuthInfo `json:"user"` }
CurrentConfig is config contains current used cluster and user.
func GetCurrentConfig ¶
func GetCurrentConfig() (*CurrentConfig, error)
GetCurrentConfig returns the current config.
func (*CurrentConfig) GetCertificateAuthority ¶
func (c *CurrentConfig) GetCertificateAuthority() string
GetCertificateAuthority returns the current used certificate authority file name.
func (*CurrentConfig) GetCertificateAuthorityData ¶
func (c *CurrentConfig) GetCertificateAuthorityData() []byte
GetCertificateAuthorityData returns the current used certificate authority data.
func (*CurrentConfig) GetClientCertificate ¶
func (c *CurrentConfig) GetClientCertificate() string
GetClientCertificate returns the current used client certificate file name.
func (*CurrentConfig) GetClientCertificateData ¶
func (c *CurrentConfig) GetClientCertificateData() []byte
GetClientCertificateData returns the current used client certificate data.
func (*CurrentConfig) GetClientKey ¶
func (c *CurrentConfig) GetClientKey() string
GetClientKey returns the current used client key file name.
func (*CurrentConfig) GetClientKeyData ¶
func (c *CurrentConfig) GetClientKeyData() []byte
GetClientKeyData returns the current used client key data.
func (*CurrentConfig) GetPassword ¶
func (c *CurrentConfig) GetPassword() string
GetPassword returns the current used password.
func (*CurrentConfig) GetServer ¶
func (c *CurrentConfig) GetServer() string
GetServer returns the current used server.
func (*CurrentConfig) GetUsername ¶
func (c *CurrentConfig) GetUsername() string
GetUsername returns the current used username.
func (*CurrentConfig) UseHTTPS ¶
func (c *CurrentConfig) UseHTTPS() bool
UseHTTPS returns whether the current used server is HTTPS.
type GlobalFlags ¶
type GlobalFlags struct { Server string ForceTLS bool InsecureSkipVerify bool OutputFormat string // following are some general flags. Can be used by all commands. But not all commands use them. Verbose bool }
GlobalFlags is the global flags for the whole client.
var CmdGlobalFlags GlobalFlags
CmdGlobalFlags is the singleton of GlobalFlags.
func (*GlobalFlags) DefaultFormat ¶
func (g *GlobalFlags) DefaultFormat() bool
DefaultFormat is the default output format.
type NamedAuthInfo ¶
NamedAuthInfo is the user with name.
type NamedCluster ¶
NamedCluster is the cluster with name.
type NamedContext ¶
NamedContext is the context with name.
type SpecVisitor ¶
SpecVisitor walk through multiple specs
func BuildSpecVisitor ¶
func BuildSpecVisitor(yamlFile string, cmd *cobra.Command) SpecVisitor
BuildSpecVisitor builds a SpecVisitor
type YAMLVisitor ¶
YAMLVisitor walk through multiple YAML documents
func BuildYAMLVisitor ¶
func BuildYAMLVisitor(yamlFile string, cmd *cobra.Command) YAMLVisitor
BuildYAMLVisitor builds a YAMLVisitor