Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultServerURL(host, apiPath string, groupVersion scheme.GroupVersion, defaultTLS bool) (*url.URL, string, error)
- func DefaultUserAgent() string
- func IsValidPathSegmentName(name string) []string
- func LoadTLSFiles(c *Config) error
- func SetSKTDefaults(config *Config) error
- func TLSConfigFor(c *Config) (*tls.Config, error)
- type ClientContentConfig
- type Config
- type ContentConfig
- type Interface
- type RESTClient
- type Request
- func (r *Request) AbsPath(segments ...string) *Request
- func (r *Request) Body(obj interface{}) *Request
- func (r *Request) Do(ctx context.Context) Result
- func (r *Request) Name(resourceName string) *Request
- func (r *Request) Resource(resource string) *Request
- func (r *Request) SetHeader(key string, values ...string) *Request
- func (r *Request) URL() *url.URL
- func (r *Request) Verb(verb string) *Request
- type Result
- type TLSClientConfig
Constants ¶
View Source
const UNKNOWN = "unknown"
Variables ¶
View Source
var NameMayNotBe = []string{".", ".."}
View Source
var NameMayNotContain = []string{"/", "%"}
Functions ¶
func DefaultServerURL ¶
func DefaultUserAgent ¶
func DefaultUserAgent() string
func IsValidPathSegmentName ¶
func LoadTLSFiles ¶
LoadTLSFiles 将数据从 CertFile、KeyFile 和 CAFile 复制到 CertData、KeyData 和 CAFile 中,或返回错误.
func SetSKTDefaults ¶
Types ¶
type ClientContentConfig ¶
type ClientContentConfig struct { Username string Password string SecretID string SecretKey string BearerToken string BearerTokenFile string TLSClientConfig AcceptContentTypes string ContentType string GroupVersion scheme.GroupVersion Negotiator runtime.ClientNegotiator }
ClientContentConfig 控制 RESTClient 与服务器的通信方式.
func (*ClientContentConfig) HasBasicAuth ¶
func (c *ClientContentConfig) HasBasicAuth() bool
HasBasicAuth 返回配置是否具有 Basic 身份验证.
func (*ClientContentConfig) HasKeyAuth ¶
func (c *ClientContentConfig) HasKeyAuth() bool
HasKeyAuth 返回配置是否具有 secretId/secretKey 身份验证.
func (*ClientContentConfig) HasTokenAuth ¶
func (c *ClientContentConfig) HasTokenAuth() bool
HasTokenAuth 返回配置是否具有 Token 身份验证.
type Config ¶
type Config struct { Host string APIPath string ContentConfig // Server requires Basic authentication Username string Password string SecretID string SecretKey string // Server requires Bearer authentication. This client will not attempt to use // refresh tokens for an OAuth2 flow. // TODO: demonstrate an OAuth2 compatible client. BearerToken string // Path to a file containing a BearerToken. // If set, the contents are periodically read. // The last successfully read value takes precedence over BearerToken. BearerTokenFile string // TLSClientConfig contains settings to enable transport layer security TLSClientConfig // UserAgent is an optional field that specifies the caller of this request. UserAgent string // The maximum length of time to wait before giving up on a server request. A value of zero means no timeout. Timeout time.Duration MaxRetries int RetryInterval time.Duration }
Config 包含可以在初始化时传递给 SKT 客户端的通用属性.
type ContentConfig ¶
type ContentConfig struct { ServiceName string AcceptContentTypes string ContentType string GroupVersion *scheme.GroupVersion Negotiator runtime.ClientNegotiator }
type Interface ¶
type Interface interface { Verb(verb string) *Request Post() *Request Put() *Request Get() *Request Delete() *Request APIVersion() scheme.GroupVersion }
Interface 定义了和 SKT API 的全部交互方法.
type RESTClient ¶
type RESTClient struct { Client *gorequest.SuperAgent // Client 是通用的请求对象 // contains filtered or unexported fields }
RESTClient 是执行通用 REST 请求的 Client.
func NewRESTClient ¶
func NewRESTClient(baseURL *url.URL, versionedAPIPath string, config ClientContentConfig, client *gorequest.SuperAgent, ) (*RESTClient, error)
NewRESTClient 创建一个新的 RESTClient.
func RESTClientFor ¶
func RESTClientFor(config *Config) (*RESTClient, error)
func (*RESTClient) APIVersion ¶
func (c *RESTClient) APIVersion() scheme.GroupVersion
APIVersion 返回当前 RESTClient 期望使用的 API 版本.
func (*RESTClient) Delete ¶
func (c *RESTClient) Delete() *Request
func (*RESTClient) Get ¶
func (c *RESTClient) Get() *Request
func (*RESTClient) Post ¶
func (c *RESTClient) Post() *Request
func (*RESTClient) Put ¶
func (c *RESTClient) Put() *Request
func (*RESTClient) Verb ¶
func (c *RESTClient) Verb(verb string) *Request
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result 包含调用 Request.Do() 的返回结果.
type TLSClientConfig ¶
type TLSClientConfig struct { // Server should be accessed without verifying the TLS certificate. For testing only. Insecure bool // ServerName is passed to the server for SNI and is used in the client to check server // ceritificates against. If ServerName is empty, the hostname used to contact the // server is used. ServerName string // Server requires TLS client certificate authentication CertFile string // Server requires TLS client certificate authentication KeyFile string // Trusted root certificates for server CAFile string // CertData holds PEM-encoded bytes (typically read from a client certificate file). // CertData takes precedence over CertFile CertData []byte // KeyData holds PEM-encoded bytes (typically read from a client certificate key file). // KeyData takes precedence over KeyFile KeyData []byte // CAData holds PEM-encoded bytes (typically read from a root certificates bundle). // CAData takes precedence over CAFile CAData []byte // NextProtos is a list of supported application level protocols, in order of preference. // Used to populate tls.Config.NextProtos. // To indicate to the server http/1.1 is preferred over http/2, set to ["http/1.1", "h2"] (though the server is free // to ignore that preference). // To use only http/1.1, set to ["http/1.1"]. NextProtos []string }
TLSClientConfig 包含启用传输层安全的设置.
func (TLSClientConfig) HasCertAuth ¶
func (c TLSClientConfig) HasCertAuth() bool
HasCertAuth 返回配置是否具有证书身份验证.
Click to show internal directories.
Click to hide internal directories.