Skip to content

Commit

Permalink
Consistent casing, redundancy, and spelling/grammar (rs#391)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nichady authored and pablitoc committed Apr 7, 2023
1 parent 26cd2fb commit 1d1b6e4
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 95 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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) {
Expand Down Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions array.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/lint/readme.md → cmd/lint/README.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ctx_test.go
Expand Up @@ -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")
}
}
6 changes: 3 additions & 3 deletions diode/internal/diodes/many_to_one.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand All @@ -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.
//
Expand Down
2 changes: 1 addition & 1 deletion diode/internal/diodes/one_to_one.go
Expand Up @@ -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.
//
Expand Down
8 changes: 4 additions & 4 deletions diode/internal/diodes/poller.go
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions diode/internal/diodes/waiter.go
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions event.go
Expand Up @@ -688,7 +688,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
Expand All @@ -697,7 +697,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
Expand Down
2 changes: 1 addition & 1 deletion globals.go
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions hlog/hlog_example_test.go
Expand Up @@ -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"))
Expand All @@ -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"}
}
5 changes: 3 additions & 2 deletions internal/cbor/cbor.go
Expand Up @@ -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 {
Expand All @@ -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)))
Expand Down
26 changes: 13 additions & 13 deletions internal/cbor/decode_stream.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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...)
Expand All @@ -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)

Expand All @@ -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, '"')
Expand All @@ -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++ {
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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{'{'})
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/cbor/string.go
Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand All @@ -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))

Expand All @@ -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))
}
Expand Down

0 comments on commit 1d1b6e4

Please sign in to comment.