Skip to content

Commit

Permalink
feat: [CN-29] remove the support of complex64/complex128 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpakhuchyi committed Jan 24, 2024
1 parent f7814e4 commit b6327cf
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 219 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ easily readable output. Ideal for safeguarding confidential data or enhancing da
- [x] Struct formatting with a default values masking of all the fields (recursively).
- [x] Strings values masking based on provided regexp patterns.
- [x] Wide range of supported types:
- `struct`, `map`, `slice`, `array`, `pointer`, `string`,
- `float64/float32`, `int/int8/int16/int32/int64/rune`,
- `uint/uint8/uint16/uint32/uint64/byte`, `bool`,
- `interface`, `complex64/complex128`.
- `struct`, `map`, `slice`, `array`, `pointer`, `string`
- `float64/float32`, `int/int8/int16/int32/int64/rune`
- `uint/uint8/uint16/uint32/uint64/byte`, `bool`, `interface`
- [x] Customizable configuration.

### Installation
Expand Down
11 changes: 6 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- Wide type support: Censor accommodates a variety of types, including:
- struct, map, slice, array, pointer, interface
- string, bool
- float64/float32, complex64/complex128
- float64/float32
- int/int8/int16/int32/int64/rune
- uint/uint8/uint16/uint32/uint64/uintptr/byte
Expand Down Expand Up @@ -92,13 +92,14 @@
| Uint/Uint8/Uint16 | |
| Uint32/Uint64/Byte | |
| String/Bool | |
| Complex64/Complex128 | |
|------------------------|-----------------------------------------------------------------------|
Unsupported Types:
|------------|------------|------------|
| Chan | UnsafePtr | Func |
|------------|------------|------------|
|------------------------|------------|------------|
| Chan | UnsafePtr | Func |
|------------------------|------------|------------|
| Complex64/Complex128 | | |
|------------------------|------------|------------|
If a value of an unsupported type is provided, a string value with the following format will be returned:
"[Unsupported type: <type>]" - where `<type>` is the type of the provided value.
Expand Down
43 changes: 8 additions & 35 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ go get -u github.com/vpakhuchyi/censor
- [x] Struct formatting with a default values masking of all the fields (recursively).
- [x] Strings values masking based on provided regexp patterns.
- [x] Wide range of supported types:
- `struct`, `map`, `slice`, `array`, `pointer`, `string`,
- `float64/float32`, `int/int8/int16/int32/int64/rune`,
- `uint/uint8/uint16/uint32/uint64/uintptr/byte`, `bool`,
- `interface`, `complex64/complex128`.
- `struct`, `map`, `slice`, `array`, `pointer`, `string`
- `float64/float32`, `int/int8/int16/int32/int64/rune`
- `uint/uint8/uint16/uint32/uint64/uintptr/byte`, `bool`, `interface`
- [x] Support encoding.TextMarshaler interface for custom types.
- [x] Customizable configuration:
- Using `.ymal` file
Expand Down Expand Up @@ -535,36 +534,6 @@ func main() {

```

### Complex64/Complex128

Both parts are formatted to include up to 15 (complex128) and 7 (complex64) precision digits respectively that is
similar to float types.

```go
package main

import (
"log/slog"

"github.com/vpakhuchyi/censor"
)

func main() {
var v complex64 = complex(99.123456789, 22.2222)

slog.Info("Request", "payload", censor.Format(v))
// Here is what we'll see in the log:
//Output: `2038/10/25 12:00:01 INFO Request payload=(99.12346+22.2222i)`

var v2 complex128 = complex(9.123456789123456, 1.050595950)

slog.Info("Request", "payload", censor.Format(v2))
// Here is what we'll see in the log:
//Output: `2038/10/25 12:00:01 INFO Request payload=(9.12345678912346+1.05059595i)`
}

```

### Rune

Please pay attention that rune type is formatted as int32 type because, under the hood, it's an alias for int32.
Expand Down Expand Up @@ -655,18 +624,22 @@ type s struct {
Chan chan int `censor:"display"`
Func func() `censor:"display"`
UnsafePointer unsafe.Pointer `censor:"display"`
Complex64 complex64 `censor:"display"`
Complex128 complex128 `censor:"display"`
}

func main() {
v := s{
Chan: make(chan int),
Func: func() {},
UnsafePointer: unsafe.Pointer(uintptr(1)),
Complex64: complex(1.11231, 2.034),
Complex128: complex(11123.123, 5.5468098889),
}

slog.Info("Request", "payload", censor.Format(v))
// Here is what we'll see in the log:
//Output: `2038/10/25 12:00:01 INFO Request payload={Chan: [Unsupported type: chan], Func: [Unsupported type: func], UnsafePointer: [Unsupported type: unsafe.Pointer]}`
//Output: `2038/10/25 12:00:01 INFO Request payload={Chan: [Unsupported type: chan], Func: [Unsupported type: func], UnsafePointer: [Unsupported type: unsafe.Pointer], Complex64: [Unsupported type: complex64], Complex128: [Unsupported type: complex128]}`
}

```
24 changes: 0 additions & 24 deletions internal/formatter/complex.go

This file was deleted.

43 changes: 0 additions & 43 deletions internal/formatter/complex_test.go

This file was deleted.

8 changes: 2 additions & 6 deletions internal/formatter/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (f *Formatter) compileExcludePatterns() {
}
}

