github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/jsonfmt/encoder_error.go (about) 1 package jsonfmt 2 3 import ( 4 "unsafe" 5 "context" 6 "github.com/v2pro/plz/reflect2" 7 ) 8 9 type errorEncoder struct { 10 valType reflect2.Type 11 } 12 13 func (encoder *errorEncoder) Encode(ctx context.Context, space []byte, ptr unsafe.Pointer) []byte { 14 obj := encoder.valType.UnsafeIndirect(ptr) 15 space = append(space, '"') 16 space = append(space, obj.(error).Error()...) 17 space = append(space, '"') 18 return space 19 }