helper

package
v0.0.0-...-81f3bb6 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The default port for HTTP-for-humans.
	DefaultHTTPPort = "8080"

	// NetworkTimeout is the timeout used for network operations.
	NetworkTimeout = 3 * time.Second
)

Variables

View Source
var DefaultConfig = Config{
	LogPath:             "/var/log/nentropy/nentropy.log",
	PanicLogPath:        "/var/log/nentropy/panic.log",
	PidFile:             "/var/run/nentropy/nentropy.pid",
	DebugMode:           false,
	LogLevel:            10,
	WALDir:              "w",
	JoinMon:             false,
	NumPendingProposals: 2000,
	Tracing:             0.0,
	Monitors:            "",
	RaftId:              1,
	MaxPendingCount:     1000,
	MemberBindPort:      7946,
	JoinMemberAddr:      "",
	NodeType:            "osd",
	Zipkin:              "",
}
View Source
var Logger *log.Logger
View Source
var NumericTable = []byte("0123456789")

Functions

func AssertTrue

func AssertTrue(b bool)

AssertTrue asserts that b is true. Otherwise, it would log fatal.

func AssertTruef

func AssertTruef(b bool, format string, args ...interface{})

AssertTruef is AssertTrue with extra info.

func Check

func Check(err error)

Check logs fatal if err != nil.

func Check2

func Check2(_ interface{}, err error)

Check2 acts as convenience wrapper around Check, using the 2nd argument as error.

func Checkf

func Checkf(err error, format string, args ...interface{})

Checkf is Check with extra info.

func CreatePidfile

func CreatePidfile(pidFile string) error

func EncodeBytesAscending

func EncodeBytesAscending(b []byte, data []byte) []byte

EncodeBytesAscending encodes the []byte value using an escape-based encoding. The encoded value is terminated with the sequence "\x00\x01" which is guaranteed to not occur elsewhere in the encoded value. The encoded bytes are append to the supplied buffer and the resulting buffer is returned.

func EncodeStringAscending

func EncodeStringAscending(b []byte, s string) []byte

EncodeStringAscending encodes the string value using an escape-based encoding. See EncodeBytes for details. The encoded bytes are append to the supplied buffer and the resulting buffer is returned.

func EncodeUint64Ascending

func EncodeUint64Ascending(b []byte, v uint64) []byte

EncodeUint64Ascending encodes the uint64 value using a big-endian 8 byte representation. The bytes are appended to the supplied buffer and the final buffer is returned.

func ErrorIf

func ErrorIf(err error, msg string, data ...interface{})

errorIf synonymous with fatalIf but doesn't exit on error != nil

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf creates a new error with stack trace, etc.

func Fatal

func Fatal(v ...interface{})

Fatal is equivalent to l.Print() followed by a call to os.Exit(1).

func FatalIf

func FatalIf(err error, msg string, data ...interface{})

fatalIf wrapper function which takes error and prints error messages.

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf is equivalent to l.Printf() followed by a call to os.Exit(1).

func Fatalln

func Fatalln(v ...interface{})

Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).

func GenerateRandomId

func GenerateRandomId() []byte

func GenerateRandomIdByLength

func GenerateRandomIdByLength(length int) []byte

func GenerateRandomNumberId

func GenerateRandomNumberId() []byte

func GetAndCreateDataDir

func GetAndCreateDataDir(baseDir string, id uint64, isMon bool) (string, error)

func GetDataDir

func GetDataDir(baseDir string, id uint64, isMon bool) (string, error)

func HashKey

func HashKey(key string) uint32

func Panic

func Panic(level int, v ...interface{})

Panic is equivalent to l.Print() followed by a call to panic().

func Panicf

func Panicf(level int, format string, v ...interface{})

Panicf is equivalent to l.Printf() followed by a call to panic().

func Panicln

func Panicln(level int, v ...interface{})

Panicln is equivalent to l.Println() followed by a call to panic().

func Print

func Print(level int, v ...interface{})

Print calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(level int, format string, v ...interface{})

Printf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.

func Println

func Println(level int, v ...interface{})

Println calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Println.

func RemovePidfile

func RemovePidfile(pidFile string)

func SecureCompare

func SecureCompare(given string, actual string) bool

