Consistent casing, redundancy, and spelling/grammar (#391)
* fix casing * remove redundant type conversions * remove unnecessary append x = append(y) is equivalent to x = y * fix grammar and spelling * rename file to enforce consistent casing with other READMEs in this repo
This commit is contained in:
parent
665519c4da
commit
c0c2e11fc3
|
@ -409,7 +409,7 @@ log.Info().Msg("hello world")
|
|||
|
||||
### Thread-safe, lock-free, non-blocking writer
|
||||
|
||||
If your writer might be slow or not thread-safe and you need your log producers to never get slowed down by a slow writer, you can use a `diode.Writer` as follow:
|
||||
If your writer might be slow or not thread-safe and you need your log producers to never get slowed down by a slow writer, you can use a `diode.Writer` as follows:
|
||||
|
||||
```go
|
||||
wr := diode.NewWriter(os.Stdout, 1000, 10*time.Millisecond, func(missed int) {
|
||||
|
@ -564,7 +564,7 @@ func main() {
|
|||
|
||||
## Global Settings
|
||||
|
||||
Some settings can be changed and will by applied to all loggers:
|
||||
Some settings can be changed and will be applied to all loggers:
|
||||
|
||||
* `log.Logger`: You can set this value to customize the global logger (the one used by package level methods).
|
||||
* `zerolog.SetGlobalLevel`: Can raise the minimum level of all loggers. Call this with `zerolog.Disabled` to disable logging altogether (quiet mode).
|
||||
|
|
4
array.go
4
array.go
|
@ -49,7 +49,7 @@ func (*Array) MarshalZerologArray(*Array) {
|
|||
func (a *Array) write(dst []byte) []byte {
|
||||
dst = enc.AppendArrayStart(dst)
|
||||
if len(a.buf) > 0 {
|
||||
dst = append(append(dst, a.buf...))
|
||||
dst = append(dst, a.buf...)
|
||||
}
|
||||
dst = enc.AppendArrayEnd(dst)
|
||||
putArray(a)
|
||||
|
@ -193,7 +193,7 @@ func (a *Array) Float64(f float64) *Array {
|
|||
return a
|
||||
}
|
||||
|
||||
// Time append append t formated as string using zerolog.TimeFieldFormat.
|
||||
// Time append append t formatted as string using zerolog.TimeFieldFormat.
|
||||
func (a *Array) Time(t time.Time) *Array {
|
||||
a.buf = enc.AppendTime(enc.AppendArrayDelim(a.buf), t, TimeFieldFormat)
|
||||
return a
|
||||
|
|
|
@ -27,7 +27,7 @@ The command accepts only one argument - the package to be inspected - and 4 opti
|
|||
- ignoreFile
|
||||
- which files to ignore, either by full path or by go path (package/file.go)
|
||||
- ignorePkg
|
||||
- do not inspect the specified package if found in the dependecy tree
|
||||
- do not inspect the specified package if found in the dependency tree
|
||||
- ignorePkgRecursively
|
||||
- do not inspect the specified package or its subpackages if found in the dependency tree
|
||||
|
|
@ -65,6 +65,6 @@ func TestCtxDisabled(t *testing.T) {
|
|||
|
||||
ctx = dl.WithContext(ctx)
|
||||
if Ctx(ctx) != &dl {
|
||||
t.Error("WithContext did not overide logger with a disabled logger")
|
||||
t.Error("WithContext did not override logger with a disabled logger")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ type ManyToOne struct {
|
|||
}
|
||||
|
||||
// NewManyToOne creates a new diode (ring buffer). The ManyToOne diode
|
||||
// is optimzed for many writers (on go-routines B-n) and a single reader
|
||||
// is optimized for many writers (on go-routines B-n) and a single reader
|
||||
// (on go-routine A). The alerter is invoked on the read's go-routine. It is
|
||||
// called when it notices that the writer go-routine has passed it and wrote
|
||||
// over data. A nil can be used to ignore alerts.
|
||||
|
@ -66,7 +66,7 @@ func (d *ManyToOne) Set(data GenericDataType) {
|
|||
}
|
||||
|
||||
// TryNext will attempt to read from the next slot of the ring buffer.
|
||||
// If there is not data available, it will return (nil, false).
|
||||
// If there is no data available, it will return (nil, false).
|
||||
func (d *ManyToOne) TryNext() (data GenericDataType, ok bool) {
|
||||
// Read a value from the ring buffer based on the readIndex.
|
||||
idx := d.readIndex % uint64(len(d.buffer))
|
||||
|
@ -80,7 +80,7 @@ func (d *ManyToOne) TryNext() (data GenericDataType, ok bool) {
|
|||
}
|
||||
|
||||
// When the seq value is less than the current read index that means a
|
||||
// value was read from idx that was previously written but has since has
|
||||
// value was read from idx that was previously written but since has
|
||||
// been dropped. This value must be ignored and the read head must not
|
||||
// increment.
|
||||
//
|
||||
|
|
|
@ -80,7 +80,7 @@ func (d *OneToOne) TryNext() (data GenericDataType, ok bool) {
|
|||
}
|
||||
|
||||
// When the seq value is less than the current read index that means a
|
||||
// value was read from idx that was previously written but has since has
|
||||
// value was read from idx that was previously written but since has
|
||||
// been dropped. This value must be ignored and the read head must not
|
||||
// increment.
|
||||
//
|
||||
|
|
|
@ -24,18 +24,18 @@ type PollerConfigOption func(*Poller)
|
|||
// WithPollingInterval sets the interval at which the diode is queried
|
||||
// for new data. The default is 10ms.
|
||||
func WithPollingInterval(interval time.Duration) PollerConfigOption {
|
||||
return PollerConfigOption(func(c *Poller) {
|
||||
return func(c *Poller) {
|
||||
c.interval = interval
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// WithPollingContext sets the context to cancel any retrieval (Next()). It
|
||||
// will not change any results for adding data (Set()). Default is
|
||||
// context.Background().
|
||||
func WithPollingContext(ctx context.Context) PollerConfigOption {
|
||||
return PollerConfigOption(func(c *Poller) {
|
||||
return func(c *Poller) {
|
||||
c.ctx = ctx
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// NewPoller returns a new Poller that wraps the given diode.
|
||||
|
|
|
@ -21,9 +21,9 @@ type WaiterConfigOption func(*Waiter)
|
|||
// will not change any results for adding data (Set()). Default is
|
||||
// context.Background().
|
||||
func WithWaiterContext(ctx context.Context) WaiterConfigOption {
|
||||
return WaiterConfigOption(func(c *Waiter) {
|
||||
return func(c *Waiter) {
|
||||
c.ctx = ctx
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// NewWaiter returns a new Waiter that wraps the given diode.
|
||||
|
|
4
event.go
4
event.go
|
@ -645,7 +645,7 @@ func (e *Event) Timestamp() *Event {
|
|||
return e
|
||||
}
|
||||
|
||||
// Time adds the field key with t formated as string using zerolog.TimeFieldFormat.
|
||||
// Time adds the field key with t formatted as string using zerolog.TimeFieldFormat.
|
||||
func (e *Event) Time(key string, t time.Time) *Event {
|
||||
if e == nil {
|
||||
return e
|
||||
|
@ -654,7 +654,7 @@ func (e *Event) Time(key string, t time.Time) *Event {
|
|||
return e
|
||||
}
|
||||
|
||||
// Times adds the field key with t formated as string using zerolog.TimeFieldFormat.
|
||||
// Times adds the field key with t formatted as string using zerolog.TimeFieldFormat.
|
||||
func (e *Event) Times(key string, t []time.Time) *Event {
|
||||
if e == nil {
|
||||
return e
|
||||
|
|
|
@ -81,7 +81,7 @@ var (
|
|||
InterfaceMarshalFunc = json.Marshal
|
||||
|
||||
// TimeFieldFormat defines the time format of the Time field type. If set to
|
||||
// TimeFormatUnix, TimeFormatUnixMs or TimeFormatUnixMicro, the time is formatted as an UNIX
|
||||
// TimeFormatUnix, TimeFormatUnixMs or TimeFormatUnixMicro, the time is formatted as a UNIX
|
||||
// timestamp as integer.
|
||||
TimeFieldFormat = time.RFC3339
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ func Example_handler() {
|
|||
// Install the logger handler with default output on the console
|
||||
c = c.Append(hlog.NewHandler(log))
|
||||
|
||||
// Install some provided extra handler to set some request's context fields.
|
||||
// Thanks to those handler, all our logs will come with some pre-populated fields.
|
||||
// Install some provided extra handlers to set some request's context fields.
|
||||
// Thanks to those handlers, all our logs will come with some pre-populated fields.
|
||||
c = c.Append(hlog.RemoteAddrHandler("ip"))
|
||||
c = c.Append(hlog.UserAgentHandler("user_agent"))
|
||||
c = c.Append(hlog.RefererHandler("referer"))
|
||||
|
@ -63,11 +63,11 @@ func Example_handler() {
|
|||
hlog.FromRequest(r).Info().
|
||||
Str("user", "current user").
|
||||
Str("status", "ok").
|
||||
Msg("Something happend")
|
||||
Msg("Something happened")
|
||||
}))
|
||||
http.Handle("/", h)
|
||||
|
||||
h.ServeHTTP(httptest.NewRecorder(), &http.Request{})
|
||||
|
||||
// Output: {"level":"info","role":"my-service","host":"local-hostname","user":"current user","status":"ok","time":"2001-02-03T04:05:06Z","message":"Something happend"}
|
||||
// Output: {"level":"info","role":"my-service","host":"local-hostname","user":"current user","status":"ok","time":"2001-02-03T04:05:06Z","message":"Something happened"}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ const (
|
|||
var IntegerTimeFieldFormat = time.RFC3339
|
||||
|
||||
// NanoTimeFieldFormat indicates the format of timestamp decoded
|
||||
// from a float value (time in seconds and nano seconds).
|
||||
// from a float value (time in seconds and nanoseconds).
|
||||
var NanoTimeFieldFormat = time.RFC3339Nano
|
||||
|
||||
func appendCborTypePrefix(dst []byte, major byte, number uint64) []byte {
|
||||
|
@ -91,7 +91,8 @@ func appendCborTypePrefix(dst []byte, major byte, number uint64) []byte {
|
|||
minor = additionalTypeIntUint64
|
||||
|
||||
}
|
||||
dst = append(dst, byte(major|minor))
|
||||
|
||||
dst = append(dst, major|minor)
|
||||
byteCount--
|
||||
for ; byteCount >= 0; byteCount-- {
|
||||
dst = append(dst, byte(number>>(uint(byteCount)*8)))
|
||||
|
|
|
@ -43,7 +43,7 @@ func readByte(src *bufio.Reader) byte {
|
|||
return b
|
||||
}
|
||||
|
||||
func decodeIntAdditonalType(src *bufio.Reader, minor byte) int64 {
|
||||
func decodeIntAdditionalType(src *bufio.Reader, minor byte) int64 {
|
||||
val := int64(0)
|
||||
if minor <= 23 {
|
||||
val = int64(minor)
|
||||
|
@ -77,7 +77,7 @@ func decodeInteger(src *bufio.Reader) int64 {
|
|||
if major != majorTypeUnsignedInt && major != majorTypeNegativeInt {
|
||||
panic(fmt.Errorf("Major type is: %d in decodeInteger!! (expected 0 or 1)", major))
|
||||
}
|
||||
val := decodeIntAdditonalType(src, minor)
|
||||
val := decodeIntAdditionalType(src, minor)
|
||||
if major == 0 {
|
||||
return val
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func decodeString(src *bufio.Reader, noQuotes bool) []byte {
|
|||
if !noQuotes {
|
||||
result = append(result, '"')
|
||||
}
|
||||
length := decodeIntAdditonalType(src, minor)
|
||||
length := decodeIntAdditionalType(src, minor)
|
||||
len := int(length)
|
||||
pbs := readNBytes(src, len)
|
||||
result = append(result, pbs...)
|
||||
|
@ -222,7 +222,7 @@ func decodeUTF8String(src *bufio.Reader) []byte {
|
|||
panic(fmt.Errorf("Major type is: %d in decodeUTF8String", major))
|
||||
}
|
||||
result := []byte{'"'}
|
||||
length := decodeIntAdditonalType(src, minor)
|
||||
length := decodeIntAdditionalType(src, minor)
|
||||
len := int(length)
|
||||
pbs := readNBytes(src, len)
|
||||
|
||||
|
@ -238,7 +238,7 @@ func decodeUTF8String(src *bufio.Reader) []byte {
|
|||
return append(dst, '"')
|
||||
}
|
||||
}
|
||||
// The string has no need for encoding an therefore is directly
|
||||
// The string has no need for encoding and therefore is directly
|
||||
// appended to the byte slice.
|
||||
result = append(result, pbs...)
|
||||
return append(result, '"')
|
||||
|
@ -257,7 +257,7 @@ func array2Json(src *bufio.Reader, dst io.Writer) {
|
|||
if minor == additionalTypeInfiniteCount {
|
||||
unSpecifiedCount = true
|
||||
} else {
|
||||
length := decodeIntAdditonalType(src, minor)
|
||||
length := decodeIntAdditionalType(src, minor)
|
||||
len = int(length)
|
||||
}
|
||||
for i := 0; unSpecifiedCount || i < len; i++ {
|
||||
|
@ -266,7 +266,7 @@ func array2Json(src *bufio.Reader, dst io.Writer) {
|
|||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
if pb[0] == byte(majorTypeSimpleAndFloat|additionalTypeBreak) {
|
||||
if pb[0] == majorTypeSimpleAndFloat|additionalTypeBreak {
|
||||
readByte(src)
|
||||
break
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ func array2Json(src *bufio.Reader, dst io.Writer) {
|
|||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
if pb[0] == byte(majorTypeSimpleAndFloat|additionalTypeBreak) {
|
||||
if pb[0] == majorTypeSimpleAndFloat|additionalTypeBreak {
|
||||
readByte(src)
|
||||
break
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ func map2Json(src *bufio.Reader, dst io.Writer) {
|
|||
if minor == additionalTypeInfiniteCount {
|
||||
unSpecifiedCount = true
|
||||
} else {
|
||||
length := decodeIntAdditonalType(src, minor)
|
||||
length := decodeIntAdditionalType(src, minor)
|
||||
len = int(length)
|
||||
}
|
||||
dst.Write([]byte{'{'})
|
||||
|
@ -311,7 +311,7 @@ func map2Json(src *bufio.Reader, dst io.Writer) {
|
|||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
if pb[0] == byte(majorTypeSimpleAndFloat|additionalTypeBreak) {
|
||||
if pb[0] == majorTypeSimpleAndFloat|additionalTypeBreak {
|
||||
readByte(src)
|
||||
break
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ func map2Json(src *bufio.Reader, dst io.Writer) {
|
|||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
if pb[0] == byte(majorTypeSimpleAndFloat|additionalTypeBreak) {
|
||||
if pb[0] == majorTypeSimpleAndFloat|additionalTypeBreak {
|
||||
readByte(src)
|
||||
break
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ func decodeTagData(src *bufio.Reader) []byte {
|
|||
|
||||
// Tag value is larger than 256 (so uint16).
|
||||
case additionalTypeIntUint16:
|
||||
val := decodeIntAdditonalType(src, minor)
|
||||
val := decodeIntAdditionalType(src, minor)
|
||||
|
||||
switch uint16(val) {
|
||||
case additionalTypeEmbeddedJSON:
|
||||
|
@ -383,7 +383,7 @@ func decodeTagData(src *bufio.Reader) []byte {
|
|||
|
||||
case additionalTypeTagNetworkPrefix:
|
||||
pb := readByte(src)
|
||||
if pb != byte(majorTypeMap|0x1) {
|
||||
if pb != majorTypeMap|0x1 {
|
||||
panic(fmt.Errorf("IP Prefix is NOT of MAP of 1 elements as expected"))
|
||||
}
|
||||
octets := decodeString(src, true)
|
||||
|
|
|
@ -8,7 +8,7 @@ func (e Encoder) AppendStrings(dst []byte, vals []string) []byte {
|
|||
l := len(vals)
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func (Encoder) AppendString(dst []byte, s string) []byte {
|
|||
l := len(s)
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, majorTypeUtf8String, uint64(l))
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func (Encoder) AppendBytes(dst, s []byte) []byte {
|
|||
l := len(s)
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func AppendEmbeddedJSON(dst, s []byte) []byte {
|
|||
minor := additionalTypeEmbeddedJSON
|
||||
|
||||
// Append the TAG to indicate this is Embedded JSON.
|
||||
dst = append(dst, byte(major|additionalTypeIntUint16))
|
||||
dst = append(dst, major|additionalTypeIntUint16)
|
||||
dst = append(dst, byte(minor>>8))
|
||||
dst = append(dst, byte(minor&0xff))
|
||||
|
||||
|
@ -87,7 +87,7 @@ func AppendEmbeddedJSON(dst, s []byte) []byte {
|
|||
l := len(s)
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
func appendIntegerTimestamp(dst []byte, t time.Time) []byte {
|
||||
major := majorTypeTags
|
||||
minor := additionalTypeTimestamp
|
||||
dst = append(dst, byte(major|minor))
|
||||
dst = append(dst, major|minor)
|
||||
secs := t.Unix()
|
||||
var val uint64
|
||||
if secs < 0 {
|
||||
|
@ -17,18 +17,18 @@ func appendIntegerTimestamp(dst []byte, t time.Time) []byte {
|
|||
major = majorTypeUnsignedInt
|
||||
val = uint64(secs)
|
||||
}
|
||||
dst = appendCborTypePrefix(dst, major, uint64(val))
|
||||
dst = appendCborTypePrefix(dst, major, val)
|
||||
return dst
|
||||
}
|
||||
|
||||
func (e Encoder) appendFloatTimestamp(dst []byte, t time.Time) []byte {
|
||||
major := majorTypeTags
|
||||
minor := additionalTypeTimestamp
|
||||
dst = append(dst, byte(major|minor))
|
||||
dst = append(dst, major|minor)
|
||||
secs := t.Unix()
|
||||
nanos := t.Nanosecond()
|
||||
var val float64
|
||||
val = float64(secs)*1.0 + float64(nanos)*1E-9
|
||||
val = float64(secs)*1.0 + float64(nanos)*1e-9
|
||||
return e.AppendFloat64(dst, val)
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (e Encoder) AppendTimes(dst []byte, vals []time.Time, unused string) []byte
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Dur
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
|
|
@ -8,17 +8,17 @@ import (
|
|||
|
||||
// AppendNil inserts a 'Nil' object into the dst byte array.
|
||||
func (Encoder) AppendNil(dst []byte) []byte {
|
||||
return append(dst, byte(majorTypeSimpleAndFloat|additionalTypeNull))
|
||||
return append(dst, majorTypeSimpleAndFloat|additionalTypeNull)
|
||||
}
|
||||
|
||||
// AppendBeginMarker inserts a map start into the dst byte array.
|
||||
func (Encoder) AppendBeginMarker(dst []byte) []byte {
|
||||
return append(dst, byte(majorTypeMap|additionalTypeInfiniteCount))
|
||||
return append(dst, majorTypeMap|additionalTypeInfiniteCount)
|
||||
}
|
||||
|
||||
// AppendEndMarker inserts a map end into the dst byte array.
|
||||
func (Encoder) AppendEndMarker(dst []byte) []byte {
|
||||
return append(dst, byte(majorTypeSimpleAndFloat|additionalTypeBreak))
|
||||
return append(dst, majorTypeSimpleAndFloat|additionalTypeBreak)
|
||||
}
|
||||
|
||||
// AppendObjectData takes an object in form of a byte array and appends to dst.
|
||||
|
@ -30,12 +30,12 @@ func (Encoder) AppendObjectData(dst []byte, o []byte) []byte {
|
|||
|
||||
// AppendArrayStart adds markers to indicate the start of an array.
|
||||
func (Encoder) AppendArrayStart(dst []byte) []byte {
|
||||
return append(dst, byte(majorTypeArray|additionalTypeInfiniteCount))
|
||||
return append(dst, majorTypeArray|additionalTypeInfiniteCount)
|
||||
}
|
||||
|
||||
// AppendArrayEnd adds markers to indicate the end of an array.
|
||||
func (Encoder) AppendArrayEnd(dst []byte) []byte {
|
||||
return append(dst, byte(majorTypeSimpleAndFloat|additionalTypeBreak))
|
||||
return append(dst, majorTypeSimpleAndFloat|additionalTypeBreak)
|
||||
}
|
||||
|
||||
// AppendArrayDelim adds markers to indicate end of a particular array element.
|
||||
|
@ -56,7 +56,7 @@ func (Encoder) AppendBool(dst []byte, val bool) []byte {
|
|||
if val {
|
||||
b = additionalTypeBoolTrue
|
||||
}
|
||||
return append(dst, byte(majorTypeSimpleAndFloat|b))
|
||||
return append(dst, majorTypeSimpleAndFloat|b)
|
||||
}
|
||||
|
||||
// AppendBools encodes and inserts an array of boolean values into the dst byte array.
|
||||
|
@ -68,7 +68,7 @@ func (e Encoder) AppendBools(dst []byte, vals []bool) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func (Encoder) AppendInt(dst []byte, val int) []byte {
|
|||
}
|
||||
if contentVal <= additionalMax {
|
||||
lb := byte(contentVal)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(contentVal))
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ func (e Encoder) AppendInts(dst []byte, vals []int) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ func (e Encoder) AppendInts8(dst []byte, vals []int8) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ func (e Encoder) AppendInts16(dst []byte, vals []int16) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ func (e Encoder) AppendInts32(dst []byte, vals []int32) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ func (Encoder) AppendInt64(dst []byte, val int64) []byte {
|
|||
}
|
||||
if contentVal <= additionalMax {
|
||||
lb := byte(contentVal)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(contentVal))
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ func (e Encoder) AppendInts64(dst []byte, vals []int64) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ func (e Encoder) AppendUints(dst []byte, vals []uint) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ func (e Encoder) AppendUints8(dst []byte, vals []uint8) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ func (e Encoder) AppendUints16(dst []byte, vals []uint16) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ func (e Encoder) AppendUints32(dst []byte, vals []uint32) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -324,9 +324,9 @@ func (Encoder) AppendUint64(dst []byte, val uint64) []byte {
|
|||
contentVal := val
|
||||
if contentVal <= additionalMax {
|
||||
lb := byte(contentVal)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(contentVal))
|
||||
dst = appendCborTypePrefix(dst, major, contentVal)
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ func (e Encoder) AppendUints64(dst []byte, vals []uint64) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ func (Encoder) AppendFloat32(dst []byte, val float32) []byte {
|
|||
for i := uint(0); i < 4; i++ {
|
||||
buf[i] = byte(n >> ((3 - i) * 8))
|
||||
}
|
||||
return append(append(dst, byte(major|subType)), buf[0], buf[1], buf[2], buf[3])
|
||||
return append(append(dst, major|subType), buf[0], buf[1], buf[2], buf[3])
|
||||
}
|
||||
|
||||
// AppendFloats32 encodes and inserts an array of single precision float value into the dst byte array.
|
||||
|
@ -379,7 +379,7 @@ func (e Encoder) AppendFloats32(dst []byte, vals []float32) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ func (Encoder) AppendFloat64(dst []byte, val float64) []byte {
|
|||
major := majorTypeSimpleAndFloat
|
||||
subType := additionalTypeFloat64
|
||||
n := math.Float64bits(val)
|
||||
dst = append(dst, byte(major|subType))
|
||||
dst = append(dst, major|subType)
|
||||
for i := uint(1); i <= 8; i++ {
|
||||
b := byte(n >> ((8 - i) * 8))
|
||||
dst = append(dst, b)
|
||||
|
@ -419,7 +419,7 @@ func (e Encoder) AppendFloats64(dst []byte, vals []float64) []byte {
|
|||
}
|
||||
if l <= additionalMax {
|
||||
lb := byte(l)
|
||||
dst = append(dst, byte(major|lb))
|
||||
dst = append(dst, major|lb)
|
||||
} else {
|
||||
dst = appendCborTypePrefix(dst, major, uint64(l))
|
||||
}
|
||||
|
@ -440,7 +440,7 @@ func (e Encoder) AppendInterface(dst []byte, i interface{}) []byte {
|
|||
|
||||
// AppendIPAddr encodes and inserts an IP Address (IPv4 or IPv6).
|
||||
func (e Encoder) AppendIPAddr(dst []byte, ip net.IP) []byte {
|
||||
dst = append(dst, byte(majorTypeTags|additionalTypeIntUint16))
|
||||
dst = append(dst, majorTypeTags|additionalTypeIntUint16)
|
||||
dst = append(dst, byte(additionalTypeTagNetworkAddr>>8))
|
||||
dst = append(dst, byte(additionalTypeTagNetworkAddr&0xff))
|
||||
return e.AppendBytes(dst, ip)
|
||||
|
@ -448,21 +448,21 @@ func (e Encoder) AppendIPAddr(dst []byte, ip net.IP) []byte {
|
|||
|
||||
// AppendIPPrefix encodes and inserts an IP Address Prefix (Address + Mask Length).
|
||||
func (e Encoder) AppendIPPrefix(dst []byte, pfx net.IPNet) []byte {
|
||||
dst = append(dst, byte(majorTypeTags|additionalTypeIntUint16))
|
||||
dst = append(dst, majorTypeTags|additionalTypeIntUint16)
|
||||
dst = append(dst, byte(additionalTypeTagNetworkPrefix>>8))
|
||||
dst = append(dst, byte(additionalTypeTagNetworkPrefix&0xff))
|
||||
|
||||
// Prefix is a tuple (aka MAP of 1 pair of elements) -
|
||||
// first element is prefix, second is mask length.
|
||||
dst = append(dst, byte(majorTypeMap|0x1))
|
||||
dst = append(dst, majorTypeMap|0x1)
|
||||
dst = e.AppendBytes(dst, pfx.IP)
|
||||
maskLen, _ := pfx.Mask.Size()
|
||||
return e.AppendUint8(dst, uint8(maskLen))
|
||||
}
|
||||
|
||||
// AppendMACAddr encodes and inserts an Hardware (MAC) address.
|
||||
// AppendMACAddr encodes and inserts a Hardware (MAC) address.
|
||||
func (e Encoder) AppendMACAddr(dst []byte, ha net.HardwareAddr) []byte {
|
||||
dst = append(dst, byte(majorTypeTags|additionalTypeIntUint16))
|
||||
dst = append(dst, majorTypeTags|additionalTypeIntUint16)
|
||||
dst = append(dst, byte(additionalTypeTagNetworkAddr>>8))
|
||||
dst = append(dst, byte(additionalTypeTagNetworkAddr&0xff))
|
||||
return e.AppendBytes(dst, ha)
|
||||
|
@ -470,7 +470,7 @@ func (e Encoder) AppendMACAddr(dst []byte, ha net.HardwareAddr) []byte {
|
|||
|
||||
// AppendHex adds a TAG and inserts a hex bytes as a string.
|
||||
func (e Encoder) AppendHex(dst []byte, val []byte) []byte {
|
||||
dst = append(dst, byte(majorTypeTags|additionalTypeIntUint16))
|
||||
dst = append(dst, majorTypeTags|additionalTypeIntUint16)
|
||||
dst = append(dst, byte(additionalTypeTagHexString>>8))
|
||||
dst = append(dst, byte(additionalTypeTagHexString&0xff))
|
||||
return e.AppendBytes(dst, val)
|
||||
|
|
|
@ -115,7 +115,6 @@ var integerTestCases = []struct {
|
|||
{-0x10001, "\x3a\x00\x01\x00\x00"},
|
||||
{-0x7FFFFFFE, "\x3a\x7f\xff\xff\xfd"},
|
||||
{-1000000, "\x3a\x00\x0f\x42\x3f"},
|
||||
|
||||
}
|
||||
|
||||
func TestAppendInt(t *testing.T) {
|
||||
|
@ -212,7 +211,7 @@ var macAddrTestCases = []struct {
|
|||
{net.HardwareAddr{0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3}, "\"20:01:0d:b8:85:a3\"", "\xd9\x01\x04\x46\x20\x01\x0d\xb8\x85\xa3"},
|
||||
}
|
||||
|
||||
func TestAppendMacAddr(t *testing.T) {
|
||||
func TestAppendMACAddr(t *testing.T) {
|
||||
for _, tc := range macAddrTestCases {
|
||||
s := enc.AppendMACAddr([]byte{}, tc.macaddr)
|
||||
got := string(s)
|
||||
|
|
|
@ -37,7 +37,7 @@ func (e Encoder) AppendStrings(dst []byte, vals []string) []byte {
|
|||
//
|
||||
// The operation loops though each byte in the string looking
|
||||
// for characters that need json or utf8 encoding. If the string
|
||||
// does not need encoding, then the string is appended in it's
|
||||
// does not need encoding, then the string is appended in its
|
||||
// entirety to the byte slice.
|
||||
// If we encounter a byte that does need encoding, switch up
|
||||
// the operation and perform a byte-by-byte read-encode-append.
|
||||
|
@ -56,7 +56,7 @@ func (Encoder) AppendString(dst []byte, s string) []byte {
|
|||
return append(dst, '"')
|
||||
}
|
||||
}
|
||||
// The string has no need for encoding an therefore is directly
|
||||
// The string has no need for encoding and therefore is directly
|
||||
// appended to the byte slice.
|
||||
dst = append(dst, s...)
|
||||
// End with a double quote
|
||||
|
@ -99,7 +99,7 @@ func appendStringComplex(dst []byte, s string, i int) []byte {
|
|||
r, size := utf8.DecodeRuneInString(s[i:])
|
||||
if r == utf8.RuneError && size == 1 {
|
||||
// In case of error, first append previous simple characters to
|
||||
// the byte slice if any and append a remplacement character code
|
||||
// the byte slice if any and append a replacement character code
|
||||
// in place of the invalid sequence.
|
||||
if start < i {
|
||||
dst = append(dst, s[start:i]...)
|
||||
|
|
|
@ -278,7 +278,7 @@ func (Encoder) AppendUints32(dst []byte, vals []uint32) []byte {
|
|||
// AppendUint64 converts the input uint64 to a string and
|
||||
// appends the encoded string to the input byte slice.
|
||||
func (Encoder) AppendUint64(dst []byte, val uint64) []byte {
|
||||
return strconv.AppendUint(dst, uint64(val), 10)
|
||||
return strconv.AppendUint(dst, val, 10)
|
||||
}
|
||||
|
||||
// AppendUints64 encodes the input uint64s to json and
|
||||
|
@ -300,7 +300,7 @@ func (Encoder) AppendUints64(dst []byte, vals []uint64) []byte {
|
|||
|
||||
func appendFloat(dst []byte, val float64, bitSize int) []byte {
|
||||
// JSON does not permit NaN or Infinity. A typical JSON encoder would fail
|
||||
// with an error, but a logging library wants the data to get thru so we
|
||||
// with an error, but a logging library wants the data to get through so we
|
||||
// make a tradeoff and store those types as string.
|
||||
switch {
|
||||
case math.IsNaN(val):
|
||||
|
|
2
log.go
2
log.go
|
@ -361,7 +361,7 @@ func (l *Logger) Panic() *Event {
|
|||
|
||||
// WithLevel starts a new message with level. Unlike Fatal and Panic
|
||||
// methods, WithLevel does not terminate the program or stop the ordinary
|
||||
// flow of a gourotine when used with their respective levels.
|
||||
// flow of a goroutine when used with their respective levels.
|
||||
//
|
||||
// You must call Msg on the returned event in order to send the event.
|
||||
func (l *Logger) WithLevel(level Level) *Event {
|
||||
|
|
|
@ -311,7 +311,7 @@ func ExampleEvent_Interface() {
|
|||
}
|
||||
|
||||
func ExampleEvent_Dur() {
|
||||
d := time.Duration(10 * time.Second)
|
||||
d := 10 * time.Second
|
||||
|
||||
log := zerolog.New(os.Stdout)
|
||||
|
||||
|
@ -325,8 +325,8 @@ func ExampleEvent_Dur() {
|
|||
|
||||
func ExampleEvent_Durs() {
|
||||
d := []time.Duration{
|
||||
time.Duration(10 * time.Second),
|
||||
time.Duration(20 * time.Second),
|
||||
10 * time.Second,
|
||||
20 * time.Second,
|
||||
}
|
||||
|
||||
log := zerolog.New(os.Stdout)
|
||||
|
@ -460,7 +460,7 @@ func ExampleContext_Interface() {
|
|||
}
|
||||
|
||||
func ExampleContext_Dur() {
|
||||
d := time.Duration(10 * time.Second)
|
||||
d := 10 * time.Second
|
||||
|
||||
log := zerolog.New(os.Stdout).With().
|
||||
Str("foo", "bar").
|
||||
|
@ -474,8 +474,8 @@ func ExampleContext_Dur() {
|
|||
|
||||
func ExampleContext_Durs() {
|
||||
d := []time.Duration{
|
||||
time.Duration(10 * time.Second),
|
||||
time.Duration(20 * time.Second),
|
||||
10 * time.Second,
|
||||
20 * time.Second,
|
||||
}
|
||||
|
||||
log := zerolog.New(os.Stdout).With().
|
||||
|
@ -510,7 +510,7 @@ func ExampleContext_IPPrefix() {
|
|||
// Output: {"Route":"192.168.0.0/24","message":"hello world"}
|
||||
}
|
||||
|
||||
func ExampleContext_MacAddr() {
|
||||
func ExampleContext_MACAddr() {
|
||||
mac := net.HardwareAddr{0x00, 0x14, 0x22, 0x01, 0x23, 0x45}
|
||||
log := zerolog.New(os.Stdout).With().
|
||||
MACAddr("hostMAC", mac).
|
||||
|
|
Loading…
Reference in New Issue