goutil

package module
v0.0.0-...-4f40efb Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2015 License: Apache-2.0 Imports: 28 Imported by: 0

README

useful utilities for http://golang.org/ and http://aws.amazon.com/

Documentation

Overview

various utilities for go-lang.

Index

Constants

View Source
const IsoFormat = "2006-01-02T15:04:05.000Z"
View Source
const SCRIPT = `` /* 913-byte string literal not displayed */
View Source
const (
	Version = "1.0"
)

Variables

This section is empty.

Functions

func Check

func Check(e error)

func DataUrl

func DataUrl(b []byte, mimeType string) string

func FormatApproxDuration

func FormatApproxDuration(dur time.Duration, terms int) string

only leading terms

func FormatDuration

func FormatDuration(dur time.Duration) string

format duration using integers only

func FormatIsoUtc

func FormatIsoUtc(t time.Time) string

formats a time as iso 8601 with IsoFormat

func InTimeRange

func InTimeRange(t, startInclusive, endExclusive time.Time) bool

func ListenAndServeTLS

func ListenAndServeTLS(srv *http.Server, certFile, keyFile []byte) error

adapted from go's net/http package, modified to work with bytes in memory instead of files on disk

func LoadZipData

func LoadZipData(path, url string) (*zip.Reader, error)

func Marshal

func Marshal(i interface{}) string

func MarshalIndent

func MarshalIndent(i interface{}) string

func NewToken

func NewToken(validity time.Duration, message, password string) string

func ParseIsoUtc

func ParseIsoUtc(t string) (time.Time, error)

parses a time as iso 8601 with IsoFormat

func PlatformInit

func PlatformInit()

generic platform init, taking full advantage of all cpu's

func Retry

func Retry(msg string, bs RetryStrategyInstance, f func() (interface{}, error)) (v interface{}, err error)

retries something, generically

func RunOptionalSSLRedirector

func RunOptionalSSLRedirector(port int, rf OptionalRedirectorFunc) error

func RunSSLRedirector

func RunSSLRedirector(port int, rf RedirectorFunc) error

redirects http to https; rf can be nil

func RunWeb

func RunWeb(handler http.Handler, port int, ssl SSLConfig, auth Authenticator) error

simple generic platform, with gzip handling

func SleepRand

func SleepRand(t time.Duration)

sleeps the given amount of time, and then some similarly scaled amount, randomly

func Timeout

func Timeout(f func() error, t time.Duration) (timedout bool, err error)

runs f and returns output or timeout with error (i.e., it's ok to call like "_,err := Timeout(...)" if you don't care which)

Types

type Authenticator

type Authenticator func(w http.ResponseWriter, r *http.Request) bool

returns whether request is authenticated or not, and if not, optionally uses w to aid authentication

type Authorizer

type Authorizer func(r *http.Request) bool

type BufferReader

type BufferReader struct {
	Buffer *bytes.Buffer
}

func (BufferReader) Close

func (b BufferReader) Close() error

func (BufferReader) Read

func (b BufferReader) Read(p []byte) (n int, err error)

type BufferReaderFact

type BufferReaderFact struct {
	Buffer []byte
}

func (BufferReaderFact) CreateReader

func (b BufferReaderFact) CreateReader() (io.ReadCloser, error)

func (BufferReaderFact) Len

func (b BufferReaderFact) Len() int

type DurationList

type DurationList []time.Duration

func (DurationList) Len

func (r DurationList) Len() int

func (DurationList) Less

func (r DurationList) Less(i, j int) bool

func (DurationList) Swap

func (r DurationList) Swap(i, j int)

type FileReaderFact

type FileReaderFact struct {
	Path   string
	Length int
}

func NewFileReaderFact

func NewFileReaderFact(path string) (*FileReaderFact, error)

func (FileReaderFact) CreateReader

func (rf FileReaderFact) CreateReader() (io.ReadCloser, error)

func (FileReaderFact) Len

func (rf FileReaderFact) Len() int

type Filter

type Filter interface {
	Update(t time.Time, x float64) float64
}

func NewLowPass

func NewLowPass(tc time.Duration) Filter

type HttpAuth

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

func NewHttpAuth

func NewHttpAuth(realm string, handler http.Handler, auths ...Authorizer) *HttpAuth

func (*HttpAuth) Add

func (a *HttpAuth) Add(user, password string)

func (*HttpAuth) Authorized

func (a *HttpAuth) Authorized(r *http.Request) bool

func (*HttpAuth) ServeHTTP