//nolint:exhaustive,gocyclo
//nolint:exhaustive
func (f *Formatter) writeValue(buf *strings.Builder, v models.Value) {
switch v.Kind {
case reflect.String:
Expand All @@ -69,8 +69,6 @@ func (f *Formatter) writeValue(buf *strings.Builder, v models.Value) {
buf.WriteString(f.Integer(v))
case reflect.Float32, reflect.Float64:
buf.WriteString(f.Float(v))
case reflect.Complex64, reflect.Complex128:
buf.WriteString(f.Complex(v))
case reflect.Struct:
buf.WriteString(f.Struct(v.Value.(models.Struct)))
case reflect.Slice, reflect.Array:
Expand All @@ -88,7 +86,7 @@ func (f *Formatter) writeValue(buf *strings.Builder, v models.Value) {
}
}

//nolint:exhaustive,gocyclo
//nolint:exhaustive
func (f *Formatter) writeField(field models.Field, buf *strings.Builder) {
switch field.Value.Kind {
case reflect.String:
Expand All @@ -98,8 +96,6 @@ func (f *Formatter) writeField(field models.Field, buf *strings.Builder) {
buf.WriteString(formatField(field.Name, f.Integer(field.Value)))
case reflect.Float32, reflect.Float64:
buf.WriteString(formatField(field.Name, f.Float(field.Value)))
case reflect.Complex64, reflect.Complex128:
buf.WriteString(formatField(field.Name, f.Complex(field.Value)))
case reflect.Struct:
buf.WriteString(formatField(field.Name, f.Struct(field.Value.Value.(models.Struct))))
case reflect.Slice, reflect.Array:
Expand Down
16 changes: 8 additions & 8 deletions internal/formatter/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,24 @@ func TestFormatter_writeValue(t *testing.T) {
})
})

t.Run("complex64", func(t *testing.T) {
t.Run("unsupported_type_complex64", func(t *testing.T) {
t.Cleanup(func() { buf.Reset() })
require.NotPanics(t, func() {
var c complex64 = 3.11111111111111 + 3.11111111111111i
v := models.Value{Value: c, Kind: reflect.Complex64}
f.writeValue(&buf, v)
exp := "(3.111111+3.111111i)"
exp := "[Unsupported type: complex64]"
require.Equal(t, exp, buf.String())
})
})

t.Run("complex128", func(t *testing.T) {
t.Run("unsupported_type_complex128", func(t *testing.T) {
t.Cleanup(func() { buf.Reset() })
require.NotPanics(t, func() {
var c complex128 = 3.11111111111111 + 3.11111111111111i
v := models.Value{Value: c, Kind: reflect.Complex128}
f.writeValue(&buf, v)
exp := "(3.11111111111111+3.11111111111111i)"
exp := "[Unsupported type: complex128]"
require.Equal(t, exp, buf.String())
})
})
Expand Down Expand Up @@ -664,7 +664,7 @@ func TestFormatter_writeField(t *testing.T) {
})
})

t.Run("complex64", func(t *testing.T) {
t.Run("unsupported_type_complex64", func(t *testing.T) {
t.Cleanup(func() { buf.Reset() })
require.NotPanics(t, func() {
var c complex64 = 3.11111111111111 + 3.11111111111111i
Expand All @@ -676,12 +676,12 @@ func TestFormatter_writeField(t *testing.T) {
},
}
f.writeField(field, &buf)
exp := `Test: (3.111111+3.111111i)`
exp := `Test: [Unsupported type: complex64]`
require.Equal(t, exp, buf.String())
})
})

t.Run("complex128", func(t *testing.T) {
t.Run("unsupported_type_complex128", func(t *testing.T) {
t.Cleanup(func() { buf.Reset() })
require.NotPanics(t, func() {
var c complex128 = 3.11111111111111 + 3.11111111111111i
Expand All @@ -693,7 +693,7 @@ func TestFormatter_writeField(t *testing.T) {
},
}
f.writeField(field, &buf)
exp := `Test: (3.11111111111111+3.11111111111111i)`
exp := `Test: [Unsupported type: complex128]`
require.Equal(t, exp, buf.String())
})
})
Expand Down
20 changes: 0 additions & 20 deletions internal/parser/complex.go

This file was deleted.

37 changes: 0 additions & 37 deletions internal/parser/complex_test.go

This file was deleted.

4 changes: 1 addition & 3 deletions internal/parser/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// In case of a pointer to unsupported type of value, a string built from config.UnsupportedTypeTmpl
// is used instead of the real value. That string contains a type of the value.
//
//nolint:exhaustive,gocyclo
//nolint:exhaustive
func (p *Parser) Interface(rv reflect.Value) models.Value {
if rv.Kind() != reflect.Interface {
panic("provided value is not an interface")
Expand All @@ -36,8 +36,6 @@ func (p *Parser) Interface(rv reflect.Value) models.Value {
return p.Float(rv.Elem())
case reflect.Bool:
return p.Bool(rv.Elem())
case reflect.Complex64, reflect.Complex128:
return p.Complex(rv.Elem())
default:
return models.Value{
Kind: k,
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestParser_Interface(t *testing.T) {
{
Name: "Names",
Value: models.Value{
Value: models.Value{Value: (1.82 + 0i), Kind: reflect.Complex128},
Value: models.Value{Value: `[Unsupported type: complex128]`, Kind: reflect.Complex128},
Kind: reflect.Interface,
},
Opts: options.FieldOptions{Display: true},
Expand Down
4 changes: 0 additions & 4 deletions internal/parser/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func (p *Parser) Map(rv reflect.Value) models.Map {
pair.Key = p.Float(key)
case reflect.Bool:
pair.Key = p.Bool(key)
case reflect.Complex64, reflect.Complex128:
pair.Key = p.Complex(key)
default:
pair.Key = models.Value{Value: fmt.Sprintf(config.UnsupportedTypeTmpl, key.Kind()), Kind: key.Kind()}
}
Expand All @@ -74,8 +72,6 @@ func (p *Parser) Map(rv reflect.Value) models.Map {
pair.Value = p.Float(value)
case reflect.Bool:
pair.Value = p.Bool(value)
case reflect.Complex64, reflect.Complex128:
pair.Value = p.Complex(value)
default:
pair.Value = models.Value{Value: fmt.Sprintf(config.UnsupportedTypeTmpl, k), Kind: k}
}
Expand Down
Loading

0 comments on commit b6327cf

Please sign in to comment.