ucloud

package
v0.15.1-0...-dc486a4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package ucloud is a package of utilities to setup ucloud sdk and improve using experience

Index

Constants

View Source
const Version = version.Version

Version is the version of sdk

Variables

View Source
var (
	String            = request.String
	StringValue       = request.StringValue
	Int               = request.Int
	IntValue          = request.IntValue
	Bool              = request.Bool
	BoolValue         = request.BoolValue
	Float64           = request.Float64
	Float64Value      = request.Float64Value
	TimeDuration      = request.TimeDuration
	TimeDurationValue = request.TimeDurationValue
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 客户端

func NewClient

func NewClient(config *Config, credential *auth.Credential) *Client

NewClient will create an client of ucloud sdk

func NewClientWithMeta

func NewClientWithMeta(config *Config, credential *auth.Credential, meta ClientMeta) *Client

func (*Client) AddHttpRequestHandler

func (c *Client) AddHttpRequestHandler(h HttpRequestHandler) error

AddHttpRequestHandler will append a response handler to client

func (*Client) AddHttpResponseHandler

func (c *Client) AddHttpResponseHandler(h HttpResponseHandler) error

AddHttpResponseHandler will append a http response handler to client

func (*Client) AddRequestHandler

func (c *Client) AddRequestHandler(h RequestHandler) error

AddRequestHandler will append a response handler to client

func (*Client) AddResponseHandler

func (c *Client) AddResponseHandler(h ResponseHandler) error

AddResponseHandler will append a response handler to client

func (*Client) GenericInvoke

func (c *Client) GenericInvoke(req request.GenericRequest) (response.GenericResponse, error)

func (*Client) GetConfig

func (c *Client) GetConfig() *Config

GetConfig will return the config of client.

func (*Client) GetCredential

func (c *Client) GetCredential() *auth.Credential

GetCredential will return the credential config of client.

func (*Client) GetLogger

func (c *Client) GetLogger() log.Logger

GetLogger will set the logger of client

func (*Client) GetMeta

func (c *Client) GetMeta() ClientMeta

GetMeta will return the meta data of client.

func (*Client) InvokeAction

func (c *Client) InvokeAction(action string, req request.Common, resp response.Common) error

InvokeAction will do an action request from a request struct and set response value into res struct pointer

func (*Client) InvokeActionWithPatcher

func (c *Client) InvokeActionWithPatcher(action string, req request.Common, resp response.Common, patches ...utils.Patch) error

InvokeActionWithPatcher will invoke action by patchers

func (*Client) NewGenericRequest

func (c *Client) NewGenericRequest() request.GenericRequest

func (*Client) SetHttpClient

func (c *Client) SetHttpClient(httpClient http.Client) error

SetHttpClient will setup a http client

func (*Client) SetLogger

func (c *Client) SetLogger(logger log.Logger)

SetLogger will set the logger of client

func (*Client) SetupRequest

func (c *Client) SetupRequest(req request.Common) request.Common

SetupRequest will init request by client configuration

type ClientMeta

type ClientMeta struct {
	Product string
}

type Config

type Config struct {
	// Region is the region of backend service
	// See also <https://docs.ucloud.cn/api/summary/regionlist> ...
	Region string `default:""`

	// Zone is the zone of backend service
	// See also <https://docs.ucloud.cn/api/summary/regionlist> ...
	Zone string `default:""`

	// ProjectId is the unique identify of project, used for organize resources,
	// Most of resources should belong to a project.
	// Sub-Account must have an project id.
	// See also <https://docs.ucloud.cn/api/summary/get_project_list> ...
	ProjectId string `default:""`

	// BaseUrl is the url of backend api
	// See also <doc link> ...
	BaseUrl string `default:"https://api.ucloud.cn"`

	// UserAgent is an attribute for sdk client, used for distinguish who is using sdk.
	// See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
	// It will be appended to the end of sdk user-agent.
	// eg. "Terraform/0.10.1" -> "GO/1.9.1 GO-SDK/0.1.0 Terraform/0.10.1"
	// NOTE: it will conflict with the User-Agent of HTTPHeaders
	UserAgent string `default:""`

	// Timeout is timeout for every request.
	Timeout time.Duration `default:"30s"`

	// MaxRetries is the number of max retry times.
	// Set MaxRetries more than 0 to enable auto-retry for network and service availability problem
	// if auto-retry is enabled, it will enable default retry policy using exponential backoff.
	MaxRetries int `default:"0"`

	// LogLevel is equal to logrus level,
	// if logLevel not be set, use INFO level as default.
	LogLevel log.Level `default:"log.InfoLevel"`
	// contains filtered or unexported fields
}

Config is the config of ucloud sdk, use for setting up client

func NewConfig

func NewConfig() Config

NewConfig will return a new client config with default options.

func (*Config) GetActionLevel

func (c *Config) GetActionLevel(action string) log.Level

GetActionLevel will return the log level of action

func (*Config) SetActionLevel

func (c *Config) SetActionLevel(action string, level log.Level)

SetActionLevel will return the log level of action

type HttpRequestHandler

type HttpRequestHandler func(c *Client, req *http.HttpRequest) (*http.HttpRequest, error)

HttpRequestHandler receive http request and return a new http request

type HttpResponseHandler

type HttpResponseHandler func(c *Client, req *http.HttpRequest, resp *http.HttpResponse, err error) (*http.HttpResponse, error)

HttpResponseHandler receive http response and return a new http response

type RequestHandler

type RequestHandler func(c *Client, req request.Common) (request.Common, error)

RequestHandler receive request and write data into this request memory area

type ResponseHandler

type ResponseHandler func(c *Client, req request.Common, resp response.Common, err error) (response.Common, error)

ResponseHandler receive response and write data into this response memory area

type ServiceClient

type ServiceClient interface {
	AddRequestHandler(h RequestHandler) error
	AddResponseHandler(h ResponseHandler) error
	AddHttpRequestHandler(h HttpRequestHandler) error
	AddHttpResponseHandler(h HttpResponseHandler) error
}

Directories

Path Synopsis
Package auth is the credential utilities of sdk
Package auth is the credential utilities of sdk
Package uerr is the error definition of service and sdk
Package uerr is the error definition of service and sdk
helpers
waiter
Package waiter is a helper package use for waiting remote state is transformed into target state.
Package waiter is a helper package use for waiting remote state is transformed into target state.
Package log is the log utilities of sdk
Package log is the log utilities of sdk
Package request is the request of service
Package request is the request of service
Package response is the response of service
Package response is the response of service
utest

Jump to

Keyboard shortcuts

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