gorion

package module
v0.0.0-...-bf2462a Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2015 License: Apache-2.0 Imports: 3 Imported by: 0

README

gorion

GoDoc

A Go client library for Iron.io services. This library provides interfaces that you can use in your code that have in-memory implementations that you can use in your code's unit tests. Currently supports a small subset of the IronMQ API.

Sample usage:

import (
  "github.com/arschles/gorion/mq"
  "golang.org/x/net/context"
)

// DoEnqueue enqueues some messages and returns all the message IDs of the new
// messages. Returns a non-nil error on any enqueue failure
func DoEnqueue(client mq.Client) ([]string, error) {
  enq, err := client.Enqueue(context.Background(), "myQueue", []NewMessage{
    {Body: "my first message", Delay: 0, PushHeaders: make(map[string]string)},
  })
  if err != nil {
    return nil, err
  }
  return enq.IDs, nil
}

Documentation

Overview

Package gorion is a Go client library for Iron.io (http://www.iron.io/) services. It provides interfaces (see the mq.Client for example) for use in your code and in-memory "stubs" for each interface that you can use in your code's unit tests.

Additionally, all interface funcs take a net.Context (http://godoc.org/golang.org/x/net/context) which your code can use to control timeouts, cancellation and more. See https://blog.golang.org/context for more information on how to use Contexts.

Gorion currently supports a small subset of the IronMQ API. See the mq package for more usage details.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCancelled is returned immediately when a func returns a net.Context that is
	// already cancelled.
	ErrCancelled = errors.New("cancelled")
)

Functions

func HTTPDo

func HTTPDo(ctx context.Context, client *http.Client, transport *http.Transport, req *http.Request, f func(*http.Response, error) error) error

HTTPDo runs the HTTP request in a goroutine and passes the response to f in that same goroutine. After the goroutine finishes, returns the result of f. If ctx.Done() receives before f returns, calls transport.CancelRequest(req) before before returning. Even though HTTPDo executes f in another goroutine, you can treat it as a synchronous call to f. Also, since HTTPDo uses client to run requests and transport to cancel them, client.Transport should be transport in most cases.

Example Usage:

type Resp struct { Num int `json:"num"` }
var resp *Resp
err := HttpDo(ctx, client, transport, req, func(resp *http.Response, err error) error {
  if err != nil { return err }
  defer resp.Body.Close()

  if err := json.NewDecoder(resp.Body).Decode(resp); err != nil {
    return err
  }
  return nil
})
if err != nil { return err }
// do something with resp...

This func was stolen/adapted from https://blog.golang.org/context

Types

This section is empty.

Directories

Path Synopsis
Package mq provides a Client interface for code that needs an IronMQ v3 (http://dev.iron.io/mq/3/reference/api/) client.
Package mq provides a Client interface for code that needs an IronMQ v3 (http://dev.iron.io/mq/3/reference/api/) client.

Jump to

Keyboard shortcuts

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