services

package
v0.0.0-...-c2f4907 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2016 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelOff    = LogLevel(0)
	LevelTrace  = LogLevel(5)
	LevelNormal = LogLevel(10)
	LevelWarn   = LogLevel(15)
)

Variables

View Source
var (
	LevelNames = map[LogLevel]string{
		LevelOff:    "  Off",
		LevelTrace:  "Trace",
		LevelNormal: "  Log",
		LevelWarn:   " Warn",
	}
)
View Source
var LockFailed = errors.New("Failed to acquire lock")
View Source
var (
	PrettyJson = true
)

Functions

func AsMap

func AsMap(obj interface{}) map[string]interface{}

func BoolBytes

func BoolBytes(value bool) []byte

func EnableResponseLogging

func EnableResponseLogging()

func EndpointLockValue

func EndpointLockValue(addr string) string

Return a string that is unique per client/endpoint. addr should contain service port.

func FillFromMap

func FillFromMap(values map[string]string, obj interface{}) error

func FloatBytes

func FloatBytes(value float64) []byte

func Http_application_error

func Http_application_error(w http.ResponseWriter, r *http.Request, err error)

func Http_check_response

func Http_check_response(resp *http.Response, err error, the_url string) ([]byte, error)

func Http_get_json

func Http_get_json(the_url string, result interface{}) error

func Http_get_json_map

func Http_get_json_map(the_url string, requiredKeys ...string) (map[string]interface{}, error)

func Http_json_map_response

func Http_json_map_response(_response *http.Response, err error, url string, requiredKeys ...string) (map[string]interface{}, error)

func Http_json_response

func Http_json_response(resp *http.Response, err error, url string, result interface{}) error

func Http_parse_json_response

func Http_parse_json_response(resp *http.Response, err error, url string) (interface{}, error)

func Http_post_string

func Http_post_string(the_url string, data url.Values) (string, error)

func Http_respond

func Http_respond(w http.ResponseWriter, r *http.Request, data []byte, code int)

func Http_respond_error

func Http_respond_error(w http.ResponseWriter, r *http.Request, err string, code int)

func Http_respond_json

func Http_respond_json(w http.ResponseWriter, r *http.Request, value interface{})

func Http_simple_post

func Http_simple_post(the_url string) error

func MakeHash

func MakeHash(data ...interface{}) string

func MakeHttpResponse

func MakeHttpResponse(req *http.Request, code int, bodyContent string) *http.Response

func MatchFormKeys

func MatchFormKeys(keys ...string) func(r *http.Request, rm *mux.RouteMatch) bool

func ParseBalanceEndpointsFlags

func ParseBalanceEndpointsFlags()

func ParseLoadBalanceConfig

func ParseLoadBalanceConfig()

func RegisterLockScripts

func RegisterLockScripts(client Redis) error

func UintBytes

func UintBytes(value uint64) []byte

Types

type HttpError

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

This is a way for the application to control the http response code, if the controller is willing to evaluate it

func Conflictf

func Conflictf(fmt_str string, val ...interface{}) HttpError

func HttpErrorf

func HttpErrorf(code int, fmt_str string, val ...interface{}) HttpError

func (HttpError) Error

func (err HttpError) Error() string

type HttpStatusError

type HttpStatusError struct {
	URL    string
	Body   string
	Code   int
	Status string
}

func (*HttpStatusError) Error

func (err *HttpStatusError) Error() string

type LogLevel

type LogLevel int

func (LogLevel) Name

func (level LogLevel) Name() string

func (LogLevel) String

func (level LogLevel) String() string

type Logger

type Logger struct {
	Prefix string
	Level  LogLevel
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(level LogLevel) *Logger

func (*Logger) Enable

func (logger *Logger) Enable(level LogLevel)

func (*Logger) Enabled

func (logger *Logger) Enabled() bool

func (*Logger) LevelEnabled

func (logger *Logger) LevelEnabled(level LogLevel) bool

func (*Logger) LogLevelf

func (logger *Logger) LogLevelf(level LogLevel, fmt string, v ...interface{})

func (*Logger) Logf

func (logger *Logger) Logf(fmt string, v ...interface{})

func (*Logger) Tracef

func (logger *Logger) Tracef(fmt string, v ...interface{})

func (*Logger) Warnf

func (logger *Logger) Warnf(fmt string, v ...interface{})

type Redis

type Redis interface {
	Cmd(cmd string, args ...interface{}) RedisResponse
	Transaction(transaction func(redis Redis) error) error
	StoreStruct(key string, obj interface{}) error
	LoadStruct(key string, obj interface{}) error
}

func ConnectRedis

func ConnectRedis(endpoint string) (Redis, error)

type RedisLock

type RedisLock struct {
	Client     Redis
	LockName   string
	LockValue  string // Should be unique per client
	Expiration time.Duration
	Retry      uint
}

func (*RedisLock) Extend

func (lock *RedisLock) Extend() error

func (*RedisLock) ExtendIn

func (lock *RedisLock) ExtendIn(redis Redis) error

func (*RedisLock) ExtendTransaction

func (lock *RedisLock) ExtendTransaction(transaction func(redis Redis) error) error

Assume lock is already locked! Instead of unlocking in the end, make sure that we still own the lock and extend the timeout

func (*RedisLock) Lock

func (lock *RedisLock) Lock() error

func (*RedisLock) Transaction

func (lock *RedisLock) Transaction(transaction func(redis Redis) error) error

At the end of the transaction, unlock the lock and make sure it is still owned by us

func (*RedisLock) TryLock

func (lock *RedisLock) TryLock() error

func (*RedisLock) Unlock

func (lock *RedisLock) Unlock() error

func (*RedisLock) UnlockIn

func (lock *RedisLock) UnlockIn(redis Redis) error

type RedisResponse

type RedisResponse interface {
	HasResult() bool
	Err() error
	Map() (map[string]string, error)
	Str() (string, error)
	Int() (int, error)
	List() ([]string, error)
	Bool() (bool, error)
}

type Storable

type Storable interface {
	Key() string
	Client() Redis
}

type StoredObject

type StoredObject struct {
	S Storable
}

func (*StoredObject) Exists

func (stored *StoredObject) Exists() (bool, error)

func (*StoredObject) Load

func (stored *StoredObject) Load() error

func (*StoredObject) LoadExisting

func (stored *StoredObject) LoadExisting() (bool, error)

func (*StoredObject) Save

func (stored *StoredObject) Save() error

func (*StoredObject) SaveIn

func (stored *StoredObject) SaveIn(redis Redis) error

Jump to

Keyboard shortcuts

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