Documentation
¶
Index ¶
- type ApiKey
- func (k *ApiKey) Delete(url string) ([]byte, error)
- func (k *ApiKey) Get(url string) ([]byte, error)
- func (k *ApiKey) Post(url, contentType string, body io.Reader) ([]byte, error)
- func (k *ApiKey) Put(url string, contentType string, body io.Reader) ([]byte, error)
- func (k *ApiKey) SetScopes(scope ...string)
- type Authenticator
- type ServiceAccount
- func (sa *ServiceAccount) Delete(url string) ([]byte, error)
- func (sa *ServiceAccount) Get(url string) ([]byte, error)
- func (sa *ServiceAccount) Name() string
- func (sa *ServiceAccount) Post(url, contentType string, body io.Reader) ([]byte, error)
- func (sa *ServiceAccount) Put(url string, contentType string, body io.Reader) ([]byte, error)
- func (sa *ServiceAccount) SetScopes(scope ...string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApiKey ¶
type ApiKey struct {
Key string
}
ApiKey uses an API key that authorize and authenticate the requests.
The API key is used in the `X-goog-api-key` header of the request.
See more: https://cloud.google.com/docs/authentication/api-keys-use#using-with-rest
func (*ApiKey) Delete ¶
Delete do a HTTP DELETE request with the API key is set in the `X-goog-api-key` header of the request.
Returns the body bytes.
If response status code is not 200, returns the body as a git.gotrbe.io/go/google/errors.Error.
func (*ApiKey) Get ¶
Get do a HTTP Get request with the API key is set in the `X-goog-api-key` header of the request.
Returns the body bytes.
If response status code is not 200, returns the body as a git.gotrbe.io/go/google/errors.Error.
func (*ApiKey) Post ¶
Post do a HTTP Post request with the API key is set in the `X-goog-api-key` header of the request.
Returns the body bytes.
If response status code is not 200, returns the body as a git.gotrbe.io/go/google/errors.Error.
func (*ApiKey) Put ¶
Put do a HTTP PUT request with the API key is set in the `X-goog-api-key` header of the request.
Returns the body bytes.
If response status code is not 204, returns the body as a git.gotrbe.io/go/google/errors.Error.
type Authenticator ¶
type Authenticator interface { // Get method should return the body bytes. // If the status code is not 200, then this method should return the body as [git.gorbe.io/go/google/errors.Error]. Get(url string) ([]byte, error) // Post method should return the body bytes. // If the status code is not 200, then this method should return the body as [git.gorbe.io/go/google/errors.Error]. Post(url, contentType string, body io.Reader) ([]byte, error) // Delete method should return the body bytes. // If the status code is not 200, then this method should return the body as [git.gorbe.io/go/google/errors.Error]. Delete(url string) ([]byte, error) // Put method should return the body bytes. // If the status code is not 200, then this method should return the body as [git.gorbe.io/go/google/errors.Error]. Put(url string, contentType string, body io.Reader) ([]byte, error) // SetScopes method sets the scope informations for OAuth2 authentication. // For ApiKey, this method do nothing. SetScopes(scope ...string) }
Authenticator is an interface that can do authenticated "GET" and "POST" requests.
type ServiceAccount ¶
type ServiceAccount struct { Email string `json:"client_email" yaml:"Email"` PrivateKey string `json:"private_key" yaml:"PrivateKey"` PrivateKeyID string `json:"private_key_id" yaml:"PrivateKeyID"` TokenURL string `json:"token_uri" yaml:"TokenURL"` Scopes []string `json:"scopes" yaml:"Scopes"` Subject string `json:"subject" yaml:"Subject"` }
ServiceAccount uses a Google Developers service account JSON key to read the credentials that authorize and authenticate the requests.
func ServiceAccountFromJSON ¶
func ServiceAccountFromJSON(data []byte) (*ServiceAccount, error)
ServiceAccountFromJSON uses a Google Developers service account JSON key to read the credentials that authorize and authenticate the requests.
func ServiceAccountFromJSONFile ¶
func ServiceAccountFromJSONFile(name string) (*ServiceAccount, error)
ServiceAccountFromJSONFile uses a Google Developers service account JSON key file in path name to read the credentials that authorize and authenticate the requests.
func (*ServiceAccount) Delete ¶
func (sa *ServiceAccount) Delete(url string) ([]byte, error)
Delete do a HTTP DELETE request with the credentials stored in *ServiceAccount.
Returns the body bytes.
If response status code is not 200, returns the body as a git.gotrbe.io/go/google/errors.Error.
func (*ServiceAccount) Get ¶
func (sa *ServiceAccount) Get(url string) ([]byte, error)
Get do a HTTP GET request with the credentials stored in *ServiceAccount.
Returns the body bytes.
If response status code is not 200, returns the body as a git.gotrbe.io/go/google/errors.Error.
func (*ServiceAccount) Name ¶
func (sa *ServiceAccount) Name() string
Name returns the username part of Email.
Example ¶
package main import ( "fmt" "git.gorbe.io/go/google/authentication" ) func main() { sa := new(authentication.ServiceAccount) sa.Email = "user0123@projectname-012345.iam.gserviceaccount.com" fmt.Printf("%s\n", sa.Name()) }
Output: user0123
func (*ServiceAccount) Post ¶
Post do a HTTP POST request with the credentials stored in *ServiceAccount.
Returns the body bytes.
If response status code is not 200, returns the body as a git.gotrbe.io/go/google/errors.Error.
func (*ServiceAccount) Put ¶
Put do a HTTP PUT request with the credentials stored in *ServiceAccount.
Returns the body bytes.
If response status code is not 204, returns the body as a git.gotrbe.io/go/google/errors.Error.
func (*ServiceAccount) SetScopes ¶
func (sa *ServiceAccount) SetScopes(scope ...string)
SetScopes sets the OAuth2 scope information.