Documentation ¶
Index ¶
- Variables
- func EnsureDir(dir string, mode os.FileMode) error
- func Exit(s string)
- func FileExists(filePath string) bool
- func IsHex(s string) bool
- func LeftPadString(s string, totalLength int) string
- func MaxInt(a, b int) int
- func MinInt(a, b int) int
- func MustWriteFile(filePath string, contents []byte, mode os.FileMode)
- func PanicConsensus(v interface{})
- func PanicCrisis(v interface{})
- func PanicQ(v interface{})
- func PanicSanity(v interface{})
- func Parallel(tasks ...func())
- func RandBytes(n int) []byte
- func RandInt() int
- func RandStr(length int) string
- func RightPadString(s string, totalLength int) string
- func StripHex(s string) string
- func TrapSignal(cb func())
- func WriteFile(filePath string, contents []byte, mode os.FileMode) error
- type BaseService
- func (bs *BaseService) IsRunning() bool
- func (bs *BaseService) OnReset() error
- func (bs *BaseService) OnStart() error
- func (bs *BaseService) OnStop()
- func (bs *BaseService) Reset() (bool, error)
- func (bs *BaseService) SetLogger(l log.Logger)
- func (bs *BaseService) Start() (bool, error)
- func (bs *BaseService) Stop() bool
- func (bs *BaseService) String() string
- func (bs *BaseService) Wait()
- type CMap
- type Service
- type StackError
- type ThrottleTimer
Constants ¶
This section is empty.
Variables ¶
var Fmt = fmt.Sprintf
Fmt shorthand, XXX DEPRECATED
Functions ¶
func FileExists ¶
func LeftPadString ¶
LeftPadString adds spaces to the left of a string to make it length totalLength
func PanicConsensus ¶
func PanicConsensus(v interface{})
Indicates a failure of consensus. Someone was malicious or something has gone horribly wrong. These should really boot us into an "emergency-recover" mode
func PanicCrisis ¶
func PanicCrisis(v interface{})
A panic here means something has gone horribly wrong, in the form of data corruption or failure of the operating system. In a correct/healthy system, these should never fire. If they do, it's indicative of a much more serious problem.
func PanicSanity ¶
func PanicSanity(v interface{})
A panic resulting from a sanity check means there is a programmer error and some guarantee is not satisfied.
func RightPadString ¶
RightPadString adds spaces to the right of a string to make it length totalLength
func TrapSignal ¶
func TrapSignal(cb func())
TrapSignal catches the SIGTERM and executes cb function. After that it exits with code 1.
Types ¶
type BaseService ¶
type BaseService struct { Logger log.Logger Quit chan struct{} // contains filtered or unexported fields }
Classical-inheritance-style service declarations. Services can be started, then stopped, then optionally restarted.
Users can override the OnStart/OnStop methods. In the absence of errors, these methods are guaranteed to be called at most once. If OnStart returns an error, service won't be marked as started, so the user can call Start again.
A call to Reset will panic, unless OnReset is overwritten, allowing OnStart/OnStop to be called again.
The caller must ensure that Start and Stop are not called concurrently.
It is ok to call Stop without calling Start first.
Typical usage:
type FooService struct { BaseService // private fields } func NewFooService() *FooService { fs := &FooService{ // init } fs.BaseService = *NewBaseService(log, "FooService", fs) return fs } func (fs *FooService) OnStart() error { fs.BaseService.OnStart() // Always call the overridden method. // initialize private fields // start subroutines, etc. } func (fs *FooService) OnStop() error { fs.BaseService.OnStop() // Always call the overridden method. // close/destroy private fields // stop subroutines, etc. }
func NewBaseService ¶
func NewBaseService(logger log.Logger, name string, impl Service) *BaseService
func (*BaseService) OnStart ¶
func (bs *BaseService) OnStart() error
Implements Service NOTE: Do not put anything in here, that way users don't need to call BaseService.OnStart()
func (*BaseService) OnStop ¶
func (bs *BaseService) OnStop()
Implements Service NOTE: Do not put anything in here, that way users don't need to call BaseService.OnStop()
func (*BaseService) SetLogger ¶
func (bs *BaseService) SetLogger(l log.Logger)
func (*BaseService) Wait ¶
func (bs *BaseService) Wait()
type CMap ¶
type CMap struct {
// contains filtered or unexported fields
}
CMap is a goroutine-safe map
type StackError ¶
type StackError struct { Err interface{} Stack []byte }
func (StackError) Error ¶
func (se StackError) Error() string
func (StackError) String ¶
func (se StackError) String() string
type ThrottleTimer ¶
type ThrottleTimer struct { Name string Ch chan struct{} // contains filtered or unexported fields }
ThrottleTimer fires an event at most "dur" after each .Set() call. If a short burst of .Set() calls happens, ThrottleTimer fires once. If a long continuous burst of .Set() calls happens, ThrottleTimer fires at most once every "dur".
func NewThrottleTimer ¶
func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer
func (*ThrottleTimer) Set ¶
func (t *ThrottleTimer) Set()
func (*ThrottleTimer) Stop ¶
func (t *ThrottleTimer) Stop() bool
For ease of .Stop()'ing services before .Start()'ing them, we ignore .Stop()'s on nil ThrottleTimers
func (*ThrottleTimer) Unset ¶
func (t *ThrottleTimer) Unset()