client

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: Apache-2.0 Imports: 16 Imported by: 68

README

Akamai Client

A golang package which helps facilitate making HTTP requests to Akamai OPEN APIs

Documentation

Overview

Package client is a simple library for http.Client to sign Akamai OPEN Edgegrid API requests

Index

Constants

This section is empty.

Variables

View Source
var (

	// UserAgent is the User-Agent value sent for all requests
	UserAgent = "Akamai-Open-Edgegrid-golang/" + libraryVersion + " golang/" + strings.TrimPrefix(runtime.Version(), "go")
	// Client is the *http.Client to use
	Client = http.DefaultClient
)

Functions

func BodyJSON

func BodyJSON(r *http.Response, data interface{}) error

BodyJSON unmarshals the Response.Body into a given data structure

func Do

func Do(config edgegrid.Config, req *http.Request) (*http.Response, error)

Do performs a given HTTP Request, signed with the Akamai OPEN Edgegrid Authorization header. An edgegrid.Response or an error is returned.

func IsClientError

func IsClientError(r *http.Response) bool

IsClientError determines if a response was a client error (4XX status)

func IsError

func IsError(r *http.Response) bool

IsError determines if the response was a client or server error (4XX or 5XX status)

func IsInformational

func IsInformational(r *http.Response) bool

IsInformational determines if a response was informational (1XX status)

func IsRedirection

func IsRedirection(r *http.Response) bool

IsRedirection determines if a response was a redirect (3XX status)

func IsServerError

func IsServerError(r *http.Response) bool

IsServerError determines if a response was a server error (5XX status)

func IsSuccess

func IsSuccess(r *http.Response) bool

IsSuccess determines if a response was successful (2XX status)

func NewJSONRequest

func NewJSONRequest(config edgegrid.Config, method, path string, body interface{}) (*http.Request, error)

NewJSONRequest creates an HTTP request that can be sent to the Akamai APIs with a JSON body The JSON body is encoded and the Content-Type/Accept headers are set automatically.

func NewMultiPartFormDataRequest added in v0.7.0

func NewMultiPartFormDataRequest(config edgegrid.Config, uriPath, filePath string, otherFormParams map[string]string) (*http.Request, error)

NewMultiPartFormDataRequest creates an HTTP request that uploads a file to the Akamai API

func NewRequest

func NewRequest(config edgegrid.Config, method, path string, body io.Reader) (*http.Request, error)

NewRequest creates an HTTP request that can be sent to Akamai APIs. A relative URL can be provided in path, which will be resolved to the Host specified in Config. If body is specified, it will be sent as the request body.

Types

type APIError

type APIError struct {
	Type        string           `json:"type"`
	Title       string           `json:"title"`
	Status      int              `json:"status"`
	Detail      string           `json:"detail"`
	Errors      []APIErrorDetail `json:"errors"`
	Problems    []APIErrorDetail `json:"problems"`
	Instance    string           `json:"instance"`
	Method      string           `json:"method"`
	ServerIP    string           `json:"serverIp"`
	ClientIP    string           `json:"clientIp"`
	RequestID   string           `json:"requestId"`
	RequestTime string           `json:"requestTime"`
	Response    *http.Response   `json:"-"`
	RawBody     string           `json:"-"`
	// contains filtered or unexported fields
}

APIError exposes an Akamai OPEN Edgegrid Error

func NewAPIError

func NewAPIError(response *http.Response) APIError

NewAPIError creates a new API error based on a Response, or http.Response-like.

func NewAPIErrorFromBody

func NewAPIErrorFromBody(response *http.Response, body []byte) APIError

NewAPIErrorFromBody creates a new API error, allowing you to pass in a body

This function is intended to be used after the body has already been read for other purposes.

func (APIError) Error

func (error APIError) Error() string

type APIErrorDetail added in v0.7.0

type APIErrorDetail struct {
	Type          string `json:"type"`
	Title         string `json:"title"`
	Detail        string `json:"detail"`
	RejectedValue string `json:"rejectedValue"`
}

type JSONBody

type JSONBody map[string]interface{}

JSONBody is a generic struct for temporary JSON unmarshalling.

type Resource

type Resource struct {
	Complete chan bool `json:"-"`
}

Resource is the "base" type for all API resources

func (*Resource) GetJSON

func (resource *Resource) GetJSON() ([]byte, error)

GetJSON returns the raw (indented) JSON (as []bytes)

func (*Resource) Init

func (resource *Resource) Init()

Init initializes the Complete channel, if it is necessary need to create a resource specific Init(), make sure to initialize the channel.

func (*Resource) PostUnmarshalJSON

func (resource *Resource) PostUnmarshalJSON() error

PostUnmarshalJSON is a default implementation of the PostUnmarshalJSON hook that simply calls Init() and sends true to the Complete channel. This is overridden in many resources, in particular those that represent collections, and have to initialize sub-resources also.

Jump to

Keyboard shortcuts

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