ephemeral

package module
v0.0.0-...-3d359b5 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2015 License: MIT Imports: 3 Imported by: 0

README

ephemeral

ephemeral is a lightweight library to fire an ephemeral Web server. It’s useful when you’re writing a CLI app which needs to authenticate against a remote server using a callback URI.

GoDoc Build Status

Usage

Ephemeral provides a small http-like API. Start by creating a server:

s := ephemeral.New()

Then declare your handler like you’d do with a classic HTTP server, except that it takes the server as its first argument:

s.HandleFunc("/", func(s *ephemeral.Server,
    w http.ResponseWriter, r *http.Request) {

    w.Write([]byte("Ok bye :)\n"))

    s.Stop("foo")
})

The server exposes a Stop method which takes one argument that can be whatever you want, including nil.

Start the server:

s.Listen(":8080")

The method won’t return until the server is stopped. It returns the argument you gave to the .Stop() call as well as an error.

Install

go get github.com/bfontaine/ephemeral

Documentation

Overview

Package ephemeral provides a way to create and stop an ephemeral Web server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequest

func GetRequest(host, path string) (*http.Request, error)

GetRequest is a shortcut function which creates an ephemeral Server, run it, and stops once it got one request, which it then returns.

Types

type Handler

type Handler func(*Server, http.ResponseWriter, *http.Request)

Handler represents the type of functions used as handlers with an ephemeral Server

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a wrapper for an ephemeral http.Server.

func New

func New() *Server

New returns a pointer on a new Server

func (*Server) HandleFunc

func (s *Server) HandleFunc(path string, fn Handler)

HandleFunc adds a new handler for a given path

func (*Server) Listen

func (s *Server) Listen(host string) (data interface{}, err error)

Listen works like http.ListenAndServe but returns the argument passed to Stop.

func (*Server) Stop

func (s *Server) Stop(data interface{})

Stop stops the server and use its argument as a return value for Listen.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/stretchr/testify/assert
A set of comprehensive testing tools for use with the normal Go testing system.
A set of comprehensive testing tools for use with the normal Go testing system.
_workspace/src/github.com/stretchr/testify/require
Alternative testing tools which stop test execution if test failed.
Alternative testing tools which stop test execution if test failed.

Jump to

Keyboard shortcuts

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