requesthandling

package
v0.0.0-...-8247dfb Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2018 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package requesthandling offers means to create signed requests for interfacing with CloudKit.

A Configuration is required to know the CloudKit container's properties, the KeyManager is required for signing requests.

Index

Examples

Constants

View Source
const (
	// GET represents HTTP GET
	GET HTTPMethod = "GET"
	// POST represents HTTP POST
	POST = "POST"
	// PUT represents HTTP PUT
	PUT = "PUT"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudkitRequestManager

type CloudkitRequestManager struct {
	Config RequestConfig
	// contains filtered or unexported fields
}

CloudkitRequestManager is the concrete implementation of RequestManager

func New

New creates a new RequestManager

func (CloudkitRequestManager) GetRequest

func (cm CloudkitRequestManager) GetRequest(operationPath string, body string) (*http.Request, error)

GetRequest is a convenience method for creating POST requests

func (*CloudkitRequestManager) HashedBody

func (cm *CloudkitRequestManager) HashedBody(body string) string

HashedBody takes the given body, hashes it, using sha256 and returns the base64 encoded result

func (CloudkitRequestManager) PostRequest

func (cm CloudkitRequestManager) PostRequest(operationPath string, body string) (*http.Request, error)

PostRequest is a convenience method for creating POST requests

func (*CloudkitRequestManager) SignatureForMessage

func (cm *CloudkitRequestManager) SignatureForMessage(message []byte) (signature []byte)

SignatureForMessage returns the signature for the given message

type HTTPMethod

type HTTPMethod string

The HTTPMethod defines the method of a request

type Payload

type Payload struct {
	Fields map[string]interface{}
}

Payload represents the payload to send with a request

type RequestConfig

type RequestConfig struct {
	Version     string
	ContainerID string
	Database    string
}

RequestConfig is used to initialise RequestManagers. It specifies the Cloudkit API version and container ID to use for requests

func NewRequestConfig

func NewRequestConfig(version string, containerID string, database string) RequestConfig

NewRequestConfig creates a fresh config with the given version and container ID

type RequestManager

type RequestManager interface {
	PostRequest(string, string) (*http.Request, error)
	GetRequest(string, string) (*http.Request, error)
}

The RequestManager interface exposes methods for creating requests

Example

This Example shows how to create a request manager.

A request manager requires a keymanager for handling authentication as well as a valid configuration.

keyManager := mocks.MockKeyManager{}
config := RequestConfig{Version: "1", ContainerID: "iCloud.com.mycontainer", Database: "public"}
requestManager := New(config, &keyManager)
fmt.Printf("Container:%s, Version:%s, Database:%s",
	requestManager.Config.ContainerID,
	requestManager.Config.Version,
	requestManager.Config.Database)
Output:

Container:iCloud.com.mycontainer, Version:1, Database:public

Jump to

Keyboard shortcuts

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