k

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

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

Go to latest
Published: Jul 20, 2013 License: BSD-3-Clause Imports: 17 Imported by: 0

README

Package k(atalysator) is a bag of small, uncategorized code supposed to ease the development of applications in go.

It would be tedious to maintain an overview in this README. For details, please consult the included documentation.


Version 0.7.2

Documentation

Overview

Package k(atalysator) is a bag of small, uncategorized code supposed to ease the development of applications in go.

As a side-effect, import package k will change the log package’s default flag to log.LstdFlags | log.Lshortfile.

Index

Constants

View Source
const (
	// Per default items up to 20 Mibibytes in size will be cached
	DEFAULT_MAX_CACHEABLE_SIZE = 20 * (1 << (10 * 2))
)
View Source
const (
	VERSION = "0.7.2"
)

Variables

This section is empty.

Functions

func DefaultEnv

func DefaultEnv(key, def string) string

DefaultEnv returns the value of an environment variable, provided it has been set. If it is unset (i.e. empty), the specified default value is returned.

func HTTPLogger

func HTTPLogger(h http.Handler, logFunc HTTPLoggerFunc) http.Handler

HTTPLogger wraps an http.Handler and calls a function logFunc with a line that can be written to an HTTP access log when a request to the handler has been completed.

func Hostname

func Hostname(def string) string

Hostname returns def if no hostname could be determined for this machine, the machine's hostname otherwise.

func JsonRemarshal

func JsonRemarshal(new interface{}, old interface{}) error

JsonRemarshal takes old, marshals it into json and unmarshals it into new. If an error occurs along the way, it is returned.

func MustBytes

func MustBytes(data []byte, err error) []byte

MustBytes is a function which usually wraps functions which return a byte slice and an error. It panics, if the given error is not nil.

func MustTCPAddr

func MustTCPAddr(rawaddr string) *net.TCPAddr

MustTCPAddr calls net.ResolveTCPAddr and panics if it returns a non-nil error.

func MustURL

func MustURL(rawurl string) *url.URL

MustURL calls net/url.Parse() and panics if it returns a non-nil error.

func NewSingleHostReverseProxy

func NewSingleHostReverseProxy(url *url.URL) *httputil.ReverseProxy

NewSingleHostReverseProxy is an augmentation of `net/http/httputil.NewSingleHostReverseProxy` which additionally sets the `Host` header.

func RandomString

func RandomString(n int) string

RandomString generates a random alpha-numeric string of length n

Types

type Cache

type Cache struct {
	// Time for which a answer is held im memory. A TTL <= 0
	// makes the Cache pass all requests directly to the handler.
	TTL time.Duration
	// Handler, whose responses are supposed to be cached
	Handler http.Handler
	// Maximum number of bytes, with which an response is eligible
	// for caching (default: 20MiB)
	MaxCacheableSize int64
	// contains filtered or unexported fields
}

Cache is a `net/http.Handler`, which uses `net/http/httptest.ResponseRecorder` to record and recall the responses of the wrapped handler from memory if the same URL is requested again. The `net/http.Request.URL.Path` is used as the caching key.

func NewCache

func NewCache(d time.Duration, handler http.Handler) *Cache

NewCache returns a new Cache, which records the responses of the given handler for the given duration.

func (*Cache) ServeHTTP

func (ch *Cache) ServeHTTP(w http.ResponseWriter, r *http.Request)

type GridDir

type GridDir struct {
	GridFS *mgo.GridFS
	// If true, the leading slash will be stripped from requests
	StripSlash bool
}

GridDir implements net/http.FileSystem to serve contents directly from MongoDB's GridFS.

To serve all files from a database containing a GridFS called `fs` via http:

session, err := mgo.Dial("mongodb://localhost/database")
if err != nil {
    log.Fatalf("Could not connect to mongodb: %s", err)
}
gfs := session.DB("").GridFS("fs")
http.Handle("/", http.FileServer(sabercat.GridDir{gfs})

Directory listing has not been implemented.

func (GridDir) Open

func (gd GridDir) Open(filename string) (http.File, error)

Tries to open a file with the corresponding GridFS path. If the connection to the server broke, a single retry is issued.

type HTTPLoggerFunc

type HTTPLoggerFunc func(logLine string)

type StringArray

type StringArray []string

StringArray is an alias for an array of strings which has common operations defined as methods.

func (StringArray) Contains

func (s StringArray) Contains(needle string) bool

Contains returns true if the receiver array contains an element equivalent to needle.

func (StringArray) String

func (s StringArray) String() string

String returns the JSON representation of the array.

Directories

Path Synopsis
package knsq (“knusk”) is a collection of helper and convenience functions for bitly’s nsq library.
package knsq (“knusk”) is a collection of helper and convenience functions for bitly’s nsq library.

Jump to

Keyboard shortcuts

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