api

package
v0.0.0-...-c818f1a Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2015 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package api implements an HTTP-based API and server for CF-SSL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessRequestFirstMatchOf

func ProcessRequestFirstMatchOf(r *http.Request, keywordSets [][]string) (map[string]string, []string, error)

ProcessRequestFirstMatchOf reads a JSON blob for the request and returns the first match of a set of keywords. For example, a request might have one of the following combinations: (foo=1, bar=2), (foo=1), and (bar=2) By giving a specific ordering of those combinations, we could decide how to accept the request.

func ProcessRequestOneOf

func ProcessRequestOneOf(r *http.Request, keywordSets [][]string) (map[string]string, []string, error)

ProcessRequestOneOf reads a JSON blob for the request and makes sure it contains one of a set of keywords. For example, a request might have the ('foo' && 'bar') keys, OR it might have the 'baz' key. In either case, we want to accept the request; however, if none of these sets shows up, the request is a bad request, and it should be returned.

func SendResponse

func SendResponse(w http.ResponseWriter, result interface{}) error

SendResponse builds a response from the result, sets the JSON header, and writes to the http.ResponseWriter.

Types

type HTTPHandler

type HTTPHandler struct {
	Handler        // CFSSL handler
	Method  string // The assoicated HTTP method
}

HTTPHandler is a wrapper that encapsulates Handler interface as http.Handler. HttpHandler also enforces that the Handler only responds to requests with registered HTTP method.

func (HTTPHandler) ServeHTTP

func (h HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP encapsulates the call to underlying Handler to handle the request and return the response with proper HTTP status code

type Handler

type Handler interface {
	Handle(w http.ResponseWriter, r *http.Request) error
}

Handler is an interface providing a generic mechanism for handling HTTP requests.

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

HandlerFunc is similar to the http.HandlerFunc type; it serves as an adapter allowing the use of ordinary functions as Handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(w http.ResponseWriter, r *http.Request) error

Handle calls f(w, r)

type Response

type Response struct {
	Success  bool              `json:"success"`
	Result   interface{}       `json:"result"`
	Errors   []ResponseMessage `json:"errors"`
	Messages []ResponseMessage `json:"messages"`
}

Response implements the CloudFlare standard for API responses. CFSSL does not currently use the messages field, but it is provided for compatability.

func NewErrorResponse

func NewErrorResponse(message string, code int) Response

NewErrorResponse is a shortcut for creating an error response for a single error.

func NewSuccessResponse

func NewSuccessResponse(result interface{}) Response

NewSuccessResponse is a shortcut for creating new successul API responses. CFSSL does not use the messages field, but it is provided to conform to the CloudFlare standard.

type ResponseMessage

type ResponseMessage struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ResponseMessage implements the standard for response errors and messages. A message has a code and a string message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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