From https://github.com/codegangsta/martini-contrib/blob/master/auth/util.go SecureCompare performs a constant time compare of two strings to limit timing attacks.

func StackTrace

func StackTrace(str string, all bool)

func Ternary

func Ternary(IF bool, THEN interface{}, ELSE interface{}) interface{}

func Wrap

func Wrap(err error) error

Wrap wraps errors from external lib.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf is Wrap with extra info.

func WritePid

func WritePid(pidfile string) error

Types

type Config

type Config struct {
	LogPath             string
	PanicLogPath        string
	PidFile             string
	DebugMode           bool
	LogLevel            int //1-20
	WALDir              string
	JoinMon             bool
	NumPendingProposals int
	Tracing             float64
	Monitors            string
	RaftId              uint64
	MaxPendingCount     uint64
	MemberBindPort      int
	JoinMemberAddr      string
	NodeID              int
	NodeType            string
	BaseDir             string

	// AdvertiseAddr is the address advertised by the server to other nodes
	// in the cluster. It should be reachable by all other nodes and should
	// route to an interface that Addr is listening on.
	AdvertiseAddr string
	AdvertiseIp   string
	HTTPAddr      string
	Zipkin        string
}
var CONFIG Config

func (*Config) InitConfig

func (c *Config) InitConfig()

type Notifier

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

func NewNotifier

func NewNotifier() *Notifier

func (*Notifier) GetChan

func (nc *Notifier) GetChan() chan struct{}

func (*Notifier) GetErr

func (nc *Notifier) GetErr() error

func (*Notifier) Notify

func (nc *Notifier) Notify(err error)

type RaftConfig

type RaftConfig struct {
	// RaftTickInterval is the resolution of the Raft timer.
	RaftTickInterval time.Duration

	// RaftElectionTimeoutTicks is the number of raft ticks before the
	// previous election expires. This value is inherited by individual stores
	// unless overridden.
	RaftElectionTimeoutTicks int

	// RangeLeaseRaftElectionTimeoutMultiplier specifies what multiple the leader
	// lease active duration should be of the raft election timeout.
	RangeLeaseRaftElectionTimeoutMultiplier float64
}

RaftConfig holds raft tuning parameters.

func (*RaftConfig) SetDefaults

func (cfg *RaftConfig) SetDefaults()

SetDefaults initializes unset fields.

type SafeMap

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

func NewSafeMap

func NewSafeMap() *SafeMap

NewSafeMap return new safemap

func (*SafeMap) Check

func (m *SafeMap) Check(k interface{}) bool

Returns true if k is exist in the map.

func (*SafeMap) Delete

func (m *SafeMap) Delete(k interface{})

Delete the given key and value.

func (*SafeMap) Get

func (m *SafeMap) Get(k interface{}) interface{}

Get from maps return the k's value

func (*SafeMap) Items

func (m *SafeMap) Items() map[interface{}]interface{}

Items returns all items in safemap.

func (*SafeMap) LoadOrStore

func (m *SafeMap) LoadOrStore(k interface{}, v interface{}) (actual interface{}, loaded bool)

Maps the given key and value. Returns false if the key is already in the map and changes nothing.

func (*SafeMap) Set

func (m *SafeMap) Set(k interface{}, v interface{}) bool

Maps the given key and value. Returns false if the key is already in the map and changes nothing.

type SafeMutex

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

SafeLock can be used in place of sync.RWMutex

func (*SafeMutex) AssertLock

func (s *SafeMutex) AssertLock()

func (*SafeMutex) AssertRLock

func (s *SafeMutex) AssertRLock()

func (*SafeMutex) Lock

func (s *SafeMutex) Lock()

func (*SafeMutex) RLock

func (s *SafeMutex) RLock()

func (*SafeMutex) RUnlock

func (s *SafeMutex) RUnlock()

func (*SafeMutex) StartWait

func (s *SafeMutex) StartWait() *SafeWait

func (*SafeMutex) Unlock

func (s *SafeMutex) Unlock()

func (*SafeMutex) Wait

func (s *SafeMutex) Wait()

type SafeWait

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

func (*SafeWait) Done

func (s *SafeWait) Done()

Jump to

Keyboard shortcuts

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