Documentation ¶
Overview ¶
Package client provide HTTP client to interract with Clever Cloud API
Index ¶
- Constants
- func WithAutoOauthConfig() func(*Client)
- func WithEndpoint(endpoint string) func(*Client)
- func WithHTTPClient(httpClient *http.Client) func(*Client)
- func WithLogger(logger logrus.FieldLogger) func(*Client)
- func WithOauthConfig(consumerKey, consumerSecret, accessToken, accessSecret string) func(*Client)
- func WithUserOauthConfig(accessToken, accessSecret string) func(*Client)
- type Authenticator
- type Client
- type Nothing
- type OAuth1Config
- type Response
- func Delete[T any](ctx context.Context, c *Client, path string) Response[T]
- func Get[T any](ctx context.Context, c *Client, path string) Response[T]
- func Patch[T any](ctx context.Context, c *Client, path string, payload interface{}) Response[T]
- func Post[T any](ctx context.Context, c *Client, path string, payload interface{}) Response[T]
- func Put[T any](ctx context.Context, c *Client, path string, payload interface{}) Response[T]
- type StreamEvent
- type StreamResponse
Examples ¶
Constants ¶
View Source
const API_ENDPOINT = "https://api.clever-cloud.com"
View Source
const CLIENT_VERSION = "v0.0.1"
View Source
const CONFIG_DIR = "clever-cloud"
For XDG.
View Source
const CONFIG_FILE_NAME = "clever-tools.json"
View Source
const NONCE_SIZE = 48
View Source
const OAUTH_CONSUMER_KEY = "FuRiWZChVFuYaVh04yCHYOnFRtzfHO"
View Source
const OAUTH_CONSUMER_SECRET = "J9k249yV0UqIzsGJWAVD4p1HLj8NyE" // #nosec G101
Variables ¶
This section is empty.
Functions ¶
func WithAutoOauthConfig ¶
func WithAutoOauthConfig() func(*Client)
Set OAuth1 credentials from environment, default: none.
func WithEndpoint ¶
Set API endoint, default: API_ENDPOINT.
func WithHTTPClient ¶
Set custom http client, default: http.DefaultClient.
func WithLogger ¶
func WithLogger(logger logrus.FieldLogger) func(*Client)
Set a logger, default: discard.
func WithOauthConfig ¶
Set OAuth1 credentials, default: none.
func WithUserOauthConfig ¶
Set OAuth1 user credentials, default: none.
Types ¶
type Authenticator ¶
type Authenticator interface { // Add authentication stuff on an HTTP request Sign(req *http.Request) // Return current user credentials (oauth1 user token, oauth1 user secret) Oauth1UserCredentials() (string, string) }
Authenticator is called to authenticate an HTTP request.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapped HTTP client used to contact CleverCloud API.
func (*Client) Oauth1UserCredentials ¶ added in v0.0.7
type OAuth1Config ¶
type OAuth1Config struct { ConsumerKey string `json:"-"` ConsumerSecret string `json:"-"` AccessToken string `json:"token"` AccessSecret string `json:"secret"` }
OAuth1Config own credentials to contact CleverCloud API.
func (OAuth1Config) Oauth1UserCredentials ¶ added in v0.0.7
func (auth OAuth1Config) Oauth1UserCredentials() (string, string)
func (*OAuth1Config) Sign ¶
func (auth *OAuth1Config) Sign(req *http.Request)
Sign an HTTP request with the given OAuth1 signature.
type Response ¶
type Response[T any] interface { Error() error HasError() bool StatusCode() int IsNotFoundError() bool SozuID() string Equal(anotherResponse Response[T]) bool Payload() *T }
func Get ¶
Perform a GET request.
Example ¶
Simple Get.
package main import ( "context" "fmt" "go.clever-cloud.dev/client" ) func main() { cc := client.New(client.WithAutoOauthConfig()) res := client.Get[map[string]interface{}](context.Background(), cc, "/v2/self") if res.HasError() { panic(res.Error()) } fmt.Printf("%+v\n", res.Payload()) }
Output:
type StreamEvent ¶
func (*StreamEvent[T]) String ¶
func (se *StreamEvent[T]) String() string
type StreamResponse ¶
type StreamResponse[T any] interface { Error() error HasError() bool StatusCode() int IsNotFoundError() bool SozuID() string Equal(anotherResponse StreamResponse[T]) bool Close() Payload() <-chan *StreamEvent[T] }
func Stream ¶
Perform an SSE request.
Example ¶
SSE.
package main import ( "context" "fmt" "go.clever-cloud.dev/client" ) func main() { type logEntry map[string]interface{} cc := client.New(client.WithAutoOauthConfig()) res := client.Stream[logEntry](context.Background(), cc, "/v4/logs") defer res.Close() for msg := range res.Payload() { fmt.Printf("%+v\n", msg) } }
Output:
Click to show internal directories.
Click to hide internal directories.