func (s *HttpAuth) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HttpAuthMux

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

func NewHttpAuthMux

func NewHttpAuthMux(realm string) *HttpAuthMux

func (*HttpAuthMux) Add

func (a *HttpAuthMux) Add(user, password string)

func (*HttpAuthMux) Authorized

func (a *HttpAuthMux) Authorized(r *http.Request) bool

func (*HttpAuthMux) Handle

func (s *HttpAuthMux) Handle(pattern string, handler http.Handler)

func (*HttpAuthMux) HandleFunc

func (s *HttpAuthMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*HttpAuthMux) ServeHTTP

func (s *HttpAuthMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Json

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

func NewJson

func NewJson(b []byte) (*Json, error)

func WrapJson

func WrapJson(i interface{}) *Json

func (*Json) AsArray

func (j *Json) AsArray() ([]interface{}, error)

func (*Json) AsBool

func (j *Json) AsBool() (bool, error)

func (*Json) AsFloat64

func (j *Json) AsFloat64() (float64, error)

func (*Json) AsInt

func (j *Json) AsInt() (int, error)

func (*Json) AsMap

func (j *Json) AsMap() (map[string]interface{}, error)

func (*Json) AsString

func (j *Json) AsString() (string, error)

func (*Json) Float64Array

func (j *Json) Float64Array() ([]float64, error)

func (*Json) Get

func (j *Json) Get(key string) *Json

func (*Json) GetIndex

func (j *Json) GetIndex(index int) *Json

func (*Json) GetPath

func (j *Json) GetPath(branch ...string) *Json

func (*Json) MarshalJSON

func (j *Json) MarshalJSON() ([]byte, error)

func (*Json) Set

func (j *Json) Set(key string, val interface{})

func (*Json) String

func (j *Json) String() string

func (*Json) StringArray

func (j *Json) StringArray() ([]string, error)

func (*Json) UnmarshalJSON

func (j *Json) UnmarshalJSON(b []byte) error

func (*Json) Unwrap

func (j *Json) Unwrap() interface{}

type KeyValueF

type KeyValueF struct {
	Key   string
	Value float64
}

type KeyValueI

type KeyValueI struct {
	Key   string
	Value int
}

type KeyValueII

type KeyValueII struct {
	Key   int
	Value int
}

type KeyValueListF

type KeyValueListF []KeyValueF

func (KeyValueListF) Len

func (k KeyValueListF) Len() int

func (KeyValueListF) Less

func (k KeyValueListF) Less(i, j int) bool

func (KeyValueListF) Swap

func (k KeyValueListF) Swap(i, j int)

type KeyValueListI

type KeyValueListI []KeyValueI

func (KeyValueListI) Len

func (k KeyValueListI) Len() int

func (KeyValueListI) Less

func (k KeyValueListI) Less(i, j int) bool

func (KeyValueListI) Swap

func (k KeyValueListI) Swap(i, j int)

type KeyValueListII

type KeyValueListII []KeyValueII

func (KeyValueListII) Len

func (k KeyValueListII) Len() int

func (KeyValueListII) Less

func (k KeyValueListII) Less(i, j int) bool

func (KeyValueListII) Swap

func (k KeyValueListII) Swap(i, j int)

type LowPass

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

func (*LowPass) Update

func (f *LowPass) Update(t time.Time, x float64) float64

type NoRetryStrategy

type NoRetryStrategy struct {
}

func (NoRetryStrategy) NewInstance

func (NoRetryStrategy) NewInstance() RetryStrategyInstance

type NoRetryStrategyInstance

type NoRetryStrategyInstance struct {
}

func (NoRetryStrategyInstance) Retry

func (NoRetryStrategyInstance) Retry() bool

type OptionalRedirector

type OptionalRedirector struct {
	Transformer OptionalRedirectorFunc
}

func (OptionalRedirector) ServeHTTP

func (f OptionalRedirector) ServeHTTP(w http.ResponseWriter, r *http.Request)

type OptionalRedirectorFunc

type OptionalRedirectorFunc func(w http.ResponseWriter, r *http.Request) (handled bool, redirect string)

type RateEstimator

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

func NewRateEstimator

func NewRateEstimator(tc time.Duration) *RateEstimator

func (*RateEstimator) Count

func (re *RateEstimator) Count() int

func (*RateEstimator) Rate

func (re *RateEstimator) Rate() float64

func (*RateEstimator) Update

func (re *RateEstimator) Update() float64

updates and return Rate()

type ReadCloser

type ReadCloser struct {
	io.Reader
}

func (ReadCloser) Close

func (r ReadCloser) Close() error

type ReaderFactory

type ReaderFactory interface {
	CreateReader() (io.ReadCloser, error)
	Len() int
}

func NewSingleReaderFact

func NewSingleReaderFact(r io.Reader, length int) ReaderFactory

type Redirector

type Redirector struct {
	Transformer RedirectorFunc
}

func (Redirector) ServeHTTP

func (f Redirector) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RedirectorFunc

type RedirectorFunc func(r *http.Request) string

if returned string is length zero, don't use

type Replicator

type Replicator struct {
}

func (Replicator) Name

func (Replicator) Name() string

func (Replicator) Run

func (r Replicator) Run(args []string)

type RetryBackoffStrat

type RetryBackoffStrat struct {
	Delay         time.Duration
	Retries       int
	BackoffFactor float64
}

func (RetryBackoffStrat) NewInstance

func (r RetryBackoffStrat) NewInstance() RetryStrategyInstance

type RetryBackoffStratInstance

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

func (*RetryBackoffStratInstance) Retry

func (r *RetryBackoffStratInstance) Retry() bool

type RetryStrategy

type RetryStrategy interface {
	NewInstance() RetryStrategyInstance
}

e.g., can combine retry logic and backoff in time together, or any other strategy

type RetryStrategyInstance

type RetryStrategyInstance interface {
	// returns whether or not to retry, backing off in time if it likes
	Retry() bool
}

type SSLConfig

type SSLConfig func() (cert interface{}, key interface{})

returns either cert/key files or bytes, or nulls if ssl not needed

type TestJson

type TestJson struct {
}

func (TestJson) Name

func (TestJson) Name() string

func (TestJson) Run

func (TestJson) Run(args []string)

type Tester

type Tester struct {
}

func (Tester) Name

func (Tester) Name() string

func (Tester) Run

func (t Tester) Run(args []string)

type TimeList

type TimeList []time.Time

func (TimeList) Len

func (r TimeList) Len() int

func (TimeList) Less

func (r TimeList) Less(i, j int) bool

func (TimeList) Swap

func (r TimeList) Swap(i, j int)

type Token

type Token struct {
	Mac     []byte    `json:"M,omitempty"`
	From    time.Time `json:"F,omitempty"`
	To      time.Time `json:"T,omitempty"`
	Message string    `json:"P,omitempty"`
}

func DecodeToken

func DecodeToken(tok, password string) (bool, *Token, error)

returns whether or not token is valid, and decoded token

type Tool

type Tool struct {
}

func (Tool) Name

func (Tool) Name() string

func (Tool) Run

func (t Tool) Run(args []string)

type WorkQueue

type WorkQueue interface {
	WorkSubmitter
	// close queue and wait for all functions to execute
	Wait()
}

func NewWorkQueue

func NewWorkQueue(n int) WorkQueue

type WorkSubmitter

type WorkSubmitter interface {
	// submit a function to queue
	Submit(f func())
}

Directories

Path Synopsis
aws
aws utilities.
aws utilities.
ddb
code for accessing dynamo db.
code for accessing dynamo db.
s3
code for accessing s3.
code for accessing s3.
code for elastic mapreduce (streaming).
code for elastic mapreduce (streaming).
runs a tool forever
runs a tool forever
work with git
work with git
math code.
math code.
blas
interface to Basic Linear Algebra Subprograms (blas).
interface to Basic Linear Algebra Subprograms (blas).
la
linear algebra routines.
linear algebra routines.
lapack
interface to Linear Algebra PACKage (lapack).
interface to Linear Algebra PACKage (lapack).
model
modelling routines.
modelling routines.
model/cancer
use modelling code on well-known prostate cancer data, check we get same results.
use modelling code on well-known prostate cancer data, check we get same results.
model/logistic
logistic modelling example.
logistic modelling example.
stats
various statistical routines.
various statistical routines.
logging for the purposes of analysis later on.
logging for the purposes of analysis later on.
parallel boosting
parallel boosting
rate-limited reader.
rate-limited reader.
idempotently prepends bin directory to current PATH and prints; e.g., export PATH=`go run src/github.com/xoba/goutil/setpath/setpath.go`
idempotently prepends bin directory to current PATH and prints; e.g., export PATH=`go run src/github.com/xoba/goutil/setpath/setpath.go`
simple smtp client.
simple smtp client.
manages main executable as agglomeration of tools.
manages main executable as agglomeration of tools.

Jump to

Keyboard shortcuts

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