From 373c29c388550d86b1da0e2b47aac905a11d1704 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Fri, 27 Jul 2018 11:50:46 -0700 Subject: [PATCH 01/25] WIP: Zap logging support --- envelope/internal/tests/enums/types.go | 123 ++++ envelope/internal/tests/exceptions/types.go | 19 + .../internal/tests/services/cache_clear.go | 7 + .../tests/services/cache_clearafter.go | 11 + .../services/conflictingnames_setvalue.go | 17 + .../tests/services/keyvalue_deletevalue.go | 25 + .../tests/services/keyvalue_getmanyvalues.go | 43 ++ .../tests/services/keyvalue_getvalue.go | 25 + .../tests/services/keyvalue_setvalue.go | 21 + .../tests/services/keyvalue_setvaluev2.go | 17 + .../internal/tests/services/keyvalue_size.go | 17 + ...service_name_non_standard_function_name.go | 13 + envelope/internal/tests/services/types.go | 22 + envelope/internal/tests/structs/types.go | 255 ++++++++ envelope/internal/tests/typedefs/types.go | 56 ++ envelope/internal/tests/unions/types.go | 66 +++ gen/enum.go | 16 + gen/field.go | 29 + gen/generator.go | 42 +- gen/internal/tests/collision/types.go | 165 ++++++ gen/internal/tests/containers/types.go | 551 ++++++++++++++++++ gen/internal/tests/enum_conflict/types.go | 27 + gen/internal/tests/enums/types.go | 123 ++++ gen/internal/tests/exceptions/types.go | 19 + gen/internal/tests/services/cache_clear.go | 7 + .../tests/services/cache_clearafter.go | 11 + .../services/conflictingnames_setvalue.go | 17 + .../tests/services/keyvalue_deletevalue.go | 25 + .../tests/services/keyvalue_getmanyvalues.go | 43 ++ .../tests/services/keyvalue_getvalue.go | 25 + .../tests/services/keyvalue_setvalue.go | 21 + .../tests/services/keyvalue_setvaluev2.go | 17 + gen/internal/tests/services/keyvalue_size.go | 17 + ...service_name_non_standard_function_name.go | 13 + gen/internal/tests/services/types.go | 22 + gen/internal/tests/structs/types.go | 255 ++++++++ gen/internal/tests/typedefs/types.go | 56 ++ gen/internal/tests/unions/types.go | 66 +++ gen/internal/tests/uuid_conflict/types.go | 11 + gen/zap.go | 277 +++++++++ glide.lock | 20 +- glide.yaml | 2 + internal/envelope/exception/types.go | 45 ++ plugin/api/plugin_goodbye.go | 13 + plugin/api/plugin_handshake.go | 21 + plugin/api/servicegenerator_generate.go | 21 + plugin/api/types.go | 300 ++++++++++ 47 files changed, 2988 insertions(+), 26 deletions(-) create mode 100644 gen/zap.go diff --git a/envelope/internal/tests/enums/types.go b/envelope/internal/tests/enums/types.go index 76d35ba4..babd3402 100644 --- a/envelope/internal/tests/enums/types.go +++ b/envelope/internal/tests/enums/types.go @@ -28,6 +28,7 @@ import ( "encoding/json" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "math" "strconv" "strings" @@ -54,6 +55,12 @@ func (v EmptyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EmptyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + return nil +} + // Ptr returns a pointer to this enum value. func (v EmptyEnum) Ptr() *EmptyEnum { return &v @@ -200,6 +207,20 @@ func (v EnumDefault) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EnumDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "Foo") + case 1: + enc.AddString("name", "Bar") + case 2: + enc.AddString("name", "Baz") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v EnumDefault) Ptr() *EnumDefault { return &v @@ -404,6 +425,32 @@ func (v EnumWithDuplicateName) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EnumWithDuplicateName) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "A") + case 1: + enc.AddString("name", "B") + case 2: + enc.AddString("name", "C") + case 3: + enc.AddString("name", "P") + case 4: + enc.AddString("name", "Q") + case 5: + enc.AddString("name", "R") + case 6: + enc.AddString("name", "X") + case 7: + enc.AddString("name", "Y") + case 8: + enc.AddString("name", "Z") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v EnumWithDuplicateName) Ptr() *EnumWithDuplicateName { return &v @@ -588,6 +635,18 @@ func (v EnumWithDuplicateValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EnumWithDuplicateValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "P") + case -1: + enc.AddString("name", "Q") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v EnumWithDuplicateValues) Ptr() *EnumWithDuplicateValues { return &v @@ -746,6 +805,20 @@ func (v EnumWithValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EnumWithValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 123: + enc.AddString("name", "X") + case 456: + enc.AddString("name", "Y") + case 789: + enc.AddString("name", "Z") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v EnumWithValues) Ptr() *EnumWithValues { return &v @@ -916,6 +989,20 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "NAME") + case 1: + enc.AddString("name", "HOME_ADDRESS") + case 2: + enc.AddString("name", "WORK_ADDRESS") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v RecordType) Ptr() *RecordType { return &v @@ -1071,6 +1158,18 @@ func (v RecordTypeValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v RecordTypeValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "FOO") + case 1: + enc.AddString("name", "BAR") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v RecordTypeValues) Ptr() *RecordTypeValues { return &v @@ -1295,6 +1394,16 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.E != nil { + enc.AddObject("e", *v.E) + } + + return nil +} + // GetE returns the value of E if it is set or its // zero value if it is unset. func (v *StructWithOptionalEnum) GetE() (o EnumDefault) { @@ -1361,6 +1470,20 @@ func (v LowerCaseEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v LowerCaseEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "containing") + case 1: + enc.AddString("name", "lower_case") + case 2: + enc.AddString("name", "items") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v LowerCaseEnum) Ptr() *LowerCaseEnum { return &v diff --git a/envelope/internal/tests/exceptions/types.go b/envelope/internal/tests/exceptions/types.go index 9d32e7ae..77303d47 100644 --- a/envelope/internal/tests/exceptions/types.go +++ b/envelope/internal/tests/exceptions/types.go @@ -27,6 +27,7 @@ import ( "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -174,6 +175,18 @@ func (v *DoesNotExistException) Equals(rhs *DoesNotExistException) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *DoesNotExistException) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("key", v.Key) + + if v.Error2 != nil { + enc.AddString("Error", *v.Error2) + } + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *DoesNotExistException) GetKey() (o string) { return v.Key } @@ -268,6 +281,12 @@ func (v *EmptyException) Equals(rhs *EmptyException) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *EmptyException) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + func (v *EmptyException) Error() string { return v.String() } diff --git a/envelope/internal/tests/services/cache_clear.go b/envelope/internal/tests/services/cache_clear.go index d14e7e3d..3c0672ca 100644 --- a/envelope/internal/tests/services/cache_clear.go +++ b/envelope/internal/tests/services/cache_clear.go @@ -26,6 +26,7 @@ package services import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -108,6 +109,12 @@ func (v *Cache_Clear_Args) Equals(rhs *Cache_Clear_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Cache_Clear_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the arguments. // diff --git a/envelope/internal/tests/services/cache_clearafter.go b/envelope/internal/tests/services/cache_clearafter.go index b252a172..1885a001 100644 --- a/envelope/internal/tests/services/cache_clearafter.go +++ b/envelope/internal/tests/services/cache_clearafter.go @@ -26,6 +26,7 @@ package services import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -148,6 +149,16 @@ func (v *Cache_ClearAfter_Args) Equals(rhs *Cache_ClearAfter_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Cache_ClearAfter_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.DurationMS != nil { + enc.AddInt64("durationMS", *v.DurationMS) + } + + return nil +} + // GetDurationMS returns the value of DurationMS if it is set or its // zero value if it is unset. func (v *Cache_ClearAfter_Args) GetDurationMS() (o int64) { diff --git a/envelope/internal/tests/services/conflictingnames_setvalue.go b/envelope/internal/tests/services/conflictingnames_setvalue.go index e60fd4b8..559b0391 100644 --- a/envelope/internal/tests/services/conflictingnames_setvalue.go +++ b/envelope/internal/tests/services/conflictingnames_setvalue.go @@ -26,6 +26,7 @@ package services import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -142,6 +143,16 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Request != nil { + enc.AddObject("request", v.Request) + } + + return nil +} + // GetRequest returns the value of Request if it is set or its // zero value if it is unset. func (v *ConflictingNames_SetValue_Args) GetRequest() (o *ConflictingNamesSetValueArgs) { @@ -321,6 +332,12 @@ func (v *ConflictingNames_SetValue_Result) Equals(rhs *ConflictingNames_SetValue return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ConflictingNames_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/envelope/internal/tests/services/keyvalue_deletevalue.go b/envelope/internal/tests/services/keyvalue_deletevalue.go index 11237978..b222bd87 100644 --- a/envelope/internal/tests/services/keyvalue_deletevalue.go +++ b/envelope/internal/tests/services/keyvalue_deletevalue.go @@ -28,6 +28,7 @@ import ( "fmt" "go.uber.org/thriftrw/envelope/internal/tests/exceptions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -156,6 +157,16 @@ func (v *KeyValue_DeleteValue_Args) Equals(rhs *KeyValue_DeleteValue_Args) bool return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_DeleteValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Key != nil { + enc.AddString("key", (string)(*v.Key)) + } + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *KeyValue_DeleteValue_Args) GetKey() (o Key) { @@ -440,6 +451,20 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.DoesNotExist != nil { + enc.AddObject("doesNotExist", v.DoesNotExist) + } + + if v.InternalError != nil { + enc.AddObject("internalError", v.InternalError) + } + + return nil +} + // GetDoesNotExist returns the value of DoesNotExist if it is set or its // zero value if it is unset. func (v *KeyValue_DeleteValue_Result) GetDoesNotExist() (o *exceptions.DoesNotExistException) { diff --git a/envelope/internal/tests/services/keyvalue_getmanyvalues.go b/envelope/internal/tests/services/keyvalue_getmanyvalues.go index d64969ca..a112f248 100644 --- a/envelope/internal/tests/services/keyvalue_getmanyvalues.go +++ b/envelope/internal/tests/services/keyvalue_getmanyvalues.go @@ -29,6 +29,7 @@ import ( "go.uber.org/thriftrw/envelope/internal/tests/exceptions" "go.uber.org/thriftrw/envelope/internal/tests/unions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -198,6 +199,25 @@ func (v *KeyValue_GetManyValues_Args) Equals(rhs *KeyValue_GetManyValues_Args) b return true } +type _List_Key_Zapper []Key + +func (vals _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendString((string)(val)) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Range != nil { + enc.AddArray("range", (_List_Key_Zapper)(v.Range)) + } + + return nil +} + // GetRange returns the value of Range if it is set or its // zero value if it is unset. func (v *KeyValue_GetManyValues_Args) GetRange() (o []Key) { @@ -535,6 +555,29 @@ func (v *KeyValue_GetManyValues_Result) Equals(rhs *KeyValue_GetManyValues_Resul return true } +type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue + +func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Success != nil { + enc.AddArray("success", (_List_ArbitraryValue_Zapper)(v.Success)) + } + + if v.DoesNotExist != nil { + enc.AddObject("doesNotExist", v.DoesNotExist) + } + + return nil +} + // GetSuccess returns the value of Success if it is set or its // zero value if it is unset. func (v *KeyValue_GetManyValues_Result) GetSuccess() (o []*unions.ArbitraryValue) { diff --git a/envelope/internal/tests/services/keyvalue_getvalue.go b/envelope/internal/tests/services/keyvalue_getvalue.go index 3d4b652a..7dee288e 100644 --- a/envelope/internal/tests/services/keyvalue_getvalue.go +++ b/envelope/internal/tests/services/keyvalue_getvalue.go @@ -29,6 +29,7 @@ import ( "go.uber.org/thriftrw/envelope/internal/tests/exceptions" "go.uber.org/thriftrw/envelope/internal/tests/unions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -141,6 +142,16 @@ func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Key != nil { + enc.AddString("key", (string)(*v.Key)) + } + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *KeyValue_GetValue_Args) GetKey() (o Key) { @@ -410,6 +421,20 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Success != nil { + enc.AddObject("success", v.Success) + } + + if v.DoesNotExist != nil { + enc.AddObject("doesNotExist", v.DoesNotExist) + } + + return nil +} + // GetSuccess returns the value of Success if it is set or its // zero value if it is unset. func (v *KeyValue_GetValue_Result) GetSuccess() (o *unions.ArbitraryValue) { diff --git a/envelope/internal/tests/services/keyvalue_setvalue.go b/envelope/internal/tests/services/keyvalue_setvalue.go index e106573d..688d0e6c 100644 --- a/envelope/internal/tests/services/keyvalue_setvalue.go +++ b/envelope/internal/tests/services/keyvalue_setvalue.go @@ -27,6 +27,7 @@ import ( "fmt" "go.uber.org/thriftrw/envelope/internal/tests/unions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -163,6 +164,20 @@ func (v *KeyValue_SetValue_Args) Equals(rhs *KeyValue_SetValue_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Key != nil { + enc.AddString("key", (string)(*v.Key)) + } + + if v.Value != nil { + enc.AddObject("value", v.Value) + } + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *KeyValue_SetValue_Args) GetKey() (o Key) { @@ -355,6 +370,12 @@ func (v *KeyValue_SetValue_Result) Equals(rhs *KeyValue_SetValue_Result) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/envelope/internal/tests/services/keyvalue_setvaluev2.go b/envelope/internal/tests/services/keyvalue_setvaluev2.go index f7d6e216..61e06132 100644 --- a/envelope/internal/tests/services/keyvalue_setvaluev2.go +++ b/envelope/internal/tests/services/keyvalue_setvaluev2.go @@ -28,6 +28,7 @@ import ( "fmt" "go.uber.org/thriftrw/envelope/internal/tests/unions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -172,6 +173,16 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("key", (string)(v.Key)) + + enc.AddObject("value", v.Value) + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *KeyValue_SetValueV2_Args) GetKey() (o Key) { return v.Key } @@ -352,6 +363,12 @@ func (v *KeyValue_SetValueV2_Result) Equals(rhs *KeyValue_SetValueV2_Result) boo return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_SetValueV2_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/envelope/internal/tests/services/keyvalue_size.go b/envelope/internal/tests/services/keyvalue_size.go index 4ccdffa3..cb4fbe93 100644 --- a/envelope/internal/tests/services/keyvalue_size.go +++ b/envelope/internal/tests/services/keyvalue_size.go @@ -27,6 +27,7 @@ import ( "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -109,6 +110,12 @@ func (v *KeyValue_Size_Args) Equals(rhs *KeyValue_Size_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_Size_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the arguments. // @@ -323,6 +330,16 @@ func (v *KeyValue_Size_Result) Equals(rhs *KeyValue_Size_Result) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_Size_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Success != nil { + enc.AddInt64("success", *v.Success) + } + + return nil +} + // GetSuccess returns the value of Success if it is set or its // zero value if it is unset. func (v *KeyValue_Size_Result) GetSuccess() (o int64) { diff --git a/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go b/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go index 5102ff40..cccb8aab 100644 --- a/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go +++ b/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go @@ -26,6 +26,7 @@ package services import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -108,6 +109,12 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Args) Equals(rhs *NonSta return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *NonStandardServiceName_NonStandardFunctionName_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the arguments. // @@ -271,6 +278,12 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Result) Equals(rhs *NonS return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *NonStandardServiceName_NonStandardFunctionName_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/envelope/internal/tests/services/types.go b/envelope/internal/tests/services/types.go index c79a4421..094496c3 100644 --- a/envelope/internal/tests/services/types.go +++ b/envelope/internal/tests/services/types.go @@ -25,9 +25,11 @@ package services import ( "bytes" + "encoding/base64" "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -165,6 +167,16 @@ func (v *ConflictingNamesSetValueArgs) Equals(rhs *ConflictingNamesSetValueArgs) return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ConflictingNamesSetValueArgs) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("key", v.Key) + + enc.AddString("value", base64.StdEncoding.EncodeToString(v.Value)) + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *ConflictingNamesSetValueArgs) GetKey() (o string) { return v.Key } @@ -289,6 +301,16 @@ func (v *InternalError) Equals(rhs *InternalError) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *InternalError) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Message != nil { + enc.AddString("message", *v.Message) + } + + return nil +} + // GetMessage returns the value of Message if it is set or its // zero value if it is unset. func (v *InternalError) GetMessage() (o string) { diff --git a/envelope/internal/tests/structs/types.go b/envelope/internal/tests/structs/types.go index d49b9393..1b89e5c7 100644 --- a/envelope/internal/tests/structs/types.go +++ b/envelope/internal/tests/structs/types.go @@ -25,11 +25,13 @@ package structs import ( "bytes" + "encoding/base64" "errors" "fmt" "go.uber.org/thriftrw/envelope/internal/tests/enums" "go.uber.org/thriftrw/ptr" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -139,6 +141,14 @@ func (v *ContactInfo) Equals(rhs *ContactInfo) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ContactInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("emailAddress", v.EmailAddress) + + return nil +} + // GetEmailAddress returns the value of EmailAddress if it is set or its // zero value if it is unset. func (v *ContactInfo) GetEmailAddress() (o string) { return v.EmailAddress } @@ -689,6 +699,62 @@ func (v *DefaultsStruct) Equals(rhs *DefaultsStruct) bool { return true } +type _List_String_Zapper []string + +func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendString(val) + } + return nil +} + +type _List_Double_Zapper []float64 + +func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendFloat64(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.RequiredPrimitive != nil { + enc.AddInt32("requiredPrimitive", *v.RequiredPrimitive) + } + + if v.OptionalPrimitive != nil { + enc.AddInt32("optionalPrimitive", *v.OptionalPrimitive) + } + + if v.RequiredEnum != nil { + enc.AddObject("requiredEnum", *v.RequiredEnum) + } + + if v.OptionalEnum != nil { + enc.AddObject("optionalEnum", *v.OptionalEnum) + } + + if v.RequiredList != nil { + enc.AddArray("requiredList", (_List_String_Zapper)(v.RequiredList)) + } + + if v.OptionalList != nil { + enc.AddArray("optionalList", (_List_Double_Zapper)(v.OptionalList)) + } + + if v.RequiredStruct != nil { + enc.AddObject("requiredStruct", v.RequiredStruct) + } + + if v.OptionalStruct != nil { + enc.AddObject("optionalStruct", v.OptionalStruct) + } + + return nil +} + // GetRequiredPrimitive returns the value of RequiredPrimitive if it is set or its // default value if it is unset. func (v *DefaultsStruct) GetRequiredPrimitive() (o int32) { @@ -937,6 +1003,16 @@ func (v *Edge) Equals(rhs *Edge) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddObject("startPoint", v.StartPoint) + + enc.AddObject("endPoint", v.EndPoint) + + return nil +} + // GetStartPoint returns the value of StartPoint if it is set or its // zero value if it is unset. func (v *Edge) GetStartPoint() (o *Point) { return v.StartPoint } @@ -1021,6 +1097,12 @@ func (v *EmptyStruct) Equals(rhs *EmptyStruct) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *EmptyStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + type Frame struct { TopLeft *Point `json:"topLeft,required"` Size *Size `json:"size,required"` @@ -1164,6 +1246,16 @@ func (v *Frame) Equals(rhs *Frame) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddObject("topLeft", v.TopLeft) + + enc.AddObject("size", v.Size) + + return nil +} + // GetTopLeft returns the value of TopLeft if it is set or its // zero value if it is unset. func (v *Frame) GetTopLeft() (o *Point) { return v.TopLeft } @@ -1420,6 +1512,28 @@ func (v *GoTags) Equals(rhs *GoTags) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *GoTags) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("Foo", v.Foo) + + if v.Bar != nil { + enc.AddString("Bar", *v.Bar) + } + + enc.AddString("FooBar", v.FooBar) + + enc.AddString("FooBarWithSpace", v.FooBarWithSpace) + + if v.FooBarWithOmitEmpty != nil { + enc.AddString("FooBarWithOmitEmpty", *v.FooBarWithOmitEmpty) + } + + enc.AddString("FooBarWithRequired", v.FooBarWithRequired) + + return nil +} + // GetFoo returns the value of Foo if it is set or its // zero value if it is unset. func (v *GoTags) GetFoo() (o string) { return v.Foo } @@ -1631,6 +1745,23 @@ func (v *Graph) Equals(rhs *Graph) bool { return true } +type _List_Edge_Zapper []*Edge + +func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)) + + return nil +} + // GetEdges returns the value of Edges if it is set or its // zero value if it is unset. func (v *Graph) GetEdges() (o []*Edge) { return v.Edges } @@ -1802,6 +1933,18 @@ func (v *Node) Equals(rhs *Node) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddInt32("value", v.Value) + + if v.Tail != nil { + enc.AddObject("tail", (*Node)(v.Tail)) + } + + return nil +} + // GetValue returns the value of Value if it is set or its // zero value if it is unset. func (v *Node) GetValue() (o int32) { return v.Value } @@ -1948,6 +2091,16 @@ func (v *Omit) Equals(rhs *Omit) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Omit) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("serialized", v.Serialized) + + enc.AddString("hidden", v.Hidden) + + return nil +} + // GetSerialized returns the value of Serialized if it is set or its // zero value if it is unset. func (v *Omit) GetSerialized() (o string) { return v.Serialized } @@ -2089,6 +2242,16 @@ func (v *Point) Equals(rhs *Point) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Point) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddFloat64("x", v.X) + + enc.AddFloat64("y", v.Y) + + return nil +} + // GetX returns the value of X if it is set or its // zero value if it is unset. func (v *Point) GetX() (o float64) { return v.X } @@ -2436,6 +2599,44 @@ func (v *PrimitiveOptionalStruct) Equals(rhs *PrimitiveOptionalStruct) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *PrimitiveOptionalStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.BoolField != nil { + enc.AddBool("boolField", *v.BoolField) + } + + if v.ByteField != nil { + enc.AddInt8("byteField", *v.ByteField) + } + + if v.Int16Field != nil { + enc.AddInt16("int16Field", *v.Int16Field) + } + + if v.Int32Field != nil { + enc.AddInt32("int32Field", *v.Int32Field) + } + + if v.Int64Field != nil { + enc.AddInt64("int64Field", *v.Int64Field) + } + + if v.DoubleField != nil { + enc.AddFloat64("doubleField", *v.DoubleField) + } + + if v.StringField != nil { + enc.AddString("stringField", *v.StringField) + } + + if v.BinaryField != nil { + enc.AddString("binaryField", base64.StdEncoding.EncodeToString(v.BinaryField)) + } + + return nil +} + // GetBoolField returns the value of BoolField if it is set or its // zero value if it is unset. func (v *PrimitiveOptionalStruct) GetBoolField() (o bool) { @@ -2809,6 +3010,28 @@ func (v *PrimitiveRequiredStruct) Equals(rhs *PrimitiveRequiredStruct) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *PrimitiveRequiredStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddBool("boolField", v.BoolField) + + enc.AddInt8("byteField", v.ByteField) + + enc.AddInt16("int16Field", v.Int16Field) + + enc.AddInt32("int32Field", v.Int32Field) + + enc.AddInt64("int64Field", v.Int64Field) + + enc.AddFloat64("doubleField", v.DoubleField) + + enc.AddString("stringField", v.StringField) + + enc.AddString("binaryField", base64.StdEncoding.EncodeToString(v.BinaryField)) + + return nil +} + // GetBoolField returns the value of BoolField if it is set or its // zero value if it is unset. func (v *PrimitiveRequiredStruct) GetBoolField() (o bool) { return v.BoolField } @@ -2973,6 +3196,16 @@ func (v *Rename) Equals(rhs *Rename) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Rename) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("Default", v.Default) + + enc.AddString("camelCase", v.CamelCase) + + return nil +} + // GetDefault returns the value of Default if it is set or its // zero value if it is unset. func (v *Rename) GetDefault() (o string) { return v.Default } @@ -3116,6 +3349,16 @@ func (v *Size) Equals(rhs *Size) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Size) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddFloat64("width", v.Width) + + enc.AddFloat64("height", v.Height) + + return nil +} + // GetWidth returns the value of Width if it is set or its // zero value if it is unset. func (v *Size) GetWidth() (o float64) { return v.Width } @@ -3260,6 +3503,18 @@ func (v *User) Equals(rhs *User) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("name", v.Name) + + if v.Contact != nil { + enc.AddObject("contact", v.Contact) + } + + return nil +} + // GetName returns the value of Name if it is set or its // zero value if it is unset. func (v *User) GetName() (o string) { return v.Name } diff --git a/envelope/internal/tests/typedefs/types.go b/envelope/internal/tests/typedefs/types.go index 85e06616..0bbebb85 100644 --- a/envelope/internal/tests/typedefs/types.go +++ b/envelope/internal/tests/typedefs/types.go @@ -30,6 +30,7 @@ import ( "go.uber.org/thriftrw/envelope/internal/tests/enums" "go.uber.org/thriftrw/envelope/internal/tests/structs" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -266,6 +267,16 @@ func (v *DefaultPrimitiveTypedef) Equals(rhs *DefaultPrimitiveTypedef) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *DefaultPrimitiveTypedef) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.State != nil { + enc.AddString("state", (string)(*v.State)) + } + + return nil +} + // GetState returns the value of State if it is set or its // default value if it is unset. func (v *DefaultPrimitiveTypedef) GetState() (o State) { @@ -595,6 +606,18 @@ func (v *Event) Equals(rhs *Event) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddObject("uuid", (*I128)(v.UUID)) + + if v.Time != nil { + enc.AddInt64("time", (int64)(*v.Time)) + } + + return nil +} + // GetUUID returns the value of UUID if it is set or its // zero value if it is unset. func (v *Event) GetUUID() (o *UUID) { return v.UUID } @@ -1271,6 +1294,29 @@ func (v *Transition) Equals(rhs *Transition) bool { return true } +type _EventGroup_Zapper []*Event + +func (vals _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("fromState", (string)(v.FromState)) + + enc.AddString("toState", (string)(v.ToState)) + + if v.Events != nil { + enc.AddArray("events", (_EventGroup_Zapper)(([]*Event)(v.Events))) + } + + return nil +} + // GetFromState returns the value of FromState if it is set or its // zero value if it is unset. func (v *Transition) GetFromState() (o State) { return v.FromState } @@ -1450,6 +1496,16 @@ func (v *I128) Equals(rhs *I128) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *I128) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddInt64("high", v.High) + + enc.AddInt64("low", v.Low) + + return nil +} + // GetHigh returns the value of High if it is set or its // zero value if it is unset. func (v *I128) GetHigh() (o int64) { return v.High } diff --git a/envelope/internal/tests/unions/types.go b/envelope/internal/tests/unions/types.go index b0de22cc..f1ec7b10 100644 --- a/envelope/internal/tests/unions/types.go +++ b/envelope/internal/tests/unions/types.go @@ -24,9 +24,11 @@ package unions import ( + "encoding/base64" "fmt" "go.uber.org/thriftrw/envelope/internal/tests/typedefs" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -450,6 +452,50 @@ func (v *ArbitraryValue) Equals(rhs *ArbitraryValue) bool { return true } +type _List_ArbitraryValue_Zapper []*ArbitraryValue + +func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue + +func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddObject((string)(k), v) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.BoolValue != nil { + enc.AddBool("boolValue", *v.BoolValue) + } + + if v.Int64Value != nil { + enc.AddInt64("int64Value", *v.Int64Value) + } + + if v.StringValue != nil { + enc.AddString("stringValue", *v.StringValue) + } + + if v.ListValue != nil { + enc.AddArray("listValue", (_List_ArbitraryValue_Zapper)(v.ListValue)) + } + + if v.MapValue != nil { + enc.AddObject("mapValue", (_Map_String_ArbitraryValue_Zapper)(v.MapValue)) + } + + return nil +} + // GetBoolValue returns the value of BoolValue if it is set or its // zero value if it is unset. func (v *ArbitraryValue) GetBoolValue() (o bool) { @@ -651,6 +697,20 @@ func (v *Document) Equals(rhs *Document) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Document) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Pdf != nil { + enc.AddString("pdf", base64.StdEncoding.EncodeToString(([]byte)(v.Pdf))) + } + + if v.PlainText != nil { + enc.AddString("plainText", *v.PlainText) + } + + return nil +} + // GetPdf returns the value of Pdf if it is set or its // zero value if it is unset. func (v *Document) GetPdf() (o typedefs.PDF) { @@ -746,3 +806,9 @@ func (v *EmptyUnion) Equals(rhs *EmptyUnion) bool { return true } + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *EmptyUnion) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} diff --git a/gen/enum.go b/gen/enum.go index fbca8449..844faa2a 100644 --- a/gen/enum.go +++ b/gen/enum.go @@ -125,6 +125,22 @@ func enum(g Generator, spec *compile.EnumSpec) error { return []byte(<$strconv>.FormatInt(int64(<$v>), 10)), nil } + <$zapcore := import "go.uber.org/zap/zapcore"> + + // TODO() + func (<$v> <$enumName>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { + enc.AddInt32("value", int32(<$v>)) + + switch int32(<$v>) { + + case <.Value>: + enc.AddString("name", "<.Name>") + + } + + return nil + } + // Ptr returns a pointer to this enum value. func (<$v> <$enumName>) Ptr() *<$enumName> { return &<$v> diff --git a/gen/field.go b/gen/field.go index c1a50367..6c4c9916 100644 --- a/gen/field.go +++ b/gen/field.go @@ -91,6 +91,10 @@ func (f fieldGroupGenerator) Generate(g Generator) error { return err } + if err := f.Zap(g); err != nil { + return err + } + return f.Accessors(g) } @@ -461,6 +465,31 @@ func (f fieldGroupGenerator) Equals(g Generator) error { `, f) } +func (f fieldGroupGenerator) Zap(g Generator) error { + return g.DeclareFromTemplate( + ` + <$zapcore := import "go.uber.org/zap/zapcore"> + <$v := newVar "v"> + // TODO(minho): Make enc a newVar. + + // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) + func (<$v> *<.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { + + <$fname := goName .> + <$fval := printf "%s.%s" $v $fname> + <- if .Required -> + enc.Add("<.Name>", ) + <- else -> + if <$fval> != nil { + enc.Add("<.Name>", ) + } + <- end> + + return nil + } + `, f) +} + func (f fieldGroupGenerator) Accessors(g Generator) error { fieldsAndAccessors := NewNamespace() return g.DeclareFromTemplate( diff --git a/gen/generator.go b/gen/generator.go index fb70ee7e..a08516bc 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -196,25 +196,29 @@ func (g *generator) LookupConstantName(c *compile.Constant) (string, error) { // TextTemplate renders the given template with the given template context. func (g *generator) TextTemplate(s string, data interface{}, opts ...TemplateOption) (string, error) { templateFuncs := template.FuncMap{ - "formatDoc": formatDoc, - "goCase": goCase, - "goName": goName, - "import": g.Import, - "isHashable": isHashable, - "isPrimitiveType": isPrimitiveType, - "isStructType": isStructType, - "newNamespace": g.Namespace.Child, - "newVar": g.Namespace.Child().NewName, - "typeName": curryGenerator(typeName, g), - "typeReference": curryGenerator(typeReference, g), - "typeReferencePtr": curryGenerator(typeReferencePtr, g), - "fromWire": curryGenerator(g.w.FromWire, g), - "fromWirePtr": curryGenerator(g.w.FromWirePtr, g), - "toWire": curryGenerator(g.w.ToWire, g), - "toWirePtr": curryGenerator(g.w.ToWirePtr, g), - "typeCode": curryGenerator(TypeCode, g), - "equals": curryGenerator(g.e.Equals, g), - "equalsPtr": curryGenerator(g.e.EqualsPtr, g), + "formatDoc": formatDoc, + "goCase": goCase, + "goName": goName, + "import": g.Import, + "isHashable": isHashable, + "isPrimitiveType": isPrimitiveType, + "isStructType": isStructType, + "newNamespace": g.Namespace.Child, + "newVar": g.Namespace.Child().NewName, + "typeName": curryGenerator(typeName, g), + "typeReference": curryGenerator(typeReference, g), + "typeReferencePtr": curryGenerator(typeReferencePtr, g), + "fromWire": curryGenerator(g.w.FromWire, g), + "fromWirePtr": curryGenerator(g.w.FromWirePtr, g), + "toWire": curryGenerator(g.w.ToWire, g), + "toWirePtr": curryGenerator(g.w.ToWirePtr, g), + "typeCode": curryGenerator(TypeCode, g), + "equals": curryGenerator(g.e.Equals, g), + "equalsPtr": curryGenerator(g.e.EqualsPtr, g), + "zapEncoder": curryGenerator(zapEncoder, g), + "zapMarshaler": curryGenerator(zapMarshaler, g), + "zapMarshalerPtr": curryGenerator(zapMarshalerPtr, g), + "zapMapItemMarshaler": curryGenerator(zapMapItemMarshaler, g), } tmpl := template.New("thriftrw").Delims("<", ">").Funcs(templateFuncs) diff --git a/gen/internal/tests/collision/types.go b/gen/internal/tests/collision/types.go index 84d02d06..641674bf 100644 --- a/gen/internal/tests/collision/types.go +++ b/gen/internal/tests/collision/types.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "math" "strconv" "strings" @@ -156,6 +157,20 @@ func (v *AccessorConflict) Equals(rhs *AccessorConflict) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *AccessorConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Name != nil { + enc.AddString("name", *v.Name) + } + + if v.GetName2 != nil { + enc.AddString("get_name", *v.GetName2) + } + + return nil +} + // GetName returns the value of Name if it is set or its // zero value if it is unset. func (v *AccessorConflict) GetName() (o string) { @@ -308,6 +323,20 @@ func (v *AccessorNoConflict) Equals(rhs *AccessorNoConflict) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *AccessorNoConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Getname != nil { + enc.AddString("getname", *v.Getname) + } + + if v.GetName != nil { + enc.AddString("get_name", *v.GetName) + } + + return nil +} + // GetGetname returns the value of Getname if it is set or its // zero value if it is unset. func (v *AccessorNoConflict) GetGetname() (o string) { @@ -429,6 +458,24 @@ func (v MyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v MyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 123: + enc.AddString("name", "X") + case 456: + enc.AddString("name", "Y") + case 789: + enc.AddString("name", "Z") + case 790: + enc.AddString("name", "FooBar") + case 791: + enc.AddString("name", "foo_bar") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v MyEnum) Ptr() *MyEnum { return &v @@ -893,6 +940,52 @@ func (v *PrimitiveContainers) Equals(rhs *PrimitiveContainers) bool { return true } +type _List_String_Zapper []string + +func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendString(val) + } + return nil +} + +type _Set_String_Zapper map[string]struct{} + +func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range vals { + + enc.AppendString(v) + } + return nil +} + +type _Map_String_String_Zapper map[string]string + +func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddString((string)(k), v) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.A != nil { + enc.AddArray("ListOrSetOrMap", (_List_String_Zapper)(v.A)) + } + + if v.B != nil { + enc.AddArray("List_Or_SetOrMap", (_Set_String_Zapper)(v.B)) + } + + if v.C != nil { + enc.AddObject("ListOrSet_Or_Map", (_Map_String_String_Zapper)(v.C)) + } + + return nil +} + // GetA returns the value of A if it is set or its // zero value if it is unset. func (v *PrimitiveContainers) GetA() (o []string) { @@ -1055,6 +1148,16 @@ func (v *StructCollision) Equals(rhs *StructCollision) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *StructCollision) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddBool("collisionField", v.CollisionField) + + enc.AddString("collision_field", v.CollisionField2) + + return nil +} + // GetCollisionField returns the value of CollisionField if it is set or its // zero value if it is unset. func (v *StructCollision) GetCollisionField() (o bool) { return v.CollisionField } @@ -1220,6 +1323,20 @@ func (v *UnionCollision) Equals(rhs *UnionCollision) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *UnionCollision) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.CollisionField != nil { + enc.AddBool("collisionField", *v.CollisionField) + } + + if v.CollisionField2 != nil { + enc.AddString("collision_field", *v.CollisionField2) + } + + return nil +} + // GetCollisionField returns the value of CollisionField if it is set or its // zero value if it is unset. func (v *UnionCollision) GetCollisionField() (o bool) { @@ -1363,6 +1480,16 @@ func (v *WithDefault) Equals(rhs *WithDefault) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *WithDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Pouet != nil { + enc.AddObject("pouet", v.Pouet) + } + + return nil +} + // GetPouet returns the value of Pouet if it is set or its // default value if it is unset. func (v *WithDefault) GetPouet() (o *StructCollision2) { @@ -1463,6 +1590,20 @@ func (v MyEnum2) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v MyEnum2) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 12: + enc.AddString("name", "X") + case 34: + enc.AddString("name", "Y") + case 56: + enc.AddString("name", "Z") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v MyEnum2) Ptr() *MyEnum2 { return &v @@ -1701,6 +1842,16 @@ func (v *StructCollision2) Equals(rhs *StructCollision2) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *StructCollision2) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddBool("collisionField", v.CollisionField) + + enc.AddString("collision_field", v.CollisionField2) + + return nil +} + // GetCollisionField returns the value of CollisionField if it is set or its // zero value if it is unset. func (v *StructCollision2) GetCollisionField() (o bool) { return v.CollisionField } @@ -1856,6 +2007,20 @@ func (v *UnionCollision2) Equals(rhs *UnionCollision2) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *UnionCollision2) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.CollisionField != nil { + enc.AddBool("collisionField", *v.CollisionField) + } + + if v.CollisionField2 != nil { + enc.AddString("collision_field", *v.CollisionField2) + } + + return nil +} + // GetCollisionField returns the value of CollisionField if it is set or its // zero value if it is unset. func (v *UnionCollision2) GetCollisionField() (o bool) { diff --git a/gen/internal/tests/containers/types.go b/gen/internal/tests/containers/types.go index 1fec0906..0a8c855c 100644 --- a/gen/internal/tests/containers/types.go +++ b/gen/internal/tests/containers/types.go @@ -5,6 +5,7 @@ package containers import ( "bytes" + "encoding/base64" "errors" "fmt" "go.uber.org/thriftrw/gen/internal/tests/enum_conflict" @@ -12,6 +13,7 @@ import ( "go.uber.org/thriftrw/gen/internal/tests/typedefs" "go.uber.org/thriftrw/gen/internal/tests/uuid_conflict" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -1652,6 +1654,275 @@ func (v *ContainersOfContainers) Equals(rhs *ContainersOfContainers) bool { return true } +type _List_I32_Zapper []int32 + +func (vals _List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendInt32(val) + } + return nil +} + +type _List_List_I32_Zapper [][]int32 + +func (vals _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendArray((_List_I32_Zapper)(val)) + } + return nil +} + +type _Set_I32_Zapper map[int32]struct{} + +func (vals _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range vals { + + enc.AppendInt32(v) + } + return nil +} + +type _List_Set_I32_Zapper []map[int32]struct{} + +func (vals _List_Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendArray((_Set_I32_Zapper)(val)) + } + return nil +} + +type _MapItem_I32_I32_Zapper struct { + Key int32 + Value int32 +} + +func (v _MapItem_I32_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("key", v.Key) + enc.AddInt32("value", v.Value) + return nil +} + +type _Map_I32_I32_Zapper map[int32]int32 + +func (keyvals _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range keyvals { + enc.AppendObject(_MapItem_I32_I32_Zapper{Key: k, Value: v}) + } + return nil +} + +type _List_Map_I32_I32_Zapper []map[int32]int32 + +func (vals _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendArray((_Map_I32_I32_Zapper)(val)) + } + return nil +} + +type _Set_String_Zapper map[string]struct{} + +func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range vals { + + enc.AppendString(v) + } + return nil +} + +type _Set_Set_String_Zapper []map[string]struct{} + +func (vals _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range vals { + + enc.AppendArray((_Set_String_Zapper)(v)) + } + return nil +} + +type _List_String_Zapper []string + +func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendString(val) + } + return nil +} + +type _Set_List_String_Zapper [][]string + +func (vals _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range vals { + + enc.AppendArray((_List_String_Zapper)(v)) + } + return nil +} + +type _Map_String_String_Zapper map[string]string + +func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddString((string)(k), v) + } + return nil +} + +type _Set_Map_String_String_Zapper []map[string]string + +func (vals _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range vals { + + enc.AppendObject((_Map_String_String_Zapper)(v)) + } + return nil +} + +type _Map_String_I32_Zapper map[string]int32 + +func (keyvals _Map_String_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddInt32((string)(k), v) + } + return nil +} + +type _MapItem_Map_String_I32_I64_Zapper struct { + Key map[string]int32 + Value int64 +} + +func (v _MapItem_Map_String_I32_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddObject("key", (_Map_String_I32_Zapper)(v.Key)) + enc.AddInt64("value", v.Value) + return nil +} + +type _Map_Map_String_I32_I64_Zapper []struct { + Key map[string]int32 + Value int64 +} + +func (keyvals _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range keyvals { + k := i.Key + v := i.Value + enc.AppendObject(_MapItem_Map_String_I32_I64_Zapper{Key: k, Value: v}) + } + return nil +} + +type _Set_I64_Zapper map[int64]struct{} + +func (vals _Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range vals { + + enc.AppendInt64(v) + } + return nil +} + +type _MapItem_List_I32_Set_I64_Zapper struct { + Key []int32 + Value map[int64]struct{} +} + +func (v _MapItem_List_I32_Set_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddArray("key", (_List_I32_Zapper)(v.Key)) + enc.AddArray("value", (_Set_I64_Zapper)(v.Value)) + return nil +} + +type _Map_List_I32_Set_I64_Zapper []struct { + Key []int32 + Value map[int64]struct{} +} + +func (keyvals _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range keyvals { + k := i.Key + v := i.Value + enc.AppendObject(_MapItem_List_I32_Set_I64_Zapper{Key: k, Value: v}) + } + return nil +} + +type _List_Double_Zapper []float64 + +func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendFloat64(val) + } + return nil +} + +type _MapItem_Set_I32_List_Double_Zapper struct { + Key map[int32]struct{} + Value []float64 +} + +func (v _MapItem_Set_I32_List_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddArray("key", (_Set_I32_Zapper)(v.Key)) + enc.AddArray("value", (_List_Double_Zapper)(v.Value)) + return nil +} + +type _Map_Set_I32_List_Double_Zapper []struct { + Key map[int32]struct{} + Value []float64 +} + +func (keyvals _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range keyvals { + k := i.Key + v := i.Value + enc.AppendObject(_MapItem_Set_I32_List_Double_Zapper{Key: k, Value: v}) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ContainersOfContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.ListOfLists != nil { + enc.AddArray("listOfLists", (_List_List_I32_Zapper)(v.ListOfLists)) + } + + if v.ListOfSets != nil { + enc.AddArray("listOfSets", (_List_Set_I32_Zapper)(v.ListOfSets)) + } + + if v.ListOfMaps != nil { + enc.AddArray("listOfMaps", (_List_Map_I32_I32_Zapper)(v.ListOfMaps)) + } + + if v.SetOfSets != nil { + enc.AddArray("setOfSets", (_Set_Set_String_Zapper)(v.SetOfSets)) + } + + if v.SetOfLists != nil { + enc.AddArray("setOfLists", (_Set_List_String_Zapper)(v.SetOfLists)) + } + + if v.SetOfMaps != nil { + enc.AddArray("setOfMaps", (_Set_Map_String_String_Zapper)(v.SetOfMaps)) + } + + if v.MapOfMapToInt != nil { + enc.AddArray("mapOfMapToInt", (_Map_Map_String_I32_I64_Zapper)(v.MapOfMapToInt)) + } + + if v.MapOfListToSet != nil { + enc.AddArray("mapOfListToSet", (_Map_List_I32_Set_I64_Zapper)(v.MapOfListToSet)) + } + + if v.MapOfSetToListOfDouble != nil { + enc.AddArray("mapOfSetToListOfDouble", (_Map_Set_I32_List_Double_Zapper)(v.MapOfSetToListOfDouble)) + } + + return nil +} + // GetListOfLists returns the value of ListOfLists if it is set or its // zero value if it is unset. func (v *ContainersOfContainers) GetListOfLists() (o [][]int32) { @@ -2119,6 +2390,63 @@ func (v *EnumContainers) Equals(rhs *EnumContainers) bool { return true } +type _List_EnumDefault_Zapper []enums.EnumDefault + +func (vals _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +type _Set_EnumWithValues_Zapper map[enums.EnumWithValues]struct{} + +func (vals _Set_EnumWithValues_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range vals { + + enc.AppendObject(v) + } + return nil +} + +type _MapItem_EnumWithDuplicateValues_I32_Zapper struct { + Key enums.EnumWithDuplicateValues + Value int32 +} + +func (v _MapItem_EnumWithDuplicateValues_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddObject("key", v.Key) + enc.AddInt32("value", v.Value) + return nil +} + +type _Map_EnumWithDuplicateValues_I32_Zapper map[enums.EnumWithDuplicateValues]int32 + +func (keyvals _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range keyvals { + enc.AppendObject(_MapItem_EnumWithDuplicateValues_I32_Zapper{Key: k, Value: v}) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *EnumContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.ListOfEnums != nil { + enc.AddArray("listOfEnums", (_List_EnumDefault_Zapper)(v.ListOfEnums)) + } + + if v.SetOfEnums != nil { + enc.AddArray("setOfEnums", (_Set_EnumWithValues_Zapper)(v.SetOfEnums)) + } + + if v.MapOfEnums != nil { + enc.AddArray("mapOfEnums", (_Map_EnumWithDuplicateValues_I32_Zapper)(v.MapOfEnums)) + } + + return nil +} + // GetListOfEnums returns the value of ListOfEnums if it is set or its // zero value if it is unset. func (v *EnumContainers) GetListOfEnums() (o []enums.EnumDefault) { @@ -2416,6 +2744,34 @@ func (v *ListOfConflictingEnums) Equals(rhs *ListOfConflictingEnums) bool { return true } +type _List_RecordType_Zapper []enum_conflict.RecordType + +func (vals _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +type _List_RecordType_1_Zapper []enums.RecordType + +func (vals _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ListOfConflictingEnums) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddArray("records", (_List_RecordType_Zapper)(v.Records)) + + enc.AddArray("otherRecords", (_List_RecordType_1_Zapper)(v.OtherRecords)) + + return nil +} + // GetRecords returns the value of Records if it is set or its // zero value if it is unset. func (v *ListOfConflictingEnums) GetRecords() (o []enum_conflict.RecordType) { return v.Records } @@ -2694,6 +3050,34 @@ func (v *ListOfConflictingUUIDs) Equals(rhs *ListOfConflictingUUIDs) bool { return true } +type _List_UUID_Zapper []*typedefs.UUID + +func (vals _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject((*typedefs.I128)(val)) + } + return nil +} + +type _List_UUID_1_Zapper []uuid_conflict.UUID + +func (vals _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendString((string)(val)) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ListOfConflictingUUIDs) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddArray("uuids", (_List_UUID_Zapper)(v.Uuids)) + + enc.AddArray("otherUUIDs", (_List_UUID_1_Zapper)(v.OtherUUIDs)) + + return nil +} + // GetUuids returns the value of Uuids if it is set or its // zero value if it is unset. func (v *ListOfConflictingUUIDs) GetUuids() (o []*typedefs.UUID) { return v.Uuids } @@ -3029,6 +3413,54 @@ func (v *MapOfBinaryAndString) Equals(rhs *MapOfBinaryAndString) bool { return true } +type _MapItem_Binary_String_Zapper struct { + Key []byte + Value string +} + +func (v _MapItem_Binary_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddString("key", base64.StdEncoding.EncodeToString(v.Key)) + enc.AddString("value", v.Value) + return nil +} + +type _Map_Binary_String_Zapper []struct { + Key []byte + Value string +} + +func (keyvals _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range keyvals { + k := i.Key + v := i.Value + enc.AppendObject(_MapItem_Binary_String_Zapper{Key: k, Value: v}) + } + return nil +} + +type _Map_String_Binary_Zapper map[string][]byte + +func (keyvals _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddString((string)(k), base64.StdEncoding.EncodeToString(v)) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *MapOfBinaryAndString) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.BinaryToString != nil { + enc.AddArray("binaryToString", (_Map_Binary_String_Zapper)(v.BinaryToString)) + } + + if v.StringToBinary != nil { + enc.AddObject("stringToBinary", (_Map_String_Binary_Zapper)(v.StringToBinary)) + } + + return nil +} + // GetBinaryToString returns the value of BinaryToString if it is set or its // zero value if it is unset. func (v *MapOfBinaryAndString) GetBinaryToString() (o []struct { @@ -3616,6 +4048,93 @@ func (v *PrimitiveContainers) Equals(rhs *PrimitiveContainers) bool { return true } +type _List_Binary_Zapper [][]byte + +func (vals _List_Binary_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendString(base64.StdEncoding.EncodeToString(val)) + } + return nil +} + +type _List_I64_Zapper []int64 + +func (vals _List_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendInt64(val) + } + return nil +} + +type _Set_Byte_Zapper map[int8]struct{} + +func (vals _Set_Byte_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range vals { + + enc.AppendInt8(v) + } + return nil +} + +type _MapItem_I32_String_Zapper struct { + Key int32 + Value string +} + +func (v _MapItem_I32_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("key", v.Key) + enc.AddString("value", v.Value) + return nil +} + +type _Map_I32_String_Zapper map[int32]string + +func (keyvals _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range keyvals { + enc.AppendObject(_MapItem_I32_String_Zapper{Key: k, Value: v}) + } + return nil +} + +type _Map_String_Bool_Zapper map[string]bool + +func (keyvals _Map_String_Bool_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddBool((string)(k), v) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.ListOfBinary != nil { + enc.AddArray("listOfBinary", (_List_Binary_Zapper)(v.ListOfBinary)) + } + + if v.ListOfInts != nil { + enc.AddArray("listOfInts", (_List_I64_Zapper)(v.ListOfInts)) + } + + if v.SetOfStrings != nil { + enc.AddArray("setOfStrings", (_Set_String_Zapper)(v.SetOfStrings)) + } + + if v.SetOfBytes != nil { + enc.AddArray("setOfBytes", (_Set_Byte_Zapper)(v.SetOfBytes)) + } + + if v.MapOfIntToString != nil { + enc.AddArray("mapOfIntToString", (_Map_I32_String_Zapper)(v.MapOfIntToString)) + } + + if v.MapOfStringToBool != nil { + enc.AddObject("mapOfStringToBool", (_Map_String_Bool_Zapper)(v.MapOfStringToBool)) + } + + return nil +} + // GetListOfBinary returns the value of ListOfBinary if it is set or its // zero value if it is unset. func (v *PrimitiveContainers) GetListOfBinary() (o [][]byte) { @@ -3921,6 +4440,38 @@ func (v *PrimitiveContainersRequired) Equals(rhs *PrimitiveContainersRequired) b return true } +type _MapItem_I64_Double_Zapper struct { + Key int64 + Value float64 +} + +func (v _MapItem_I64_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt64("key", v.Key) + enc.AddFloat64("value", v.Value) + return nil +} + +type _Map_I64_Double_Zapper map[int64]float64 + +func (keyvals _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range keyvals { + enc.AppendObject(_MapItem_I64_Double_Zapper{Key: k, Value: v}) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *PrimitiveContainersRequired) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddArray("listOfStrings", (_List_String_Zapper)(v.ListOfStrings)) + + enc.AddArray("setOfInts", (_Set_I32_Zapper)(v.SetOfInts)) + + enc.AddArray("mapOfIntsToDoubles", (_Map_I64_Double_Zapper)(v.MapOfIntsToDoubles)) + + return nil +} + // GetListOfStrings returns the value of ListOfStrings if it is set or its // zero value if it is unset. func (v *PrimitiveContainersRequired) GetListOfStrings() (o []string) { return v.ListOfStrings } diff --git a/gen/internal/tests/enum_conflict/types.go b/gen/internal/tests/enum_conflict/types.go index ecd10d2b..b3a78735 100644 --- a/gen/internal/tests/enum_conflict/types.go +++ b/gen/internal/tests/enum_conflict/types.go @@ -9,6 +9,7 @@ import ( "fmt" "go.uber.org/thriftrw/gen/internal/tests/enums" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "math" "strconv" "strings" @@ -63,6 +64,18 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "Name") + case 1: + enc.AddString("name", "Email") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v RecordType) Ptr() *RecordType { return &v @@ -351,6 +364,20 @@ func (v *Records) Equals(rhs *Records) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Records) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.RecordType != nil { + enc.AddObject("recordType", *v.RecordType) + } + + if v.OtherRecordType != nil { + enc.AddObject("otherRecordType", *v.OtherRecordType) + } + + return nil +} + // GetRecordType returns the value of RecordType if it is set or its // default value if it is unset. func (v *Records) GetRecordType() (o RecordType) { diff --git a/gen/internal/tests/enums/types.go b/gen/internal/tests/enums/types.go index bd2c7650..bd1efd2c 100644 --- a/gen/internal/tests/enums/types.go +++ b/gen/internal/tests/enums/types.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "math" "strconv" "strings" @@ -34,6 +35,12 @@ func (v EmptyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EmptyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + return nil +} + // Ptr returns a pointer to this enum value. func (v EmptyEnum) Ptr() *EmptyEnum { return &v @@ -180,6 +187,20 @@ func (v EnumDefault) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EnumDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "Foo") + case 1: + enc.AddString("name", "Bar") + case 2: + enc.AddString("name", "Baz") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v EnumDefault) Ptr() *EnumDefault { return &v @@ -384,6 +405,32 @@ func (v EnumWithDuplicateName) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EnumWithDuplicateName) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "A") + case 1: + enc.AddString("name", "B") + case 2: + enc.AddString("name", "C") + case 3: + enc.AddString("name", "P") + case 4: + enc.AddString("name", "Q") + case 5: + enc.AddString("name", "R") + case 6: + enc.AddString("name", "X") + case 7: + enc.AddString("name", "Y") + case 8: + enc.AddString("name", "Z") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v EnumWithDuplicateName) Ptr() *EnumWithDuplicateName { return &v @@ -568,6 +615,18 @@ func (v EnumWithDuplicateValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EnumWithDuplicateValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "P") + case -1: + enc.AddString("name", "Q") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v EnumWithDuplicateValues) Ptr() *EnumWithDuplicateValues { return &v @@ -726,6 +785,20 @@ func (v EnumWithValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v EnumWithValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 123: + enc.AddString("name", "X") + case 456: + enc.AddString("name", "Y") + case 789: + enc.AddString("name", "Z") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v EnumWithValues) Ptr() *EnumWithValues { return &v @@ -896,6 +969,20 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "NAME") + case 1: + enc.AddString("name", "HOME_ADDRESS") + case 2: + enc.AddString("name", "WORK_ADDRESS") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v RecordType) Ptr() *RecordType { return &v @@ -1051,6 +1138,18 @@ func (v RecordTypeValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v RecordTypeValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "FOO") + case 1: + enc.AddString("name", "BAR") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v RecordTypeValues) Ptr() *RecordTypeValues { return &v @@ -1275,6 +1374,16 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.E != nil { + enc.AddObject("e", *v.E) + } + + return nil +} + // GetE returns the value of E if it is set or its // zero value if it is unset. func (v *StructWithOptionalEnum) GetE() (o EnumDefault) { @@ -1341,6 +1450,20 @@ func (v LowerCaseEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v LowerCaseEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "containing") + case 1: + enc.AddString("name", "lower_case") + case 2: + enc.AddString("name", "items") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v LowerCaseEnum) Ptr() *LowerCaseEnum { return &v diff --git a/gen/internal/tests/exceptions/types.go b/gen/internal/tests/exceptions/types.go index 973600ca..27a164d1 100644 --- a/gen/internal/tests/exceptions/types.go +++ b/gen/internal/tests/exceptions/types.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -154,6 +155,18 @@ func (v *DoesNotExistException) Equals(rhs *DoesNotExistException) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *DoesNotExistException) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("key", v.Key) + + if v.Error2 != nil { + enc.AddString("Error", *v.Error2) + } + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *DoesNotExistException) GetKey() (o string) { return v.Key } @@ -248,6 +261,12 @@ func (v *EmptyException) Equals(rhs *EmptyException) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *EmptyException) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + func (v *EmptyException) Error() string { return v.String() } diff --git a/gen/internal/tests/services/cache_clear.go b/gen/internal/tests/services/cache_clear.go index b502d4cb..ba96159e 100644 --- a/gen/internal/tests/services/cache_clear.go +++ b/gen/internal/tests/services/cache_clear.go @@ -6,6 +6,7 @@ package services import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -88,6 +89,12 @@ func (v *Cache_Clear_Args) Equals(rhs *Cache_Clear_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Cache_Clear_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the arguments. // diff --git a/gen/internal/tests/services/cache_clearafter.go b/gen/internal/tests/services/cache_clearafter.go index 8f2e912a..c41302ab 100644 --- a/gen/internal/tests/services/cache_clearafter.go +++ b/gen/internal/tests/services/cache_clearafter.go @@ -6,6 +6,7 @@ package services import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -128,6 +129,16 @@ func (v *Cache_ClearAfter_Args) Equals(rhs *Cache_ClearAfter_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Cache_ClearAfter_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.DurationMS != nil { + enc.AddInt64("durationMS", *v.DurationMS) + } + + return nil +} + // GetDurationMS returns the value of DurationMS if it is set or its // zero value if it is unset. func (v *Cache_ClearAfter_Args) GetDurationMS() (o int64) { diff --git a/gen/internal/tests/services/conflictingnames_setvalue.go b/gen/internal/tests/services/conflictingnames_setvalue.go index b77f78e9..1bd5f879 100644 --- a/gen/internal/tests/services/conflictingnames_setvalue.go +++ b/gen/internal/tests/services/conflictingnames_setvalue.go @@ -6,6 +6,7 @@ package services import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -122,6 +123,16 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Request != nil { + enc.AddObject("request", v.Request) + } + + return nil +} + // GetRequest returns the value of Request if it is set or its // zero value if it is unset. func (v *ConflictingNames_SetValue_Args) GetRequest() (o *ConflictingNamesSetValueArgs) { @@ -301,6 +312,12 @@ func (v *ConflictingNames_SetValue_Result) Equals(rhs *ConflictingNames_SetValue return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ConflictingNames_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/gen/internal/tests/services/keyvalue_deletevalue.go b/gen/internal/tests/services/keyvalue_deletevalue.go index 55d6dad6..dbd99df5 100644 --- a/gen/internal/tests/services/keyvalue_deletevalue.go +++ b/gen/internal/tests/services/keyvalue_deletevalue.go @@ -8,6 +8,7 @@ import ( "fmt" "go.uber.org/thriftrw/gen/internal/tests/exceptions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -136,6 +137,16 @@ func (v *KeyValue_DeleteValue_Args) Equals(rhs *KeyValue_DeleteValue_Args) bool return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_DeleteValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Key != nil { + enc.AddString("key", (string)(*v.Key)) + } + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *KeyValue_DeleteValue_Args) GetKey() (o Key) { @@ -420,6 +431,20 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.DoesNotExist != nil { + enc.AddObject("doesNotExist", v.DoesNotExist) + } + + if v.InternalError != nil { + enc.AddObject("internalError", v.InternalError) + } + + return nil +} + // GetDoesNotExist returns the value of DoesNotExist if it is set or its // zero value if it is unset. func (v *KeyValue_DeleteValue_Result) GetDoesNotExist() (o *exceptions.DoesNotExistException) { diff --git a/gen/internal/tests/services/keyvalue_getmanyvalues.go b/gen/internal/tests/services/keyvalue_getmanyvalues.go index 8a73ecc8..63102e3a 100644 --- a/gen/internal/tests/services/keyvalue_getmanyvalues.go +++ b/gen/internal/tests/services/keyvalue_getmanyvalues.go @@ -9,6 +9,7 @@ import ( "go.uber.org/thriftrw/gen/internal/tests/exceptions" "go.uber.org/thriftrw/gen/internal/tests/unions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -178,6 +179,25 @@ func (v *KeyValue_GetManyValues_Args) Equals(rhs *KeyValue_GetManyValues_Args) b return true } +type _List_Key_Zapper []Key + +func (vals _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendString((string)(val)) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Range != nil { + enc.AddArray("range", (_List_Key_Zapper)(v.Range)) + } + + return nil +} + // GetRange returns the value of Range if it is set or its // zero value if it is unset. func (v *KeyValue_GetManyValues_Args) GetRange() (o []Key) { @@ -515,6 +535,29 @@ func (v *KeyValue_GetManyValues_Result) Equals(rhs *KeyValue_GetManyValues_Resul return true } +type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue + +func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Success != nil { + enc.AddArray("success", (_List_ArbitraryValue_Zapper)(v.Success)) + } + + if v.DoesNotExist != nil { + enc.AddObject("doesNotExist", v.DoesNotExist) + } + + return nil +} + // GetSuccess returns the value of Success if it is set or its // zero value if it is unset. func (v *KeyValue_GetManyValues_Result) GetSuccess() (o []*unions.ArbitraryValue) { diff --git a/gen/internal/tests/services/keyvalue_getvalue.go b/gen/internal/tests/services/keyvalue_getvalue.go index aa10142c..945093fc 100644 --- a/gen/internal/tests/services/keyvalue_getvalue.go +++ b/gen/internal/tests/services/keyvalue_getvalue.go @@ -9,6 +9,7 @@ import ( "go.uber.org/thriftrw/gen/internal/tests/exceptions" "go.uber.org/thriftrw/gen/internal/tests/unions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -121,6 +122,16 @@ func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Key != nil { + enc.AddString("key", (string)(*v.Key)) + } + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *KeyValue_GetValue_Args) GetKey() (o Key) { @@ -390,6 +401,20 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Success != nil { + enc.AddObject("success", v.Success) + } + + if v.DoesNotExist != nil { + enc.AddObject("doesNotExist", v.DoesNotExist) + } + + return nil +} + // GetSuccess returns the value of Success if it is set or its // zero value if it is unset. func (v *KeyValue_GetValue_Result) GetSuccess() (o *unions.ArbitraryValue) { diff --git a/gen/internal/tests/services/keyvalue_setvalue.go b/gen/internal/tests/services/keyvalue_setvalue.go index 95cb424a..5e98aec2 100644 --- a/gen/internal/tests/services/keyvalue_setvalue.go +++ b/gen/internal/tests/services/keyvalue_setvalue.go @@ -7,6 +7,7 @@ import ( "fmt" "go.uber.org/thriftrw/gen/internal/tests/unions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -143,6 +144,20 @@ func (v *KeyValue_SetValue_Args) Equals(rhs *KeyValue_SetValue_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Key != nil { + enc.AddString("key", (string)(*v.Key)) + } + + if v.Value != nil { + enc.AddObject("value", v.Value) + } + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *KeyValue_SetValue_Args) GetKey() (o Key) { @@ -335,6 +350,12 @@ func (v *KeyValue_SetValue_Result) Equals(rhs *KeyValue_SetValue_Result) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/gen/internal/tests/services/keyvalue_setvaluev2.go b/gen/internal/tests/services/keyvalue_setvaluev2.go index a2fb7009..07f87201 100644 --- a/gen/internal/tests/services/keyvalue_setvaluev2.go +++ b/gen/internal/tests/services/keyvalue_setvaluev2.go @@ -8,6 +8,7 @@ import ( "fmt" "go.uber.org/thriftrw/gen/internal/tests/unions" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -152,6 +153,16 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("key", (string)(v.Key)) + + enc.AddObject("value", v.Value) + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *KeyValue_SetValueV2_Args) GetKey() (o Key) { return v.Key } @@ -332,6 +343,12 @@ func (v *KeyValue_SetValueV2_Result) Equals(rhs *KeyValue_SetValueV2_Result) boo return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_SetValueV2_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/gen/internal/tests/services/keyvalue_size.go b/gen/internal/tests/services/keyvalue_size.go index 228e98e3..b88793b7 100644 --- a/gen/internal/tests/services/keyvalue_size.go +++ b/gen/internal/tests/services/keyvalue_size.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -89,6 +90,12 @@ func (v *KeyValue_Size_Args) Equals(rhs *KeyValue_Size_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_Size_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the arguments. // @@ -303,6 +310,16 @@ func (v *KeyValue_Size_Result) Equals(rhs *KeyValue_Size_Result) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *KeyValue_Size_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Success != nil { + enc.AddInt64("success", *v.Success) + } + + return nil +} + // GetSuccess returns the value of Success if it is set or its // zero value if it is unset. func (v *KeyValue_Size_Result) GetSuccess() (o int64) { diff --git a/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go b/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go index 840613ad..f34ee6c5 100644 --- a/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go +++ b/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go @@ -6,6 +6,7 @@ package services import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -88,6 +89,12 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Args) Equals(rhs *NonSta return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *NonStandardServiceName_NonStandardFunctionName_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the arguments. // @@ -251,6 +258,12 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Result) Equals(rhs *NonS return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *NonStandardServiceName_NonStandardFunctionName_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/gen/internal/tests/services/types.go b/gen/internal/tests/services/types.go index c17c1ed3..2283fb97 100644 --- a/gen/internal/tests/services/types.go +++ b/gen/internal/tests/services/types.go @@ -5,9 +5,11 @@ package services import ( "bytes" + "encoding/base64" "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -145,6 +147,16 @@ func (v *ConflictingNamesSetValueArgs) Equals(rhs *ConflictingNamesSetValueArgs) return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ConflictingNamesSetValueArgs) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("key", v.Key) + + enc.AddString("value", base64.StdEncoding.EncodeToString(v.Value)) + + return nil +} + // GetKey returns the value of Key if it is set or its // zero value if it is unset. func (v *ConflictingNamesSetValueArgs) GetKey() (o string) { return v.Key } @@ -269,6 +281,16 @@ func (v *InternalError) Equals(rhs *InternalError) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *InternalError) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Message != nil { + enc.AddString("message", *v.Message) + } + + return nil +} + // GetMessage returns the value of Message if it is set or its // zero value if it is unset. func (v *InternalError) GetMessage() (o string) { diff --git a/gen/internal/tests/structs/types.go b/gen/internal/tests/structs/types.go index 361ef83b..515bb0be 100644 --- a/gen/internal/tests/structs/types.go +++ b/gen/internal/tests/structs/types.go @@ -5,11 +5,13 @@ package structs import ( "bytes" + "encoding/base64" "errors" "fmt" "go.uber.org/thriftrw/gen/internal/tests/enums" "go.uber.org/thriftrw/ptr" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -119,6 +121,14 @@ func (v *ContactInfo) Equals(rhs *ContactInfo) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ContactInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("emailAddress", v.EmailAddress) + + return nil +} + // GetEmailAddress returns the value of EmailAddress if it is set or its // zero value if it is unset. func (v *ContactInfo) GetEmailAddress() (o string) { return v.EmailAddress } @@ -669,6 +679,62 @@ func (v *DefaultsStruct) Equals(rhs *DefaultsStruct) bool { return true } +type _List_String_Zapper []string + +func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendString(val) + } + return nil +} + +type _List_Double_Zapper []float64 + +func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendFloat64(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.RequiredPrimitive != nil { + enc.AddInt32("requiredPrimitive", *v.RequiredPrimitive) + } + + if v.OptionalPrimitive != nil { + enc.AddInt32("optionalPrimitive", *v.OptionalPrimitive) + } + + if v.RequiredEnum != nil { + enc.AddObject("requiredEnum", *v.RequiredEnum) + } + + if v.OptionalEnum != nil { + enc.AddObject("optionalEnum", *v.OptionalEnum) + } + + if v.RequiredList != nil { + enc.AddArray("requiredList", (_List_String_Zapper)(v.RequiredList)) + } + + if v.OptionalList != nil { + enc.AddArray("optionalList", (_List_Double_Zapper)(v.OptionalList)) + } + + if v.RequiredStruct != nil { + enc.AddObject("requiredStruct", v.RequiredStruct) + } + + if v.OptionalStruct != nil { + enc.AddObject("optionalStruct", v.OptionalStruct) + } + + return nil +} + // GetRequiredPrimitive returns the value of RequiredPrimitive if it is set or its // default value if it is unset. func (v *DefaultsStruct) GetRequiredPrimitive() (o int32) { @@ -917,6 +983,16 @@ func (v *Edge) Equals(rhs *Edge) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddObject("startPoint", v.StartPoint) + + enc.AddObject("endPoint", v.EndPoint) + + return nil +} + // GetStartPoint returns the value of StartPoint if it is set or its // zero value if it is unset. func (v *Edge) GetStartPoint() (o *Point) { return v.StartPoint } @@ -1001,6 +1077,12 @@ func (v *EmptyStruct) Equals(rhs *EmptyStruct) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *EmptyStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + type Frame struct { TopLeft *Point `json:"topLeft,required"` Size *Size `json:"size,required"` @@ -1144,6 +1226,16 @@ func (v *Frame) Equals(rhs *Frame) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddObject("topLeft", v.TopLeft) + + enc.AddObject("size", v.Size) + + return nil +} + // GetTopLeft returns the value of TopLeft if it is set or its // zero value if it is unset. func (v *Frame) GetTopLeft() (o *Point) { return v.TopLeft } @@ -1400,6 +1492,28 @@ func (v *GoTags) Equals(rhs *GoTags) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *GoTags) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("Foo", v.Foo) + + if v.Bar != nil { + enc.AddString("Bar", *v.Bar) + } + + enc.AddString("FooBar", v.FooBar) + + enc.AddString("FooBarWithSpace", v.FooBarWithSpace) + + if v.FooBarWithOmitEmpty != nil { + enc.AddString("FooBarWithOmitEmpty", *v.FooBarWithOmitEmpty) + } + + enc.AddString("FooBarWithRequired", v.FooBarWithRequired) + + return nil +} + // GetFoo returns the value of Foo if it is set or its // zero value if it is unset. func (v *GoTags) GetFoo() (o string) { return v.Foo } @@ -1611,6 +1725,23 @@ func (v *Graph) Equals(rhs *Graph) bool { return true } +type _List_Edge_Zapper []*Edge + +func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)) + + return nil +} + // GetEdges returns the value of Edges if it is set or its // zero value if it is unset. func (v *Graph) GetEdges() (o []*Edge) { return v.Edges } @@ -1782,6 +1913,18 @@ func (v *Node) Equals(rhs *Node) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddInt32("value", v.Value) + + if v.Tail != nil { + enc.AddObject("tail", (*Node)(v.Tail)) + } + + return nil +} + // GetValue returns the value of Value if it is set or its // zero value if it is unset. func (v *Node) GetValue() (o int32) { return v.Value } @@ -1928,6 +2071,16 @@ func (v *Omit) Equals(rhs *Omit) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Omit) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("serialized", v.Serialized) + + enc.AddString("hidden", v.Hidden) + + return nil +} + // GetSerialized returns the value of Serialized if it is set or its // zero value if it is unset. func (v *Omit) GetSerialized() (o string) { return v.Serialized } @@ -2069,6 +2222,16 @@ func (v *Point) Equals(rhs *Point) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Point) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddFloat64("x", v.X) + + enc.AddFloat64("y", v.Y) + + return nil +} + // GetX returns the value of X if it is set or its // zero value if it is unset. func (v *Point) GetX() (o float64) { return v.X } @@ -2416,6 +2579,44 @@ func (v *PrimitiveOptionalStruct) Equals(rhs *PrimitiveOptionalStruct) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *PrimitiveOptionalStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.BoolField != nil { + enc.AddBool("boolField", *v.BoolField) + } + + if v.ByteField != nil { + enc.AddInt8("byteField", *v.ByteField) + } + + if v.Int16Field != nil { + enc.AddInt16("int16Field", *v.Int16Field) + } + + if v.Int32Field != nil { + enc.AddInt32("int32Field", *v.Int32Field) + } + + if v.Int64Field != nil { + enc.AddInt64("int64Field", *v.Int64Field) + } + + if v.DoubleField != nil { + enc.AddFloat64("doubleField", *v.DoubleField) + } + + if v.StringField != nil { + enc.AddString("stringField", *v.StringField) + } + + if v.BinaryField != nil { + enc.AddString("binaryField", base64.StdEncoding.EncodeToString(v.BinaryField)) + } + + return nil +} + // GetBoolField returns the value of BoolField if it is set or its // zero value if it is unset. func (v *PrimitiveOptionalStruct) GetBoolField() (o bool) { @@ -2789,6 +2990,28 @@ func (v *PrimitiveRequiredStruct) Equals(rhs *PrimitiveRequiredStruct) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *PrimitiveRequiredStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddBool("boolField", v.BoolField) + + enc.AddInt8("byteField", v.ByteField) + + enc.AddInt16("int16Field", v.Int16Field) + + enc.AddInt32("int32Field", v.Int32Field) + + enc.AddInt64("int64Field", v.Int64Field) + + enc.AddFloat64("doubleField", v.DoubleField) + + enc.AddString("stringField", v.StringField) + + enc.AddString("binaryField", base64.StdEncoding.EncodeToString(v.BinaryField)) + + return nil +} + // GetBoolField returns the value of BoolField if it is set or its // zero value if it is unset. func (v *PrimitiveRequiredStruct) GetBoolField() (o bool) { return v.BoolField } @@ -2953,6 +3176,16 @@ func (v *Rename) Equals(rhs *Rename) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Rename) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("Default", v.Default) + + enc.AddString("camelCase", v.CamelCase) + + return nil +} + // GetDefault returns the value of Default if it is set or its // zero value if it is unset. func (v *Rename) GetDefault() (o string) { return v.Default } @@ -3096,6 +3329,16 @@ func (v *Size) Equals(rhs *Size) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Size) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddFloat64("width", v.Width) + + enc.AddFloat64("height", v.Height) + + return nil +} + // GetWidth returns the value of Width if it is set or its // zero value if it is unset. func (v *Size) GetWidth() (o float64) { return v.Width } @@ -3240,6 +3483,18 @@ func (v *User) Equals(rhs *User) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("name", v.Name) + + if v.Contact != nil { + enc.AddObject("contact", v.Contact) + } + + return nil +} + // GetName returns the value of Name if it is set or its // zero value if it is unset. func (v *User) GetName() (o string) { return v.Name } diff --git a/gen/internal/tests/typedefs/types.go b/gen/internal/tests/typedefs/types.go index 126784d2..fb9ca735 100644 --- a/gen/internal/tests/typedefs/types.go +++ b/gen/internal/tests/typedefs/types.go @@ -10,6 +10,7 @@ import ( "go.uber.org/thriftrw/gen/internal/tests/enums" "go.uber.org/thriftrw/gen/internal/tests/structs" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -246,6 +247,16 @@ func (v *DefaultPrimitiveTypedef) Equals(rhs *DefaultPrimitiveTypedef) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *DefaultPrimitiveTypedef) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.State != nil { + enc.AddString("state", (string)(*v.State)) + } + + return nil +} + // GetState returns the value of State if it is set or its // default value if it is unset. func (v *DefaultPrimitiveTypedef) GetState() (o State) { @@ -575,6 +586,18 @@ func (v *Event) Equals(rhs *Event) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddObject("uuid", (*I128)(v.UUID)) + + if v.Time != nil { + enc.AddInt64("time", (int64)(*v.Time)) + } + + return nil +} + // GetUUID returns the value of UUID if it is set or its // zero value if it is unset. func (v *Event) GetUUID() (o *UUID) { return v.UUID } @@ -1251,6 +1274,29 @@ func (v *Transition) Equals(rhs *Transition) bool { return true } +type _EventGroup_Zapper []*Event + +func (vals _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("fromState", (string)(v.FromState)) + + enc.AddString("toState", (string)(v.ToState)) + + if v.Events != nil { + enc.AddArray("events", (_EventGroup_Zapper)(([]*Event)(v.Events))) + } + + return nil +} + // GetFromState returns the value of FromState if it is set or its // zero value if it is unset. func (v *Transition) GetFromState() (o State) { return v.FromState } @@ -1430,6 +1476,16 @@ func (v *I128) Equals(rhs *I128) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *I128) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddInt64("high", v.High) + + enc.AddInt64("low", v.Low) + + return nil +} + // GetHigh returns the value of High if it is set or its // zero value if it is unset. func (v *I128) GetHigh() (o int64) { return v.High } diff --git a/gen/internal/tests/unions/types.go b/gen/internal/tests/unions/types.go index 2ff8d95b..462ed961 100644 --- a/gen/internal/tests/unions/types.go +++ b/gen/internal/tests/unions/types.go @@ -4,9 +4,11 @@ package unions import ( + "encoding/base64" "fmt" "go.uber.org/thriftrw/gen/internal/tests/typedefs" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -430,6 +432,50 @@ func (v *ArbitraryValue) Equals(rhs *ArbitraryValue) bool { return true } +type _List_ArbitraryValue_Zapper []*ArbitraryValue + +func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue + +func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddObject((string)(k), v) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.BoolValue != nil { + enc.AddBool("boolValue", *v.BoolValue) + } + + if v.Int64Value != nil { + enc.AddInt64("int64Value", *v.Int64Value) + } + + if v.StringValue != nil { + enc.AddString("stringValue", *v.StringValue) + } + + if v.ListValue != nil { + enc.AddArray("listValue", (_List_ArbitraryValue_Zapper)(v.ListValue)) + } + + if v.MapValue != nil { + enc.AddObject("mapValue", (_Map_String_ArbitraryValue_Zapper)(v.MapValue)) + } + + return nil +} + // GetBoolValue returns the value of BoolValue if it is set or its // zero value if it is unset. func (v *ArbitraryValue) GetBoolValue() (o bool) { @@ -631,6 +677,20 @@ func (v *Document) Equals(rhs *Document) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Document) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Pdf != nil { + enc.AddString("pdf", base64.StdEncoding.EncodeToString(([]byte)(v.Pdf))) + } + + if v.PlainText != nil { + enc.AddString("plainText", *v.PlainText) + } + + return nil +} + // GetPdf returns the value of Pdf if it is set or its // zero value if it is unset. func (v *Document) GetPdf() (o typedefs.PDF) { @@ -726,3 +786,9 @@ func (v *EmptyUnion) Equals(rhs *EmptyUnion) bool { return true } + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *EmptyUnion) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} diff --git a/gen/internal/tests/uuid_conflict/types.go b/gen/internal/tests/uuid_conflict/types.go index cd64697e..69e9c43f 100644 --- a/gen/internal/tests/uuid_conflict/types.go +++ b/gen/internal/tests/uuid_conflict/types.go @@ -8,6 +8,7 @@ import ( "fmt" "go.uber.org/thriftrw/gen/internal/tests/typedefs" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -188,6 +189,16 @@ func (v *UUIDConflict) Equals(rhs *UUIDConflict) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *UUIDConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("localUUID", (string)(v.LocalUUID)) + + enc.AddObject("importedUUID", (*typedefs.I128)(v.ImportedUUID)) + + return nil +} + // GetLocalUUID returns the value of LocalUUID if it is set or its // zero value if it is unset. func (v *UUIDConflict) GetLocalUUID() (o UUID) { return v.LocalUUID } diff --git a/gen/zap.go b/gen/zap.go new file mode 100644 index 00000000..bf894a35 --- /dev/null +++ b/gen/zap.go @@ -0,0 +1,277 @@ +// Copyright (c) 2018 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package gen + +import ( + "fmt" + + "go.uber.org/thriftrw/compile" +) + +func zapEncoder(g Generator, spec compile.TypeSpec) string { + root := compile.RootTypeSpec(spec) + + switch t := root.(type) { + // Primitives + case *compile.BoolSpec: + return ("Bool") + case *compile.I8Spec: + return ("Int8") + case *compile.I16Spec: + return ("Int16") + case *compile.I32Spec: + return ("Int32") + case *compile.I64Spec: + return ("Int64") + case *compile.DoubleSpec: + return ("Float64") + case *compile.StringSpec: + return ("String") + case *compile.BinarySpec: + return ("String") + + // Containers + case *compile.MapSpec: + // TODO: use objects if the key is a string or array if not. + switch t.KeySpec.(type) { + case *compile.StringSpec: + return "Object" + default: + return "Array" + } + case *compile.SetSpec: + // TODO: generate wrapper types for sets and use those here + return ("Array") + case *compile.ListSpec: + return ("Array") + + // User-defined + case *compile.EnumSpec: + return ("Object") + case *compile.StructSpec: + return ("Object") + default: + } + panic(root) +} + +func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string, error) { + root := compile.RootTypeSpec(spec) + + if _, ok := spec.(*compile.TypedefSpec); ok { + // For typedefs, cast to the root type and rely on that functionality. + rootName, err := typeReference(g, root) + if err != nil { + return "", err + } + fieldValue = fmt.Sprintf("(%v)(%v)", rootName, fieldValue) + } + + if isPrimitiveType(spec) { + return fieldValue, nil + } + + switch t := root.(type) { + case *compile.BinarySpec: + // There is no AppendBinary for ArrayEncoder, so we opt for encoding it ourselves and + // appending it as a string. We also use AddString instead of AddBinary for ObjectEncoder + // for consistency. + base64 := g.Import("encoding/base64") + return fmt.Sprintf("%v.StdEncoding.EncodeToString(%v)", base64, fieldValue), nil + case *compile.MapSpec: + // TODO: use objects if the key is a string or array if not. + name := "_" + g.MangleType(spec) + "_Zapper" + switch t.KeySpec.(type) { + case *compile.StringSpec: + // t should already be the root type, so there's no need to check if it is a typedef of a + // string. For simplicity, we always cast the key to a string when logging this way. + if err := g.EnsureDeclared( + ` + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$keyvals := newVar "keyvals"> + <$k := newVar "k"> + <$v := newVar "v"> + func (<$keyvals> <.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { + for <$k>, <$v> := range <$keyvals> { + enc.Add((string)(<$k>), ) + } + return nil + } + `, struct { + Name string + Type compile.TypeSpec + }{ + Name: name, + Type: root, + }, + ); err != nil { + return "", err + } + + // TODO: generate wrapper types for sets and use those here + return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil + // // return fieldValue, nil + default: + if err := g.EnsureDeclared( + ` + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$keyvals := newVar "keyvals"> + <$k := newVar "k"> + <$v := newVar "v"> + <$i := newVar "i"> + func (<$keyvals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { + <- if isHashable .Type.KeySpec -> + for <$k>, <$v> := range <$keyvals> { + + for _, <$i> := range <$keyvals> { + <$k> := <$i>.Key + <$v> := <$i>.Value + + enc.AppendObject() + } + return nil + } + `, struct { + Name string + Type compile.TypeSpec + }{ + Name: name, + Type: root, + }, + ); err != nil { + return "", err + } + + // TODO: generate wrapper types for sets and use those here + return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil + } + case *compile.SetSpec: + name := "_" + g.MangleType(spec) + "_Zapper" + if err := g.EnsureDeclared( + ` + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$vals := newVar "vals"> + <$v := newVar "v"> + func (<$vals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { + <- if isHashable .Type.ValueSpec -> + for <$v> := range <$vals> { + + for _, <$v> := range <$vals> { + + enc.Append() + } + return nil + } + `, struct { + Name string + Type compile.TypeSpec + }{ + Name: name, + Type: root, + }, + ); err != nil { + return "", err + } + + // TODO: generate wrapper types for sets and use those here + return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil + case *compile.ListSpec: + name := "_" + g.MangleType(spec) + "_Zapper" + if err := g.EnsureDeclared( + ` + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$vals := newVar "vals"> + func (<$vals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { + for _, val := range <$vals> { + enc.Append() + } + return nil + } + `, struct { + Name string + Type compile.TypeSpec + }{ + Name: name, + Type: root, + }, + ); err != nil { + return "", err + } + + // TODO: generate wrapper types for sets and use those here + return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil + case *compile.StructSpec: + return fieldValue, nil + default: + } + panic(root) +} + +func zapMarshalerPtr(g Generator, spec compile.TypeSpec, fieldValue string) (string, error) { + if isPrimitiveType(spec) { + fieldValue = "*" + fieldValue + } + return zapMarshaler(g, spec, fieldValue) +} + +func zapMapItemMarshaler( + g Generator, + keySpec compile.TypeSpec, + keyVar string, + valueSpec compile.TypeSpec, + valueVar string, +) (string, error) { + name := "_MapItem_" + g.MangleType(keySpec) + "_" + g.MangleType(valueSpec) + "_Zapper" + if err := g.EnsureDeclared( + ` + type <.Name> struct { + Key + Value + } + <$zapcore := import "go.uber.org/zap/zapcore"> + <$v := newVar "v"> + <$key := printf "%s.%s" $v "Key"> + <$val := printf "%s.%s" $v "Value"> + func (<$v> <.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { + enc.Add("key", ) + enc.Add("value", ) + return nil + } + `, struct { + Name string + KeyType compile.TypeSpec + ValueType compile.TypeSpec + }{ + Name: name, + KeyType: keySpec, + ValueType: valueSpec, + }, + ); err != nil { + return "", err + } + + // TODO: generate wrapper types for sets and use those here + return fmt.Sprintf("%v{Key: %v, Value: %v}", name, keyVar, valueVar), nil +} diff --git a/glide.lock b/glide.lock index 8697b2b6..1e72b538 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,12 @@ -hash: 26c2c55ca402d6605deed8219389876b6207f46109135620b0f6ec7f84ca1a84 -updated: 2018-04-24T13:31:10.646395712-07:00 +hash: de4f56d34612433b7a80991786d4a9bf401fbd8d74bfd4b53e8a277e7f93bd6e +updated: 2018-07-25T12:58:08.506626687-07:00 imports: - name: github.com/anmitsu/go-shlex version: 648efa622239a2f6ff949fed78ee37b48d499ba4 - name: github.com/fatih/structtag version: da3d9ab5b78fdc25d3a7614853b085200bd10da9 - name: github.com/golang/mock - version: 13f360950a79f5864a972c786a10a50e44b69541 + version: c34cdb4725f4c3844d095133c6e40e448b86589b subpackages: - gomock - name: github.com/jessevdk/go-flags @@ -16,24 +16,30 @@ imports: - name: github.com/kr/text version: 7cafcd837844e784b526369c9bce262804aebc60 - name: go.uber.org/atomic - version: 8474b86a5a6f79c443ce4b2992817ff32cf208b8 + version: 1ea20fb1cbb1cc08cbd0d913a96dead89aa18289 - name: go.uber.org/multierr version: 3c4937480c32f4c13a875a1829af76c98ca3d40a +- name: go.uber.org/zap + version: 4d45f9617f7d90f7a663ff21c7a4321dbe78098b +- name: golang.org/x/net + version: d0887baf81f4598189d4e12a37c6da86f0bba4d0 + subpackages: + - context - name: golang.org/x/tools version: 4e70a1b26a7875f00ca1916637a876b5ffaeec59 subpackages: - go/ast/astutil testImports: - name: github.com/davecgh/go-spew - version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 + version: 8991bc29aa16c548c550c7ff78260e27b9ab7c73 subpackages: - spew - name: github.com/pmezard/go-difflib - version: d8ed2627bdf02c080bf22230dbb337003b7aba2d + version: 792786c7400a136282c1664665ae0a8db921c6c2 subpackages: - difflib - name: github.com/stretchr/testify - version: 12b6f73e6084dad08a7c6e575284b177ecafbc71 + version: f35b8ab0b5a2cef36673838d662e249dd9c94686 subpackages: - assert - require diff --git a/glide.yaml b/glide.yaml index 978b5dcc..40ba5547 100644 --- a/glide.yaml +++ b/glide.yaml @@ -12,6 +12,8 @@ import: version: ^1 - package: github.com/fatih/structtag version: ^0.1.0 +- package: go.uber.org/zap + version: ^1 testImport: - package: github.com/golang/mock subpackages: diff --git a/internal/envelope/exception/types.go b/internal/envelope/exception/types.go index 175d9322..9a7f898a 100644 --- a/internal/envelope/exception/types.go +++ b/internal/envelope/exception/types.go @@ -28,6 +28,7 @@ import ( "encoding/json" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "math" "strconv" "strings" @@ -145,6 +146,36 @@ func (v ExceptionType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v ExceptionType) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 0: + enc.AddString("name", "UNKNOWN") + case 1: + enc.AddString("name", "UNKNOWN_METHOD") + case 2: + enc.AddString("name", "INVALID_MESSAGE_TYPE") + case 3: + enc.AddString("name", "WRONG_METHOD_NAME") + case 4: + enc.AddString("name", "BAD_SEQUENCE_ID") + case 5: + enc.AddString("name", "MISSING_RESULT") + case 6: + enc.AddString("name", "INTERNAL_ERROR") + case 7: + enc.AddString("name", "PROTOCOL_ERROR") + case 8: + enc.AddString("name", "INVALID_TRANSFORM") + case 9: + enc.AddString("name", "INVALID_PROTOCOL") + case 10: + enc.AddString("name", "UNSUPPORTED_CLIENT_TYPE") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v ExceptionType) Ptr() *ExceptionType { return &v @@ -441,6 +472,20 @@ func (v *TApplicationException) Equals(rhs *TApplicationException) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *TApplicationException) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Message != nil { + enc.AddString("message", *v.Message) + } + + if v.Type != nil { + enc.AddObject("type", *v.Type) + } + + return nil +} + // GetMessage returns the value of Message if it is set or its // zero value if it is unset. func (v *TApplicationException) GetMessage() (o string) { diff --git a/plugin/api/plugin_goodbye.go b/plugin/api/plugin_goodbye.go index 29760620..9c893c6e 100644 --- a/plugin/api/plugin_goodbye.go +++ b/plugin/api/plugin_goodbye.go @@ -26,6 +26,7 @@ package api import ( "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -108,6 +109,12 @@ func (v *Plugin_Goodbye_Args) Equals(rhs *Plugin_Goodbye_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Plugin_Goodbye_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the arguments. // @@ -271,6 +278,12 @@ func (v *Plugin_Goodbye_Result) Equals(rhs *Plugin_Goodbye_Result) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Plugin_Goodbye_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // MethodName returns the name of the Thrift function as specified in // the IDL, for which this struct represent the result. // diff --git a/plugin/api/plugin_handshake.go b/plugin/api/plugin_handshake.go index c5cc1d51..5d6ed4d2 100644 --- a/plugin/api/plugin_handshake.go +++ b/plugin/api/plugin_handshake.go @@ -27,6 +27,7 @@ import ( "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -143,6 +144,16 @@ func (v *Plugin_Handshake_Args) Equals(rhs *Plugin_Handshake_Args) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Plugin_Handshake_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Request != nil { + enc.AddObject("request", v.Request) + } + + return nil +} + // GetRequest returns the value of Request if it is set or its // zero value if it is unset. func (v *Plugin_Handshake_Args) GetRequest() (o *HandshakeRequest) { @@ -377,6 +388,16 @@ func (v *Plugin_Handshake_Result) Equals(rhs *Plugin_Handshake_Result) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Plugin_Handshake_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Success != nil { + enc.AddObject("success", v.Success) + } + + return nil +} + // GetSuccess returns the value of Success if it is set or its // zero value if it is unset. func (v *Plugin_Handshake_Result) GetSuccess() (o *HandshakeResponse) { diff --git a/plugin/api/servicegenerator_generate.go b/plugin/api/servicegenerator_generate.go index c3d2ffc3..fae70013 100644 --- a/plugin/api/servicegenerator_generate.go +++ b/plugin/api/servicegenerator_generate.go @@ -27,6 +27,7 @@ import ( "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "strings" ) @@ -143,6 +144,16 @@ func (v *ServiceGenerator_Generate_Args) Equals(rhs *ServiceGenerator_Generate_A return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ServiceGenerator_Generate_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Request != nil { + enc.AddObject("request", v.Request) + } + + return nil +} + // GetRequest returns the value of Request if it is set or its // zero value if it is unset. func (v *ServiceGenerator_Generate_Args) GetRequest() (o *GenerateServiceRequest) { @@ -377,6 +388,16 @@ func (v *ServiceGenerator_Generate_Result) Equals(rhs *ServiceGenerator_Generate return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *ServiceGenerator_Generate_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Success != nil { + enc.AddObject("success", v.Success) + } + + return nil +} + // GetSuccess returns the value of Success if it is set or its // zero value if it is unset. func (v *ServiceGenerator_Generate_Result) GetSuccess() (o *GenerateServiceResponse) { diff --git a/plugin/api/types.go b/plugin/api/types.go index 8f71a925..ffe1bb3c 100644 --- a/plugin/api/types.go +++ b/plugin/api/types.go @@ -25,10 +25,12 @@ package api import ( "bytes" + "encoding/base64" "encoding/json" "errors" "fmt" "go.uber.org/thriftrw/wire" + "go.uber.org/zap/zapcore" "math" "strconv" "strings" @@ -187,6 +189,16 @@ func (v *Argument) Equals(rhs *Argument) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Argument) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("name", v.Name) + + enc.AddObject("type", v.Type) + + return nil +} + // GetName returns the value of Name if it is set or its // zero value if it is unset. func (v *Argument) GetName() (o string) { return v.Name } @@ -243,6 +255,16 @@ func (v Feature) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v Feature) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 1: + enc.AddString("name", "SERVICE_GENERATOR") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v Feature) Ptr() *Feature { return &v @@ -782,6 +804,52 @@ func (v *Function) Equals(rhs *Function) bool { return true } +type _List_Argument_Zapper []*Argument + +func (vals _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +type _Map_String_String_Zapper map[string]string + +func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddString((string)(k), v) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Function) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("name", v.Name) + + enc.AddString("thriftName", v.ThriftName) + + enc.AddArray("arguments", (_List_Argument_Zapper)(v.Arguments)) + + if v.ReturnType != nil { + enc.AddObject("returnType", v.ReturnType) + } + + if v.Exceptions != nil { + enc.AddArray("exceptions", (_List_Argument_Zapper)(v.Exceptions)) + } + + if v.OneWay != nil { + enc.AddBool("oneWay", *v.OneWay) + } + + if v.Annotations != nil { + enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)) + } + + return nil +} + // GetName returns the value of Name if it is set or its // zero value if it is unset. func (v *Function) GetName() (o string) { return v.Name } @@ -1264,6 +1332,67 @@ func (v *GenerateServiceRequest) Equals(rhs *GenerateServiceRequest) bool { return true } +type _List_ServiceID_Zapper []ServiceID + +func (vals _List_ServiceID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendInt32((int32)(val)) + } + return nil +} + +type _MapItem_ServiceID_Service_Zapper struct { + Key ServiceID + Value *Service +} + +func (v _MapItem_ServiceID_Service_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("key", (int32)(v.Key)) + enc.AddObject("value", v.Value) + return nil +} + +type _Map_ServiceID_Service_Zapper map[ServiceID]*Service + +func (keyvals _Map_ServiceID_Service_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range keyvals { + enc.AppendObject(_MapItem_ServiceID_Service_Zapper{Key: k, Value: v}) + } + return nil +} + +type _MapItem_ModuleID_Module_Zapper struct { + Key ModuleID + Value *Module +} + +func (v _MapItem_ModuleID_Module_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("key", (int32)(v.Key)) + enc.AddObject("value", v.Value) + return nil +} + +type _Map_ModuleID_Module_Zapper map[ModuleID]*Module + +func (keyvals _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range keyvals { + enc.AppendObject(_MapItem_ModuleID_Module_Zapper{Key: k, Value: v}) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *GenerateServiceRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddArray("rootServices", (_List_ServiceID_Zapper)(v.RootServices)) + + enc.AddArray("services", (_Map_ServiceID_Service_Zapper)(v.Services)) + + enc.AddArray("modules", (_Map_ModuleID_Module_Zapper)(v.Modules)) + + return nil +} + // GetRootServices returns the value of RootServices if it is set or its // zero value if it is unset. func (v *GenerateServiceRequest) GetRootServices() (o []ServiceID) { return v.RootServices } @@ -1471,6 +1600,25 @@ func (v *GenerateServiceResponse) Equals(rhs *GenerateServiceResponse) bool { return true } +type _Map_String_Binary_Zapper map[string][]byte + +func (keyvals _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range keyvals { + enc.AddString((string)(k), base64.StdEncoding.EncodeToString(v)) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *GenerateServiceResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.Files != nil { + enc.AddObject("files", (_Map_String_Binary_Zapper)(v.Files)) + } + + return nil +} + // GetFiles returns the value of Files if it is set or its // zero value if it is unset. func (v *GenerateServiceResponse) GetFiles() (o map[string][]byte) { @@ -1559,6 +1707,12 @@ func (v *HandshakeRequest) Equals(rhs *HandshakeRequest) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *HandshakeRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + return nil +} + // HandshakeResponse is the response from the plugin for a HandshakeRequest. type HandshakeResponse struct { // Name of the plugin. This MUST match the name of the plugin specified @@ -1831,6 +1985,31 @@ func (v *HandshakeResponse) Equals(rhs *HandshakeResponse) bool { return true } +type _List_Feature_Zapper []Feature + +func (vals _List_Feature_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *HandshakeResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("name", v.Name) + + enc.AddInt32("apiVersion", v.APIVersion) + + enc.AddArray("features", (_List_Feature_Zapper)(v.Features)) + + if v.LibraryVersion != nil { + enc.AddString("libraryVersion", *v.LibraryVersion) + } + + return nil +} + // GetName returns the value of Name if it is set or its // zero value if it is unset. func (v *HandshakeResponse) GetName() (o string) { return v.Name } @@ -1994,6 +2173,16 @@ func (v *Module) Equals(rhs *Module) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Module) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("importPath", v.ImportPath) + + enc.AddString("directory", v.Directory) + + return nil +} + // GetImportPath returns the value of ImportPath if it is set or its // zero value if it is unset. func (v *Module) GetImportPath() (o string) { return v.ImportPath } @@ -2368,6 +2557,37 @@ func (v *Service) Equals(rhs *Service) bool { return true } +type _List_Function_Zapper []*Function + +func (vals _List_Function_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, val := range vals { + enc.AppendObject(val) + } + return nil +} + +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Service) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("name", v.Name) + + enc.AddString("thriftName", v.ThriftName) + + if v.ParentID != nil { + enc.AddInt32("parentID", (int32)(*v.ParentID)) + } + + enc.AddArray("functions", (_List_Function_Zapper)(v.Functions)) + + enc.AddInt32("moduleID", (int32)(v.ModuleID)) + + if v.Annotations != nil { + enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)) + } + + return nil +} + // GetName returns the value of Name if it is set or its // zero value if it is unset. func (v *Service) GetName() (o string) { return v.Name } @@ -2536,6 +2756,32 @@ func (v SimpleType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } +// TODO() +func (v SimpleType) MarshalLogObject(enc zapcore.ObjectEncoder) error { + enc.AddInt32("value", int32(v)) + switch int32(v) { + case 1: + enc.AddString("name", "BOOL") + case 2: + enc.AddString("name", "BYTE") + case 3: + enc.AddString("name", "INT8") + case 4: + enc.AddString("name", "INT16") + case 5: + enc.AddString("name", "INT32") + case 6: + enc.AddString("name", "INT64") + case 7: + enc.AddString("name", "FLOAT64") + case 8: + enc.AddString("name", "STRING") + case 9: + enc.AddString("name", "STRUCT_EMPTY") + } + return nil +} + // Ptr returns a pointer to this enum value. func (v SimpleType) Ptr() *SimpleType { return &v @@ -2959,6 +3205,36 @@ func (v *Type) Equals(rhs *Type) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *Type) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + if v.SimpleType != nil { + enc.AddObject("simpleType", *v.SimpleType) + } + + if v.SliceType != nil { + enc.AddObject("sliceType", v.SliceType) + } + + if v.KeyValueSliceType != nil { + enc.AddObject("keyValueSliceType", v.KeyValueSliceType) + } + + if v.MapType != nil { + enc.AddObject("mapType", v.MapType) + } + + if v.ReferenceType != nil { + enc.AddObject("referenceType", v.ReferenceType) + } + + if v.PointerType != nil { + enc.AddObject("pointerType", v.PointerType) + } + + return nil +} + // GetSimpleType returns the value of SimpleType if it is set or its // zero value if it is unset. func (v *Type) GetSimpleType() (o SimpleType) { @@ -3157,6 +3433,16 @@ func (v *TypePair) Equals(rhs *TypePair) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *TypePair) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddObject("left", v.Left) + + enc.AddObject("right", v.Right) + + return nil +} + // GetLeft returns the value of Left if it is set or its // zero value if it is unset. func (v *TypePair) GetLeft() (o *Type) { return v.Left } @@ -3341,6 +3627,20 @@ func (v *TypeReference) Equals(rhs *TypeReference) bool { return true } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +func (v *TypeReference) MarshalLogObject(enc zapcore.ObjectEncoder) error { + + enc.AddString("name", v.Name) + + enc.AddString("importPath", v.ImportPath) + + if v.Annotations != nil { + enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)) + } + + return nil +} + // GetName returns the value of Name if it is set or its // zero value if it is unset. func (v *TypeReference) GetName() (o string) { return v.Name } From 31f8d9cdaf1dae41e990e24801633a1b3686ecfc Mon Sep 17 00:00:00 2001 From: Minho Park Date: Fri, 27 Jul 2018 16:11:58 -0700 Subject: [PATCH 02/25] Add error handling for enc.{Add,Append}{Array,Object} for Zap logging --- gen/field.go | 8 ++++++++ gen/generator.go | 1 + gen/zap.go | 49 +++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/gen/field.go b/gen/field.go index 6c4c9916..646eeaa2 100644 --- a/gen/field.go +++ b/gen/field.go @@ -478,10 +478,18 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <$fname := goName .> <$fval := printf "%s.%s" $v $fname> <- if .Required -> + if err := enc.Add("<.Name>", ) + <- if (zapCanError .Type)>; err != nil { + return err + } <- else -> if <$fval> != nil { + if err := enc.Add("<.Name>", ) + <- if (zapCanError .Type)>; err != nil { + return err + } } <- end> diff --git a/gen/generator.go b/gen/generator.go index a08516bc..836cb806 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -215,6 +215,7 @@ func (g *generator) TextTemplate(s string, data interface{}, opts ...TemplateOpt "typeCode": curryGenerator(TypeCode, g), "equals": curryGenerator(g.e.Equals, g), "equalsPtr": curryGenerator(g.e.EqualsPtr, g), + "zapCanError": zapCanError, "zapEncoder": curryGenerator(zapEncoder, g), "zapMarshaler": curryGenerator(zapMarshaler, g), "zapMarshalerPtr": curryGenerator(zapMarshalerPtr, g), diff --git a/gen/zap.go b/gen/zap.go index bf894a35..0e396820 100644 --- a/gen/zap.go +++ b/gen/zap.go @@ -112,7 +112,11 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string <$v := newVar "v"> func (<$keyvals> <.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { for <$k>, <$v> := range <$keyvals> { - enc.Add((string)(<$k>), ) + if err := + enc.Add((string)(<$k>), ) + <- if (zapCanError .Type.ValueSpec) ->; err != nil { + return err + } } return nil } @@ -147,7 +151,9 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string <$k> := <$i>.Key <$v> := <$i>.Value - enc.AppendObject() + if err := enc.AppendObject(); err != nil { + return err + } } return nil } @@ -178,8 +184,12 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string for <$v> := range <$vals> { for _, <$v> := range <$vals> { - - enc.Append() + + if err := + enc.Append() + <- if (zapCanError .Type.ValueSpec)>; err != nil { + return err + } } return nil } @@ -205,7 +215,11 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string <$vals := newVar "vals"> func (<$vals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { for _, val := range <$vals> { - enc.Append() + if err := + enc.Append() + <- if (zapCanError .Type.ValueSpec)>; err != nil { + return err + } } return nil } @@ -255,8 +269,16 @@ func zapMapItemMarshaler( <$key := printf "%s.%s" $v "Key"> <$val := printf "%s.%s" $v "Value"> func (<$v> <.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { + if err := enc.Add("key", ) + <- if (zapCanError .KeyType)>; err != nil { + return err + } + if err := enc.Add("value", ) + <- if (zapCanError .ValueType)>; err != nil { + return err + } return nil } `, struct { @@ -275,3 +297,20 @@ func zapMapItemMarshaler( // TODO: generate wrapper types for sets and use those here return fmt.Sprintf("%v{Key: %v, Value: %v}", name, keyVar, valueVar), nil } + +func zapCanError(spec compile.TypeSpec) bool { + root := compile.RootTypeSpec(spec) + + switch root.(type) { + // Primitives + case *compile.BoolSpec, *compile.I8Spec, *compile.I16Spec, *compile.I32Spec, + *compile.I64Spec, *compile.DoubleSpec, *compile.StringSpec, *compile.BinarySpec: + return false + + case *compile.MapSpec, *compile.SetSpec, *compile.ListSpec, *compile.EnumSpec, + *compile.StructSpec: + return true + default: + } + panic(root) +} From 7ebab96c0503e27f64cdb63c289e48c529d23c20 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Fri, 27 Jul 2018 16:13:29 -0700 Subject: [PATCH 03/25] Replace generated files with previous commit's change applied --- envelope/internal/tests/enums/types.go | 4 +- .../services/conflictingnames_setvalue.go | 4 +- .../tests/services/keyvalue_deletevalue.go | 8 +- .../tests/services/keyvalue_getmanyvalues.go | 16 +- .../tests/services/keyvalue_getvalue.go | 8 +- .../tests/services/keyvalue_setvalue.go | 4 +- .../tests/services/keyvalue_setvaluev2.go | 4 +- envelope/internal/tests/structs/types.go | 56 +++-- envelope/internal/tests/typedefs/types.go | 12 +- envelope/internal/tests/unions/types.go | 16 +- gen/internal/tests/collision/types.go | 17 +- gen/internal/tests/containers/types.go | 216 +++++++++++++----- gen/internal/tests/enum_conflict/types.go | 8 +- gen/internal/tests/enums/types.go | 4 +- .../services/conflictingnames_setvalue.go | 4 +- .../tests/services/keyvalue_deletevalue.go | 8 +- .../tests/services/keyvalue_getmanyvalues.go | 16 +- .../tests/services/keyvalue_getvalue.go | 8 +- .../tests/services/keyvalue_setvalue.go | 4 +- .../tests/services/keyvalue_setvaluev2.go | 4 +- gen/internal/tests/structs/types.go | 56 +++-- gen/internal/tests/typedefs/types.go | 12 +- gen/internal/tests/unions/types.go | 16 +- gen/internal/tests/uuid_conflict/types.go | 4 +- internal/envelope/exception/types.go | 4 +- plugin/api/plugin_handshake.go | 8 +- plugin/api/servicegenerator_generate.go | 8 +- plugin/api/types.go | 112 ++++++--- 28 files changed, 474 insertions(+), 167 deletions(-) diff --git a/envelope/internal/tests/enums/types.go b/envelope/internal/tests/enums/types.go index babd3402..f9e703ef 100644 --- a/envelope/internal/tests/enums/types.go +++ b/envelope/internal/tests/enums/types.go @@ -1398,7 +1398,9 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.E != nil { - enc.AddObject("e", *v.E) + if err := enc.AddObject("e", *v.E); err != nil { + return err + } } return nil diff --git a/envelope/internal/tests/services/conflictingnames_setvalue.go b/envelope/internal/tests/services/conflictingnames_setvalue.go index 559b0391..91e8ba1d 100644 --- a/envelope/internal/tests/services/conflictingnames_setvalue.go +++ b/envelope/internal/tests/services/conflictingnames_setvalue.go @@ -147,7 +147,9 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { - enc.AddObject("request", v.Request) + if err := enc.AddObject("request", v.Request); err != nil { + return err + } } return nil diff --git a/envelope/internal/tests/services/keyvalue_deletevalue.go b/envelope/internal/tests/services/keyvalue_deletevalue.go index b222bd87..2d43b7e2 100644 --- a/envelope/internal/tests/services/keyvalue_deletevalue.go +++ b/envelope/internal/tests/services/keyvalue_deletevalue.go @@ -455,11 +455,15 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DoesNotExist != nil { - enc.AddObject("doesNotExist", v.DoesNotExist) + if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { + return err + } } if v.InternalError != nil { - enc.AddObject("internalError", v.InternalError) + if err := enc.AddObject("internalError", v.InternalError); err != nil { + return err + } } return nil diff --git a/envelope/internal/tests/services/keyvalue_getmanyvalues.go b/envelope/internal/tests/services/keyvalue_getmanyvalues.go index a112f248..ff79977a 100644 --- a/envelope/internal/tests/services/keyvalue_getmanyvalues.go +++ b/envelope/internal/tests/services/keyvalue_getmanyvalues.go @@ -212,7 +212,9 @@ func (vals _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Range != nil { - enc.AddArray("range", (_List_Key_Zapper)(v.Range)) + if err := enc.AddArray("range", (_List_Key_Zapper)(v.Range)); err != nil { + return err + } } return nil @@ -559,7 +561,9 @@ type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -568,11 +572,15 @@ func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { - enc.AddArray("success", (_List_ArbitraryValue_Zapper)(v.Success)) + if err := enc.AddArray("success", (_List_ArbitraryValue_Zapper)(v.Success)); err != nil { + return err + } } if v.DoesNotExist != nil { - enc.AddObject("doesNotExist", v.DoesNotExist) + if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { + return err + } } return nil diff --git a/envelope/internal/tests/services/keyvalue_getvalue.go b/envelope/internal/tests/services/keyvalue_getvalue.go index 7dee288e..82cfa37e 100644 --- a/envelope/internal/tests/services/keyvalue_getvalue.go +++ b/envelope/internal/tests/services/keyvalue_getvalue.go @@ -425,11 +425,15 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { - enc.AddObject("success", v.Success) + if err := enc.AddObject("success", v.Success); err != nil { + return err + } } if v.DoesNotExist != nil { - enc.AddObject("doesNotExist", v.DoesNotExist) + if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { + return err + } } return nil diff --git a/envelope/internal/tests/services/keyvalue_setvalue.go b/envelope/internal/tests/services/keyvalue_setvalue.go index 688d0e6c..79e2aca9 100644 --- a/envelope/internal/tests/services/keyvalue_setvalue.go +++ b/envelope/internal/tests/services/keyvalue_setvalue.go @@ -172,7 +172,9 @@ func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) err } if v.Value != nil { - enc.AddObject("value", v.Value) + if err := enc.AddObject("value", v.Value); err != nil { + return err + } } return nil diff --git a/envelope/internal/tests/services/keyvalue_setvaluev2.go b/envelope/internal/tests/services/keyvalue_setvaluev2.go index 61e06132..53c5b664 100644 --- a/envelope/internal/tests/services/keyvalue_setvaluev2.go +++ b/envelope/internal/tests/services/keyvalue_setvaluev2.go @@ -178,7 +178,9 @@ func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) e enc.AddString("key", (string)(v.Key)) - enc.AddObject("value", v.Value) + if err := enc.AddObject("value", v.Value); err != nil { + return err + } return nil } diff --git a/envelope/internal/tests/structs/types.go b/envelope/internal/tests/structs/types.go index 1b89e5c7..128645ad 100644 --- a/envelope/internal/tests/structs/types.go +++ b/envelope/internal/tests/structs/types.go @@ -729,27 +729,39 @@ func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { } if v.RequiredEnum != nil { - enc.AddObject("requiredEnum", *v.RequiredEnum) + if err := enc.AddObject("requiredEnum", *v.RequiredEnum); err != nil { + return err + } } if v.OptionalEnum != nil { - enc.AddObject("optionalEnum", *v.OptionalEnum) + if err := enc.AddObject("optionalEnum", *v.OptionalEnum); err != nil { + return err + } } if v.RequiredList != nil { - enc.AddArray("requiredList", (_List_String_Zapper)(v.RequiredList)) + if err := enc.AddArray("requiredList", (_List_String_Zapper)(v.RequiredList)); err != nil { + return err + } } if v.OptionalList != nil { - enc.AddArray("optionalList", (_List_Double_Zapper)(v.OptionalList)) + if err := enc.AddArray("optionalList", (_List_Double_Zapper)(v.OptionalList)); err != nil { + return err + } } if v.RequiredStruct != nil { - enc.AddObject("requiredStruct", v.RequiredStruct) + if err := enc.AddObject("requiredStruct", v.RequiredStruct); err != nil { + return err + } } if v.OptionalStruct != nil { - enc.AddObject("optionalStruct", v.OptionalStruct) + if err := enc.AddObject("optionalStruct", v.OptionalStruct); err != nil { + return err + } } return nil @@ -1006,9 +1018,13 @@ func (v *Edge) Equals(rhs *Edge) bool { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("startPoint", v.StartPoint) + if err := enc.AddObject("startPoint", v.StartPoint); err != nil { + return err + } - enc.AddObject("endPoint", v.EndPoint) + if err := enc.AddObject("endPoint", v.EndPoint); err != nil { + return err + } return nil } @@ -1249,9 +1265,13 @@ func (v *Frame) Equals(rhs *Frame) bool { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("topLeft", v.TopLeft) + if err := enc.AddObject("topLeft", v.TopLeft); err != nil { + return err + } - enc.AddObject("size", v.Size) + if err := enc.AddObject("size", v.Size); err != nil { + return err + } return nil } @@ -1749,7 +1769,9 @@ type _List_Edge_Zapper []*Edge func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -1757,7 +1779,9 @@ func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)) + if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { + return err + } return nil } @@ -1939,7 +1963,9 @@ func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", v.Value) if v.Tail != nil { - enc.AddObject("tail", (*Node)(v.Tail)) + if err := enc.AddObject("tail", (*Node)(v.Tail)); err != nil { + return err + } } return nil @@ -3509,7 +3535,9 @@ func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) if v.Contact != nil { - enc.AddObject("contact", v.Contact) + if err := enc.AddObject("contact", v.Contact); err != nil { + return err + } } return nil diff --git a/envelope/internal/tests/typedefs/types.go b/envelope/internal/tests/typedefs/types.go index 0bbebb85..34e45f0c 100644 --- a/envelope/internal/tests/typedefs/types.go +++ b/envelope/internal/tests/typedefs/types.go @@ -609,7 +609,9 @@ func (v *Event) Equals(rhs *Event) bool { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("uuid", (*I128)(v.UUID)) + if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { + return err + } if v.Time != nil { enc.AddInt64("time", (int64)(*v.Time)) @@ -1298,7 +1300,9 @@ type _EventGroup_Zapper []*Event func (vals _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -1311,7 +1315,9 @@ func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("toState", (string)(v.ToState)) if v.Events != nil { - enc.AddArray("events", (_EventGroup_Zapper)(([]*Event)(v.Events))) + if err := enc.AddArray("events", (_EventGroup_Zapper)(([]*Event)(v.Events))); err != nil { + return err + } } return nil diff --git a/envelope/internal/tests/unions/types.go b/envelope/internal/tests/unions/types.go index f1ec7b10..c3ce4bc0 100644 --- a/envelope/internal/tests/unions/types.go +++ b/envelope/internal/tests/unions/types.go @@ -456,7 +456,9 @@ type _List_ArbitraryValue_Zapper []*ArbitraryValue func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -465,7 +467,9 @@ type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { - enc.AddObject((string)(k), v) + if err := enc.AddObject((string)(k), v); err != nil { + return err + } } return nil } @@ -486,11 +490,15 @@ func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { } if v.ListValue != nil { - enc.AddArray("listValue", (_List_ArbitraryValue_Zapper)(v.ListValue)) + if err := enc.AddArray("listValue", (_List_ArbitraryValue_Zapper)(v.ListValue)); err != nil { + return err + } } if v.MapValue != nil { - enc.AddObject("mapValue", (_Map_String_ArbitraryValue_Zapper)(v.MapValue)) + if err := enc.AddObject("mapValue", (_Map_String_ArbitraryValue_Zapper)(v.MapValue)); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/collision/types.go b/gen/internal/tests/collision/types.go index 641674bf..95f233c3 100644 --- a/gen/internal/tests/collision/types.go +++ b/gen/internal/tests/collision/types.go @@ -953,7 +953,6 @@ type _Set_String_Zapper map[string]struct{} func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { - enc.AppendString(v) } return nil @@ -972,15 +971,21 @@ func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEnco func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.A != nil { - enc.AddArray("ListOrSetOrMap", (_List_String_Zapper)(v.A)) + if err := enc.AddArray("ListOrSetOrMap", (_List_String_Zapper)(v.A)); err != nil { + return err + } } if v.B != nil { - enc.AddArray("List_Or_SetOrMap", (_Set_String_Zapper)(v.B)) + if err := enc.AddArray("List_Or_SetOrMap", (_Set_String_Zapper)(v.B)); err != nil { + return err + } } if v.C != nil { - enc.AddObject("ListOrSet_Or_Map", (_Map_String_String_Zapper)(v.C)) + if err := enc.AddObject("ListOrSet_Or_Map", (_Map_String_String_Zapper)(v.C)); err != nil { + return err + } } return nil @@ -1484,7 +1489,9 @@ func (v *WithDefault) Equals(rhs *WithDefault) bool { func (v *WithDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Pouet != nil { - enc.AddObject("pouet", v.Pouet) + if err := enc.AddObject("pouet", v.Pouet); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/containers/types.go b/gen/internal/tests/containers/types.go index 0a8c855c..45138c11 100644 --- a/gen/internal/tests/containers/types.go +++ b/gen/internal/tests/containers/types.go @@ -1667,7 +1667,9 @@ type _List_List_I32_Zapper [][]int32 func (vals _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendArray((_List_I32_Zapper)(val)) + if err := enc.AppendArray((_List_I32_Zapper)(val)); err != nil { + return err + } } return nil } @@ -1676,7 +1678,6 @@ type _Set_I32_Zapper map[int32]struct{} func (vals _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { - enc.AppendInt32(v) } return nil @@ -1686,7 +1687,9 @@ type _List_Set_I32_Zapper []map[int32]struct{} func (vals _List_Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendArray((_Set_I32_Zapper)(val)) + if err := enc.AppendArray((_Set_I32_Zapper)(val)); err != nil { + return err + } } return nil } @@ -1706,7 +1709,9 @@ type _Map_I32_I32_Zapper map[int32]int32 func (keyvals _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { - enc.AppendObject(_MapItem_I32_I32_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_I32_I32_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -1715,7 +1720,9 @@ type _List_Map_I32_I32_Zapper []map[int32]int32 func (vals _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendArray((_Map_I32_I32_Zapper)(val)) + if err := enc.AppendArray((_Map_I32_I32_Zapper)(val)); err != nil { + return err + } } return nil } @@ -1724,7 +1731,6 @@ type _Set_String_Zapper map[string]struct{} func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { - enc.AppendString(v) } return nil @@ -1734,8 +1740,9 @@ type _Set_Set_String_Zapper []map[string]struct{} func (vals _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range vals { - - enc.AppendArray((_Set_String_Zapper)(v)) + if err := enc.AppendArray((_Set_String_Zapper)(v)); err != nil { + return err + } } return nil } @@ -1753,8 +1760,9 @@ type _Set_List_String_Zapper [][]string func (vals _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range vals { - - enc.AppendArray((_List_String_Zapper)(v)) + if err := enc.AppendArray((_List_String_Zapper)(v)); err != nil { + return err + } } return nil } @@ -1772,8 +1780,9 @@ type _Set_Map_String_String_Zapper []map[string]string func (vals _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range vals { - - enc.AppendObject((_Map_String_String_Zapper)(v)) + if err := enc.AppendObject((_Map_String_String_Zapper)(v)); err != nil { + return err + } } return nil } @@ -1793,7 +1802,9 @@ type _MapItem_Map_String_I32_I64_Zapper struct { } func (v _MapItem_Map_String_I32_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("key", (_Map_String_I32_Zapper)(v.Key)) + if err := enc.AddObject("key", (_Map_String_I32_Zapper)(v.Key)); err != nil { + return err + } enc.AddInt64("value", v.Value) return nil } @@ -1807,7 +1818,9 @@ func (keyvals _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayE for _, i := range keyvals { k := i.Key v := i.Value - enc.AppendObject(_MapItem_Map_String_I32_I64_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_Map_String_I32_I64_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -1816,7 +1829,6 @@ type _Set_I64_Zapper map[int64]struct{} func (vals _Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { - enc.AppendInt64(v) } return nil @@ -1828,8 +1840,12 @@ type _MapItem_List_I32_Set_I64_Zapper struct { } func (v _MapItem_List_I32_Set_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddArray("key", (_List_I32_Zapper)(v.Key)) - enc.AddArray("value", (_Set_I64_Zapper)(v.Value)) + if err := enc.AddArray("key", (_List_I32_Zapper)(v.Key)); err != nil { + return err + } + if err := enc.AddArray("value", (_Set_I64_Zapper)(v.Value)); err != nil { + return err + } return nil } @@ -1842,7 +1858,9 @@ func (keyvals _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEnc for _, i := range keyvals { k := i.Key v := i.Value - enc.AppendObject(_MapItem_List_I32_Set_I64_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_List_I32_Set_I64_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -1862,8 +1880,12 @@ type _MapItem_Set_I32_List_Double_Zapper struct { } func (v _MapItem_Set_I32_List_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddArray("key", (_Set_I32_Zapper)(v.Key)) - enc.AddArray("value", (_List_Double_Zapper)(v.Value)) + if err := enc.AddArray("key", (_Set_I32_Zapper)(v.Key)); err != nil { + return err + } + if err := enc.AddArray("value", (_List_Double_Zapper)(v.Value)); err != nil { + return err + } return nil } @@ -1876,7 +1898,9 @@ func (keyvals _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.Array for _, i := range keyvals { k := i.Key v := i.Value - enc.AppendObject(_MapItem_Set_I32_List_Double_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_Set_I32_List_Double_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -1885,39 +1909,57 @@ func (keyvals _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.Array func (v *ContainersOfContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfLists != nil { - enc.AddArray("listOfLists", (_List_List_I32_Zapper)(v.ListOfLists)) + if err := enc.AddArray("listOfLists", (_List_List_I32_Zapper)(v.ListOfLists)); err != nil { + return err + } } if v.ListOfSets != nil { - enc.AddArray("listOfSets", (_List_Set_I32_Zapper)(v.ListOfSets)) + if err := enc.AddArray("listOfSets", (_List_Set_I32_Zapper)(v.ListOfSets)); err != nil { + return err + } } if v.ListOfMaps != nil { - enc.AddArray("listOfMaps", (_List_Map_I32_I32_Zapper)(v.ListOfMaps)) + if err := enc.AddArray("listOfMaps", (_List_Map_I32_I32_Zapper)(v.ListOfMaps)); err != nil { + return err + } } if v.SetOfSets != nil { - enc.AddArray("setOfSets", (_Set_Set_String_Zapper)(v.SetOfSets)) + if err := enc.AddArray("setOfSets", (_Set_Set_String_Zapper)(v.SetOfSets)); err != nil { + return err + } } if v.SetOfLists != nil { - enc.AddArray("setOfLists", (_Set_List_String_Zapper)(v.SetOfLists)) + if err := enc.AddArray("setOfLists", (_Set_List_String_Zapper)(v.SetOfLists)); err != nil { + return err + } } if v.SetOfMaps != nil { - enc.AddArray("setOfMaps", (_Set_Map_String_String_Zapper)(v.SetOfMaps)) + if err := enc.AddArray("setOfMaps", (_Set_Map_String_String_Zapper)(v.SetOfMaps)); err != nil { + return err + } } if v.MapOfMapToInt != nil { - enc.AddArray("mapOfMapToInt", (_Map_Map_String_I32_I64_Zapper)(v.MapOfMapToInt)) + if err := enc.AddArray("mapOfMapToInt", (_Map_Map_String_I32_I64_Zapper)(v.MapOfMapToInt)); err != nil { + return err + } } if v.MapOfListToSet != nil { - enc.AddArray("mapOfListToSet", (_Map_List_I32_Set_I64_Zapper)(v.MapOfListToSet)) + if err := enc.AddArray("mapOfListToSet", (_Map_List_I32_Set_I64_Zapper)(v.MapOfListToSet)); err != nil { + return err + } } if v.MapOfSetToListOfDouble != nil { - enc.AddArray("mapOfSetToListOfDouble", (_Map_Set_I32_List_Double_Zapper)(v.MapOfSetToListOfDouble)) + if err := enc.AddArray("mapOfSetToListOfDouble", (_Map_Set_I32_List_Double_Zapper)(v.MapOfSetToListOfDouble)); err != nil { + return err + } } return nil @@ -2394,7 +2436,9 @@ type _List_EnumDefault_Zapper []enums.EnumDefault func (vals _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -2403,8 +2447,9 @@ type _Set_EnumWithValues_Zapper map[enums.EnumWithValues]struct{} func (vals _Set_EnumWithValues_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { - - enc.AppendObject(v) + if err := enc.AppendObject(v); err != nil { + return err + } } return nil } @@ -2415,7 +2460,9 @@ type _MapItem_EnumWithDuplicateValues_I32_Zapper struct { } func (v _MapItem_EnumWithDuplicateValues_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("key", v.Key) + if err := enc.AddObject("key", v.Key); err != nil { + return err + } enc.AddInt32("value", v.Value) return nil } @@ -2424,7 +2471,9 @@ type _Map_EnumWithDuplicateValues_I32_Zapper map[enums.EnumWithDuplicateValues]i func (keyvals _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { - enc.AppendObject(_MapItem_EnumWithDuplicateValues_I32_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_EnumWithDuplicateValues_I32_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -2433,15 +2482,21 @@ func (keyvals _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapco func (v *EnumContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfEnums != nil { - enc.AddArray("listOfEnums", (_List_EnumDefault_Zapper)(v.ListOfEnums)) + if err := enc.AddArray("listOfEnums", (_List_EnumDefault_Zapper)(v.ListOfEnums)); err != nil { + return err + } } if v.SetOfEnums != nil { - enc.AddArray("setOfEnums", (_Set_EnumWithValues_Zapper)(v.SetOfEnums)) + if err := enc.AddArray("setOfEnums", (_Set_EnumWithValues_Zapper)(v.SetOfEnums)); err != nil { + return err + } } if v.MapOfEnums != nil { - enc.AddArray("mapOfEnums", (_Map_EnumWithDuplicateValues_I32_Zapper)(v.MapOfEnums)) + if err := enc.AddArray("mapOfEnums", (_Map_EnumWithDuplicateValues_I32_Zapper)(v.MapOfEnums)); err != nil { + return err + } } return nil @@ -2748,7 +2803,9 @@ type _List_RecordType_Zapper []enum_conflict.RecordType func (vals _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -2757,7 +2814,9 @@ type _List_RecordType_1_Zapper []enums.RecordType func (vals _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -2765,9 +2824,13 @@ func (vals _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *ListOfConflictingEnums) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddArray("records", (_List_RecordType_Zapper)(v.Records)) + if err := enc.AddArray("records", (_List_RecordType_Zapper)(v.Records)); err != nil { + return err + } - enc.AddArray("otherRecords", (_List_RecordType_1_Zapper)(v.OtherRecords)) + if err := enc.AddArray("otherRecords", (_List_RecordType_1_Zapper)(v.OtherRecords)); err != nil { + return err + } return nil } @@ -3054,7 +3117,9 @@ type _List_UUID_Zapper []*typedefs.UUID func (vals _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject((*typedefs.I128)(val)) + if err := enc.AppendObject((*typedefs.I128)(val)); err != nil { + return err + } } return nil } @@ -3071,9 +3136,13 @@ func (vals _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *ListOfConflictingUUIDs) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddArray("uuids", (_List_UUID_Zapper)(v.Uuids)) + if err := enc.AddArray("uuids", (_List_UUID_Zapper)(v.Uuids)); err != nil { + return err + } - enc.AddArray("otherUUIDs", (_List_UUID_1_Zapper)(v.OtherUUIDs)) + if err := enc.AddArray("otherUUIDs", (_List_UUID_1_Zapper)(v.OtherUUIDs)); err != nil { + return err + } return nil } @@ -3433,7 +3502,9 @@ func (keyvals _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncode for _, i := range keyvals { k := i.Key v := i.Value - enc.AppendObject(_MapItem_Binary_String_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_Binary_String_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -3451,11 +3522,15 @@ func (keyvals _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEnco func (v *MapOfBinaryAndString) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BinaryToString != nil { - enc.AddArray("binaryToString", (_Map_Binary_String_Zapper)(v.BinaryToString)) + if err := enc.AddArray("binaryToString", (_Map_Binary_String_Zapper)(v.BinaryToString)); err != nil { + return err + } } if v.StringToBinary != nil { - enc.AddObject("stringToBinary", (_Map_String_Binary_Zapper)(v.StringToBinary)) + if err := enc.AddObject("stringToBinary", (_Map_String_Binary_Zapper)(v.StringToBinary)); err != nil { + return err + } } return nil @@ -4070,7 +4145,6 @@ type _Set_Byte_Zapper map[int8]struct{} func (vals _Set_Byte_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { - enc.AppendInt8(v) } return nil @@ -4091,7 +4165,9 @@ type _Map_I32_String_Zapper map[int32]string func (keyvals _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { - enc.AppendObject(_MapItem_I32_String_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_I32_String_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -4109,27 +4185,39 @@ func (keyvals _Map_String_Bool_Zapper) MarshalLogObject(enc zapcore.ObjectEncode func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfBinary != nil { - enc.AddArray("listOfBinary", (_List_Binary_Zapper)(v.ListOfBinary)) + if err := enc.AddArray("listOfBinary", (_List_Binary_Zapper)(v.ListOfBinary)); err != nil { + return err + } } if v.ListOfInts != nil { - enc.AddArray("listOfInts", (_List_I64_Zapper)(v.ListOfInts)) + if err := enc.AddArray("listOfInts", (_List_I64_Zapper)(v.ListOfInts)); err != nil { + return err + } } if v.SetOfStrings != nil { - enc.AddArray("setOfStrings", (_Set_String_Zapper)(v.SetOfStrings)) + if err := enc.AddArray("setOfStrings", (_Set_String_Zapper)(v.SetOfStrings)); err != nil { + return err + } } if v.SetOfBytes != nil { - enc.AddArray("setOfBytes", (_Set_Byte_Zapper)(v.SetOfBytes)) + if err := enc.AddArray("setOfBytes", (_Set_Byte_Zapper)(v.SetOfBytes)); err != nil { + return err + } } if v.MapOfIntToString != nil { - enc.AddArray("mapOfIntToString", (_Map_I32_String_Zapper)(v.MapOfIntToString)) + if err := enc.AddArray("mapOfIntToString", (_Map_I32_String_Zapper)(v.MapOfIntToString)); err != nil { + return err + } } if v.MapOfStringToBool != nil { - enc.AddObject("mapOfStringToBool", (_Map_String_Bool_Zapper)(v.MapOfStringToBool)) + if err := enc.AddObject("mapOfStringToBool", (_Map_String_Bool_Zapper)(v.MapOfStringToBool)); err != nil { + return err + } } return nil @@ -4455,7 +4543,9 @@ type _Map_I64_Double_Zapper map[int64]float64 func (keyvals _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { - enc.AppendObject(_MapItem_I64_Double_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_I64_Double_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -4463,11 +4553,17 @@ func (keyvals _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *PrimitiveContainersRequired) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddArray("listOfStrings", (_List_String_Zapper)(v.ListOfStrings)) + if err := enc.AddArray("listOfStrings", (_List_String_Zapper)(v.ListOfStrings)); err != nil { + return err + } - enc.AddArray("setOfInts", (_Set_I32_Zapper)(v.SetOfInts)) + if err := enc.AddArray("setOfInts", (_Set_I32_Zapper)(v.SetOfInts)); err != nil { + return err + } - enc.AddArray("mapOfIntsToDoubles", (_Map_I64_Double_Zapper)(v.MapOfIntsToDoubles)) + if err := enc.AddArray("mapOfIntsToDoubles", (_Map_I64_Double_Zapper)(v.MapOfIntsToDoubles)); err != nil { + return err + } return nil } diff --git a/gen/internal/tests/enum_conflict/types.go b/gen/internal/tests/enum_conflict/types.go index b3a78735..03a3d583 100644 --- a/gen/internal/tests/enum_conflict/types.go +++ b/gen/internal/tests/enum_conflict/types.go @@ -368,11 +368,15 @@ func (v *Records) Equals(rhs *Records) bool { func (v *Records) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.RecordType != nil { - enc.AddObject("recordType", *v.RecordType) + if err := enc.AddObject("recordType", *v.RecordType); err != nil { + return err + } } if v.OtherRecordType != nil { - enc.AddObject("otherRecordType", *v.OtherRecordType) + if err := enc.AddObject("otherRecordType", *v.OtherRecordType); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/enums/types.go b/gen/internal/tests/enums/types.go index bd1efd2c..3388aced 100644 --- a/gen/internal/tests/enums/types.go +++ b/gen/internal/tests/enums/types.go @@ -1378,7 +1378,9 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.E != nil { - enc.AddObject("e", *v.E) + if err := enc.AddObject("e", *v.E); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/services/conflictingnames_setvalue.go b/gen/internal/tests/services/conflictingnames_setvalue.go index 1bd5f879..993bc12a 100644 --- a/gen/internal/tests/services/conflictingnames_setvalue.go +++ b/gen/internal/tests/services/conflictingnames_setvalue.go @@ -127,7 +127,9 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { - enc.AddObject("request", v.Request) + if err := enc.AddObject("request", v.Request); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/services/keyvalue_deletevalue.go b/gen/internal/tests/services/keyvalue_deletevalue.go index dbd99df5..62897187 100644 --- a/gen/internal/tests/services/keyvalue_deletevalue.go +++ b/gen/internal/tests/services/keyvalue_deletevalue.go @@ -435,11 +435,15 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DoesNotExist != nil { - enc.AddObject("doesNotExist", v.DoesNotExist) + if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { + return err + } } if v.InternalError != nil { - enc.AddObject("internalError", v.InternalError) + if err := enc.AddObject("internalError", v.InternalError); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/services/keyvalue_getmanyvalues.go b/gen/internal/tests/services/keyvalue_getmanyvalues.go index 63102e3a..44d81b52 100644 --- a/gen/internal/tests/services/keyvalue_getmanyvalues.go +++ b/gen/internal/tests/services/keyvalue_getmanyvalues.go @@ -192,7 +192,9 @@ func (vals _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Range != nil { - enc.AddArray("range", (_List_Key_Zapper)(v.Range)) + if err := enc.AddArray("range", (_List_Key_Zapper)(v.Range)); err != nil { + return err + } } return nil @@ -539,7 +541,9 @@ type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -548,11 +552,15 @@ func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { - enc.AddArray("success", (_List_ArbitraryValue_Zapper)(v.Success)) + if err := enc.AddArray("success", (_List_ArbitraryValue_Zapper)(v.Success)); err != nil { + return err + } } if v.DoesNotExist != nil { - enc.AddObject("doesNotExist", v.DoesNotExist) + if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/services/keyvalue_getvalue.go b/gen/internal/tests/services/keyvalue_getvalue.go index 945093fc..bf796ad6 100644 --- a/gen/internal/tests/services/keyvalue_getvalue.go +++ b/gen/internal/tests/services/keyvalue_getvalue.go @@ -405,11 +405,15 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { - enc.AddObject("success", v.Success) + if err := enc.AddObject("success", v.Success); err != nil { + return err + } } if v.DoesNotExist != nil { - enc.AddObject("doesNotExist", v.DoesNotExist) + if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/services/keyvalue_setvalue.go b/gen/internal/tests/services/keyvalue_setvalue.go index 5e98aec2..b6730ae5 100644 --- a/gen/internal/tests/services/keyvalue_setvalue.go +++ b/gen/internal/tests/services/keyvalue_setvalue.go @@ -152,7 +152,9 @@ func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) err } if v.Value != nil { - enc.AddObject("value", v.Value) + if err := enc.AddObject("value", v.Value); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/services/keyvalue_setvaluev2.go b/gen/internal/tests/services/keyvalue_setvaluev2.go index 07f87201..9601bab8 100644 --- a/gen/internal/tests/services/keyvalue_setvaluev2.go +++ b/gen/internal/tests/services/keyvalue_setvaluev2.go @@ -158,7 +158,9 @@ func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) e enc.AddString("key", (string)(v.Key)) - enc.AddObject("value", v.Value) + if err := enc.AddObject("value", v.Value); err != nil { + return err + } return nil } diff --git a/gen/internal/tests/structs/types.go b/gen/internal/tests/structs/types.go index 515bb0be..3ff86a00 100644 --- a/gen/internal/tests/structs/types.go +++ b/gen/internal/tests/structs/types.go @@ -709,27 +709,39 @@ func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { } if v.RequiredEnum != nil { - enc.AddObject("requiredEnum", *v.RequiredEnum) + if err := enc.AddObject("requiredEnum", *v.RequiredEnum); err != nil { + return err + } } if v.OptionalEnum != nil { - enc.AddObject("optionalEnum", *v.OptionalEnum) + if err := enc.AddObject("optionalEnum", *v.OptionalEnum); err != nil { + return err + } } if v.RequiredList != nil { - enc.AddArray("requiredList", (_List_String_Zapper)(v.RequiredList)) + if err := enc.AddArray("requiredList", (_List_String_Zapper)(v.RequiredList)); err != nil { + return err + } } if v.OptionalList != nil { - enc.AddArray("optionalList", (_List_Double_Zapper)(v.OptionalList)) + if err := enc.AddArray("optionalList", (_List_Double_Zapper)(v.OptionalList)); err != nil { + return err + } } if v.RequiredStruct != nil { - enc.AddObject("requiredStruct", v.RequiredStruct) + if err := enc.AddObject("requiredStruct", v.RequiredStruct); err != nil { + return err + } } if v.OptionalStruct != nil { - enc.AddObject("optionalStruct", v.OptionalStruct) + if err := enc.AddObject("optionalStruct", v.OptionalStruct); err != nil { + return err + } } return nil @@ -986,9 +998,13 @@ func (v *Edge) Equals(rhs *Edge) bool { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("startPoint", v.StartPoint) + if err := enc.AddObject("startPoint", v.StartPoint); err != nil { + return err + } - enc.AddObject("endPoint", v.EndPoint) + if err := enc.AddObject("endPoint", v.EndPoint); err != nil { + return err + } return nil } @@ -1229,9 +1245,13 @@ func (v *Frame) Equals(rhs *Frame) bool { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("topLeft", v.TopLeft) + if err := enc.AddObject("topLeft", v.TopLeft); err != nil { + return err + } - enc.AddObject("size", v.Size) + if err := enc.AddObject("size", v.Size); err != nil { + return err + } return nil } @@ -1729,7 +1749,9 @@ type _List_Edge_Zapper []*Edge func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -1737,7 +1759,9 @@ func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)) + if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { + return err + } return nil } @@ -1919,7 +1943,9 @@ func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", v.Value) if v.Tail != nil { - enc.AddObject("tail", (*Node)(v.Tail)) + if err := enc.AddObject("tail", (*Node)(v.Tail)); err != nil { + return err + } } return nil @@ -3489,7 +3515,9 @@ func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) if v.Contact != nil { - enc.AddObject("contact", v.Contact) + if err := enc.AddObject("contact", v.Contact); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/typedefs/types.go b/gen/internal/tests/typedefs/types.go index fb9ca735..41879895 100644 --- a/gen/internal/tests/typedefs/types.go +++ b/gen/internal/tests/typedefs/types.go @@ -589,7 +589,9 @@ func (v *Event) Equals(rhs *Event) bool { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("uuid", (*I128)(v.UUID)) + if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { + return err + } if v.Time != nil { enc.AddInt64("time", (int64)(*v.Time)) @@ -1278,7 +1280,9 @@ type _EventGroup_Zapper []*Event func (vals _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -1291,7 +1295,9 @@ func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("toState", (string)(v.ToState)) if v.Events != nil { - enc.AddArray("events", (_EventGroup_Zapper)(([]*Event)(v.Events))) + if err := enc.AddArray("events", (_EventGroup_Zapper)(([]*Event)(v.Events))); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/unions/types.go b/gen/internal/tests/unions/types.go index 462ed961..916f10f5 100644 --- a/gen/internal/tests/unions/types.go +++ b/gen/internal/tests/unions/types.go @@ -436,7 +436,9 @@ type _List_ArbitraryValue_Zapper []*ArbitraryValue func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -445,7 +447,9 @@ type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { - enc.AddObject((string)(k), v) + if err := enc.AddObject((string)(k), v); err != nil { + return err + } } return nil } @@ -466,11 +470,15 @@ func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { } if v.ListValue != nil { - enc.AddArray("listValue", (_List_ArbitraryValue_Zapper)(v.ListValue)) + if err := enc.AddArray("listValue", (_List_ArbitraryValue_Zapper)(v.ListValue)); err != nil { + return err + } } if v.MapValue != nil { - enc.AddObject("mapValue", (_Map_String_ArbitraryValue_Zapper)(v.MapValue)) + if err := enc.AddObject("mapValue", (_Map_String_ArbitraryValue_Zapper)(v.MapValue)); err != nil { + return err + } } return nil diff --git a/gen/internal/tests/uuid_conflict/types.go b/gen/internal/tests/uuid_conflict/types.go index 69e9c43f..32be3b31 100644 --- a/gen/internal/tests/uuid_conflict/types.go +++ b/gen/internal/tests/uuid_conflict/types.go @@ -194,7 +194,9 @@ func (v *UUIDConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("localUUID", (string)(v.LocalUUID)) - enc.AddObject("importedUUID", (*typedefs.I128)(v.ImportedUUID)) + if err := enc.AddObject("importedUUID", (*typedefs.I128)(v.ImportedUUID)); err != nil { + return err + } return nil } diff --git a/internal/envelope/exception/types.go b/internal/envelope/exception/types.go index 9a7f898a..f0aae8fe 100644 --- a/internal/envelope/exception/types.go +++ b/internal/envelope/exception/types.go @@ -480,7 +480,9 @@ func (v *TApplicationException) MarshalLogObject(enc zapcore.ObjectEncoder) erro } if v.Type != nil { - enc.AddObject("type", *v.Type) + if err := enc.AddObject("type", *v.Type); err != nil { + return err + } } return nil diff --git a/plugin/api/plugin_handshake.go b/plugin/api/plugin_handshake.go index 5d6ed4d2..e23cf07f 100644 --- a/plugin/api/plugin_handshake.go +++ b/plugin/api/plugin_handshake.go @@ -148,7 +148,9 @@ func (v *Plugin_Handshake_Args) Equals(rhs *Plugin_Handshake_Args) bool { func (v *Plugin_Handshake_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { - enc.AddObject("request", v.Request) + if err := enc.AddObject("request", v.Request); err != nil { + return err + } } return nil @@ -392,7 +394,9 @@ func (v *Plugin_Handshake_Result) Equals(rhs *Plugin_Handshake_Result) bool { func (v *Plugin_Handshake_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { - enc.AddObject("success", v.Success) + if err := enc.AddObject("success", v.Success); err != nil { + return err + } } return nil diff --git a/plugin/api/servicegenerator_generate.go b/plugin/api/servicegenerator_generate.go index fae70013..b8ea96e0 100644 --- a/plugin/api/servicegenerator_generate.go +++ b/plugin/api/servicegenerator_generate.go @@ -148,7 +148,9 @@ func (v *ServiceGenerator_Generate_Args) Equals(rhs *ServiceGenerator_Generate_A func (v *ServiceGenerator_Generate_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { - enc.AddObject("request", v.Request) + if err := enc.AddObject("request", v.Request); err != nil { + return err + } } return nil @@ -392,7 +394,9 @@ func (v *ServiceGenerator_Generate_Result) Equals(rhs *ServiceGenerator_Generate func (v *ServiceGenerator_Generate_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { - enc.AddObject("success", v.Success) + if err := enc.AddObject("success", v.Success); err != nil { + return err + } } return nil diff --git a/plugin/api/types.go b/plugin/api/types.go index ffe1bb3c..e5a7fe4d 100644 --- a/plugin/api/types.go +++ b/plugin/api/types.go @@ -194,7 +194,9 @@ func (v *Argument) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) - enc.AddObject("type", v.Type) + if err := enc.AddObject("type", v.Type); err != nil { + return err + } return nil } @@ -808,7 +810,9 @@ type _List_Argument_Zapper []*Argument func (vals _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -829,14 +833,20 @@ func (v *Function) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("thriftName", v.ThriftName) - enc.AddArray("arguments", (_List_Argument_Zapper)(v.Arguments)) + if err := enc.AddArray("arguments", (_List_Argument_Zapper)(v.Arguments)); err != nil { + return err + } if v.ReturnType != nil { - enc.AddObject("returnType", v.ReturnType) + if err := enc.AddObject("returnType", v.ReturnType); err != nil { + return err + } } if v.Exceptions != nil { - enc.AddArray("exceptions", (_List_Argument_Zapper)(v.Exceptions)) + if err := enc.AddArray("exceptions", (_List_Argument_Zapper)(v.Exceptions)); err != nil { + return err + } } if v.OneWay != nil { @@ -844,7 +854,9 @@ func (v *Function) MarshalLogObject(enc zapcore.ObjectEncoder) error { } if v.Annotations != nil { - enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)) + if err := enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)); err != nil { + return err + } } return nil @@ -1348,7 +1360,9 @@ type _MapItem_ServiceID_Service_Zapper struct { func (v _MapItem_ServiceID_Service_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", (int32)(v.Key)) - enc.AddObject("value", v.Value) + if err := enc.AddObject("value", v.Value); err != nil { + return err + } return nil } @@ -1356,7 +1370,9 @@ type _Map_ServiceID_Service_Zapper map[ServiceID]*Service func (keyvals _Map_ServiceID_Service_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { - enc.AppendObject(_MapItem_ServiceID_Service_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_ServiceID_Service_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -1368,7 +1384,9 @@ type _MapItem_ModuleID_Module_Zapper struct { func (v _MapItem_ModuleID_Module_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", (int32)(v.Key)) - enc.AddObject("value", v.Value) + if err := enc.AddObject("value", v.Value); err != nil { + return err + } return nil } @@ -1376,7 +1394,9 @@ type _Map_ModuleID_Module_Zapper map[ModuleID]*Module func (keyvals _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { - enc.AppendObject(_MapItem_ModuleID_Module_Zapper{Key: k, Value: v}) + if err := enc.AppendObject(_MapItem_ModuleID_Module_Zapper{Key: k, Value: v}); err != nil { + return err + } } return nil } @@ -1384,11 +1404,17 @@ func (keyvals _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEnco // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *GenerateServiceRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddArray("rootServices", (_List_ServiceID_Zapper)(v.RootServices)) + if err := enc.AddArray("rootServices", (_List_ServiceID_Zapper)(v.RootServices)); err != nil { + return err + } - enc.AddArray("services", (_Map_ServiceID_Service_Zapper)(v.Services)) + if err := enc.AddArray("services", (_Map_ServiceID_Service_Zapper)(v.Services)); err != nil { + return err + } - enc.AddArray("modules", (_Map_ModuleID_Module_Zapper)(v.Modules)) + if err := enc.AddArray("modules", (_Map_ModuleID_Module_Zapper)(v.Modules)); err != nil { + return err + } return nil } @@ -1613,7 +1639,9 @@ func (keyvals _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEnco func (v *GenerateServiceResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Files != nil { - enc.AddObject("files", (_Map_String_Binary_Zapper)(v.Files)) + if err := enc.AddObject("files", (_Map_String_Binary_Zapper)(v.Files)); err != nil { + return err + } } return nil @@ -1989,7 +2017,9 @@ type _List_Feature_Zapper []Feature func (vals _List_Feature_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -2001,7 +2031,9 @@ func (v *HandshakeResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("apiVersion", v.APIVersion) - enc.AddArray("features", (_List_Feature_Zapper)(v.Features)) + if err := enc.AddArray("features", (_List_Feature_Zapper)(v.Features)); err != nil { + return err + } if v.LibraryVersion != nil { enc.AddString("libraryVersion", *v.LibraryVersion) @@ -2561,7 +2593,9 @@ type _List_Function_Zapper []*Function func (vals _List_Function_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { - enc.AppendObject(val) + if err := enc.AppendObject(val); err != nil { + return err + } } return nil } @@ -2577,12 +2611,16 @@ func (v *Service) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("parentID", (int32)(*v.ParentID)) } - enc.AddArray("functions", (_List_Function_Zapper)(v.Functions)) + if err := enc.AddArray("functions", (_List_Function_Zapper)(v.Functions)); err != nil { + return err + } enc.AddInt32("moduleID", (int32)(v.ModuleID)) if v.Annotations != nil { - enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)) + if err := enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)); err != nil { + return err + } } return nil @@ -3209,27 +3247,39 @@ func (v *Type) Equals(rhs *Type) bool { func (v *Type) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.SimpleType != nil { - enc.AddObject("simpleType", *v.SimpleType) + if err := enc.AddObject("simpleType", *v.SimpleType); err != nil { + return err + } } if v.SliceType != nil { - enc.AddObject("sliceType", v.SliceType) + if err := enc.AddObject("sliceType", v.SliceType); err != nil { + return err + } } if v.KeyValueSliceType != nil { - enc.AddObject("keyValueSliceType", v.KeyValueSliceType) + if err := enc.AddObject("keyValueSliceType", v.KeyValueSliceType); err != nil { + return err + } } if v.MapType != nil { - enc.AddObject("mapType", v.MapType) + if err := enc.AddObject("mapType", v.MapType); err != nil { + return err + } } if v.ReferenceType != nil { - enc.AddObject("referenceType", v.ReferenceType) + if err := enc.AddObject("referenceType", v.ReferenceType); err != nil { + return err + } } if v.PointerType != nil { - enc.AddObject("pointerType", v.PointerType) + if err := enc.AddObject("pointerType", v.PointerType); err != nil { + return err + } } return nil @@ -3436,9 +3486,13 @@ func (v *TypePair) Equals(rhs *TypePair) bool { // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v *TypePair) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddObject("left", v.Left) + if err := enc.AddObject("left", v.Left); err != nil { + return err + } - enc.AddObject("right", v.Right) + if err := enc.AddObject("right", v.Right); err != nil { + return err + } return nil } @@ -3635,7 +3689,9 @@ func (v *TypeReference) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("importPath", v.ImportPath) if v.Annotations != nil { - enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)) + if err := enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)); err != nil { + return err + } } return nil From af511503f05b0583825d2cbf6a92e52ecb5ec58b Mon Sep 17 00:00:00 2001 From: Minho Park Date: Fri, 27 Jul 2018 16:50:36 -0700 Subject: [PATCH 04/25] Add comment placeholders --- gen/zap.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gen/zap.go b/gen/zap.go index 0e396820..f9070d97 100644 --- a/gen/zap.go +++ b/gen/zap.go @@ -110,6 +110,7 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string <$keyvals := newVar "keyvals"> <$k := newVar "k"> <$v := newVar "v"> + // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (<$keyvals> <.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { for <$k>, <$v> := range <$keyvals> { if err := @@ -143,6 +144,7 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string <$k := newVar "k"> <$v := newVar "v"> <$i := newVar "i"> + // MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (<$keyvals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { <- if isHashable .Type.KeySpec -> for <$k>, <$v> := range <$keyvals> { @@ -179,6 +181,7 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string <$zapcore := import "go.uber.org/zap/zapcore"> <$vals := newVar "vals"> <$v := newVar "v"> + // MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (<$vals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { <- if isHashable .Type.ValueSpec -> for <$v> := range <$vals> { @@ -213,6 +216,7 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string type <.Name> <$zapcore := import "go.uber.org/zap/zapcore"> <$vals := newVar "vals"> + // MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (<$vals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { for _, val := range <$vals> { if err := @@ -268,6 +272,7 @@ func zapMapItemMarshaler( <$v := newVar "v"> <$key := printf "%s.%s" $v "Key"> <$val := printf "%s.%s" $v "Value"> + // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (<$v> <.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { if err := enc.Add("key", ) From cb70f077a27e3815c96a3c3b311c9274ba27f0d7 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Fri, 27 Jul 2018 16:57:05 -0700 Subject: [PATCH 05/25] Add test files --- .../tests/services/keyvalue_getmanyvalues.go | 2 + envelope/internal/tests/structs/types.go | 3 ++ envelope/internal/tests/typedefs/types.go | 1 + envelope/internal/tests/unions/types.go | 2 + gen/internal/tests/collision/types.go | 3 ++ gen/internal/tests/containers/types.go | 41 +++++++++++++++++++ .../tests/services/keyvalue_getmanyvalues.go | 2 + gen/internal/tests/structs/types.go | 3 ++ gen/internal/tests/typedefs/types.go | 1 + gen/internal/tests/unions/types.go | 2 + plugin/api/types.go | 10 +++++ 11 files changed, 70 insertions(+) diff --git a/envelope/internal/tests/services/keyvalue_getmanyvalues.go b/envelope/internal/tests/services/keyvalue_getmanyvalues.go index ff79977a..2fdb755a 100644 --- a/envelope/internal/tests/services/keyvalue_getmanyvalues.go +++ b/envelope/internal/tests/services/keyvalue_getmanyvalues.go @@ -201,6 +201,7 @@ func (v *KeyValue_GetManyValues_Args) Equals(rhs *KeyValue_GetManyValues_Args) b type _List_Key_Zapper []Key +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendString((string)(val)) @@ -559,6 +560,7 @@ func (v *KeyValue_GetManyValues_Result) Equals(rhs *KeyValue_GetManyValues_Resul type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { diff --git a/envelope/internal/tests/structs/types.go b/envelope/internal/tests/structs/types.go index 128645ad..8fa9b752 100644 --- a/envelope/internal/tests/structs/types.go +++ b/envelope/internal/tests/structs/types.go @@ -701,6 +701,7 @@ func (v *DefaultsStruct) Equals(rhs *DefaultsStruct) bool { type _List_String_Zapper []string +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendString(val) @@ -710,6 +711,7 @@ func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _List_Double_Zapper []float64 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendFloat64(val) @@ -1767,6 +1769,7 @@ func (v *Graph) Equals(rhs *Graph) bool { type _List_Edge_Zapper []*Edge +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { diff --git a/envelope/internal/tests/typedefs/types.go b/envelope/internal/tests/typedefs/types.go index 34e45f0c..0feb70b4 100644 --- a/envelope/internal/tests/typedefs/types.go +++ b/envelope/internal/tests/typedefs/types.go @@ -1298,6 +1298,7 @@ func (v *Transition) Equals(rhs *Transition) bool { type _EventGroup_Zapper []*Event +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { diff --git a/envelope/internal/tests/unions/types.go b/envelope/internal/tests/unions/types.go index c3ce4bc0..87cd43ec 100644 --- a/envelope/internal/tests/unions/types.go +++ b/envelope/internal/tests/unions/types.go @@ -454,6 +454,7 @@ func (v *ArbitraryValue) Equals(rhs *ArbitraryValue) bool { type _List_ArbitraryValue_Zapper []*ArbitraryValue +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { @@ -465,6 +466,7 @@ func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { if err := enc.AddObject((string)(k), v); err != nil { diff --git a/gen/internal/tests/collision/types.go b/gen/internal/tests/collision/types.go index 95f233c3..2cd6bc9b 100644 --- a/gen/internal/tests/collision/types.go +++ b/gen/internal/tests/collision/types.go @@ -942,6 +942,7 @@ func (v *PrimitiveContainers) Equals(rhs *PrimitiveContainers) bool { type _List_String_Zapper []string +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendString(val) @@ -951,6 +952,7 @@ func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _Set_String_Zapper map[string]struct{} +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { enc.AppendString(v) @@ -960,6 +962,7 @@ func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Map_String_String_Zapper map[string]string +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { enc.AddString((string)(k), v) diff --git a/gen/internal/tests/containers/types.go b/gen/internal/tests/containers/types.go index 45138c11..4b6b56fb 100644 --- a/gen/internal/tests/containers/types.go +++ b/gen/internal/tests/containers/types.go @@ -1656,6 +1656,7 @@ func (v *ContainersOfContainers) Equals(rhs *ContainersOfContainers) bool { type _List_I32_Zapper []int32 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendInt32(val) @@ -1665,6 +1666,7 @@ func (vals _List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_List_I32_Zapper [][]int32 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendArray((_List_I32_Zapper)(val)); err != nil { @@ -1676,6 +1678,7 @@ func (vals _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) erro type _Set_I32_Zapper map[int32]struct{} +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { enc.AppendInt32(v) @@ -1685,6 +1688,7 @@ func (vals _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_Set_I32_Zapper []map[int32]struct{} +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendArray((_Set_I32_Zapper)(val)); err != nil { @@ -1699,6 +1703,7 @@ type _MapItem_I32_I32_Zapper struct { Value int32 } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_I32_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", v.Key) enc.AddInt32("value", v.Value) @@ -1707,6 +1712,7 @@ func (v _MapItem_I32_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) err type _Map_I32_I32_Zapper map[int32]int32 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { if err := enc.AppendObject(_MapItem_I32_I32_Zapper{Key: k, Value: v}); err != nil { @@ -1718,6 +1724,7 @@ func (keyvals _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) err type _List_Map_I32_I32_Zapper []map[int32]int32 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendArray((_Map_I32_I32_Zapper)(val)); err != nil { @@ -1729,6 +1736,7 @@ func (vals _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e type _Set_String_Zapper map[string]struct{} +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { enc.AppendString(v) @@ -1738,6 +1746,7 @@ func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Set_Set_String_Zapper []map[string]struct{} +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range vals { if err := enc.AppendArray((_Set_String_Zapper)(v)); err != nil { @@ -1749,6 +1758,7 @@ func (vals _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) err type _List_String_Zapper []string +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendString(val) @@ -1758,6 +1768,7 @@ func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _Set_List_String_Zapper [][]string +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range vals { if err := enc.AppendArray((_List_String_Zapper)(v)); err != nil { @@ -1769,6 +1780,7 @@ func (vals _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) er type _Map_String_String_Zapper map[string]string +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { enc.AddString((string)(k), v) @@ -1778,6 +1790,7 @@ func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEnco type _Set_Map_String_String_Zapper []map[string]string +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range vals { if err := enc.AppendObject((_Map_String_String_Zapper)(v)); err != nil { @@ -1789,6 +1802,7 @@ func (vals _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncod type _Map_String_I32_Zapper map[string]int32 +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { enc.AddInt32((string)(k), v) @@ -1801,6 +1815,7 @@ type _MapItem_Map_String_I32_I64_Zapper struct { Value int64 } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_Map_String_I32_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", (_Map_String_I32_Zapper)(v.Key)); err != nil { return err @@ -1814,6 +1829,7 @@ type _Map_Map_String_I32_I64_Zapper []struct { Value int64 } +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range keyvals { k := i.Key @@ -1827,6 +1843,7 @@ func (keyvals _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayE type _Set_I64_Zapper map[int64]struct{} +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { enc.AppendInt64(v) @@ -1839,6 +1856,7 @@ type _MapItem_List_I32_Set_I64_Zapper struct { Value map[int64]struct{} } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_List_I32_Set_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("key", (_List_I32_Zapper)(v.Key)); err != nil { return err @@ -1854,6 +1872,7 @@ type _Map_List_I32_Set_I64_Zapper []struct { Value map[int64]struct{} } +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range keyvals { k := i.Key @@ -1867,6 +1886,7 @@ func (keyvals _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEnc type _List_Double_Zapper []float64 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendFloat64(val) @@ -1879,6 +1899,7 @@ type _MapItem_Set_I32_List_Double_Zapper struct { Value []float64 } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_Set_I32_List_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("key", (_Set_I32_Zapper)(v.Key)); err != nil { return err @@ -1894,6 +1915,7 @@ type _Map_Set_I32_List_Double_Zapper []struct { Value []float64 } +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range keyvals { k := i.Key @@ -2434,6 +2456,7 @@ func (v *EnumContainers) Equals(rhs *EnumContainers) bool { type _List_EnumDefault_Zapper []enums.EnumDefault +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { @@ -2445,6 +2468,7 @@ func (vals _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e type _Set_EnumWithValues_Zapper map[enums.EnumWithValues]struct{} +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_EnumWithValues_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { if err := enc.AppendObject(v); err != nil { @@ -2459,6 +2483,7 @@ type _MapItem_EnumWithDuplicateValues_I32_Zapper struct { Value int32 } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_EnumWithDuplicateValues_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", v.Key); err != nil { return err @@ -2469,6 +2494,7 @@ func (v _MapItem_EnumWithDuplicateValues_I32_Zapper) MarshalLogObject(enc zapcor type _Map_EnumWithDuplicateValues_I32_Zapper map[enums.EnumWithDuplicateValues]int32 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { if err := enc.AppendObject(_MapItem_EnumWithDuplicateValues_I32_Zapper{Key: k, Value: v}); err != nil { @@ -2801,6 +2827,7 @@ func (v *ListOfConflictingEnums) Equals(rhs *ListOfConflictingEnums) bool { type _List_RecordType_Zapper []enum_conflict.RecordType +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { @@ -2812,6 +2839,7 @@ func (vals _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) er type _List_RecordType_1_Zapper []enums.RecordType +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { @@ -3115,6 +3143,7 @@ func (v *ListOfConflictingUUIDs) Equals(rhs *ListOfConflictingUUIDs) bool { type _List_UUID_Zapper []*typedefs.UUID +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject((*typedefs.I128)(val)); err != nil { @@ -3126,6 +3155,7 @@ func (vals _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_UUID_1_Zapper []uuid_conflict.UUID +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendString((string)(val)) @@ -3487,6 +3517,7 @@ type _MapItem_Binary_String_Zapper struct { Value string } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_Binary_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", base64.StdEncoding.EncodeToString(v.Key)) enc.AddString("value", v.Value) @@ -3498,6 +3529,7 @@ type _Map_Binary_String_Zapper []struct { Value string } +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range keyvals { k := i.Key @@ -3511,6 +3543,7 @@ func (keyvals _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncode type _Map_String_Binary_Zapper map[string][]byte +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { enc.AddString((string)(k), base64.StdEncoding.EncodeToString(v)) @@ -4125,6 +4158,7 @@ func (v *PrimitiveContainers) Equals(rhs *PrimitiveContainers) bool { type _List_Binary_Zapper [][]byte +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Binary_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendString(base64.StdEncoding.EncodeToString(val)) @@ -4134,6 +4168,7 @@ func (vals _List_Binary_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _List_I64_Zapper []int64 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendInt64(val) @@ -4143,6 +4178,7 @@ func (vals _List_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Set_Byte_Zapper map[int8]struct{} +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _Set_Byte_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range vals { enc.AppendInt8(v) @@ -4155,6 +4191,7 @@ type _MapItem_I32_String_Zapper struct { Value string } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_I32_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", v.Key) enc.AddString("value", v.Value) @@ -4163,6 +4200,7 @@ func (v _MapItem_I32_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) type _Map_I32_String_Zapper map[int32]string +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { if err := enc.AppendObject(_MapItem_I32_String_Zapper{Key: k, Value: v}); err != nil { @@ -4174,6 +4212,7 @@ func (keyvals _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) type _Map_String_Bool_Zapper map[string]bool +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_Bool_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { enc.AddBool((string)(k), v) @@ -4533,6 +4572,7 @@ type _MapItem_I64_Double_Zapper struct { Value float64 } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_I64_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt64("key", v.Key) enc.AddFloat64("value", v.Value) @@ -4541,6 +4581,7 @@ func (v _MapItem_I64_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) type _Map_I64_Double_Zapper map[int64]float64 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { if err := enc.AppendObject(_MapItem_I64_Double_Zapper{Key: k, Value: v}); err != nil { diff --git a/gen/internal/tests/services/keyvalue_getmanyvalues.go b/gen/internal/tests/services/keyvalue_getmanyvalues.go index 44d81b52..b23a85db 100644 --- a/gen/internal/tests/services/keyvalue_getmanyvalues.go +++ b/gen/internal/tests/services/keyvalue_getmanyvalues.go @@ -181,6 +181,7 @@ func (v *KeyValue_GetManyValues_Args) Equals(rhs *KeyValue_GetManyValues_Args) b type _List_Key_Zapper []Key +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendString((string)(val)) @@ -539,6 +540,7 @@ func (v *KeyValue_GetManyValues_Result) Equals(rhs *KeyValue_GetManyValues_Resul type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { diff --git a/gen/internal/tests/structs/types.go b/gen/internal/tests/structs/types.go index 3ff86a00..2b3327ce 100644 --- a/gen/internal/tests/structs/types.go +++ b/gen/internal/tests/structs/types.go @@ -681,6 +681,7 @@ func (v *DefaultsStruct) Equals(rhs *DefaultsStruct) bool { type _List_String_Zapper []string +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendString(val) @@ -690,6 +691,7 @@ func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _List_Double_Zapper []float64 +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendFloat64(val) @@ -1747,6 +1749,7 @@ func (v *Graph) Equals(rhs *Graph) bool { type _List_Edge_Zapper []*Edge +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { diff --git a/gen/internal/tests/typedefs/types.go b/gen/internal/tests/typedefs/types.go index 41879895..9253922f 100644 --- a/gen/internal/tests/typedefs/types.go +++ b/gen/internal/tests/typedefs/types.go @@ -1278,6 +1278,7 @@ func (v *Transition) Equals(rhs *Transition) bool { type _EventGroup_Zapper []*Event +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { diff --git a/gen/internal/tests/unions/types.go b/gen/internal/tests/unions/types.go index 916f10f5..3971a732 100644 --- a/gen/internal/tests/unions/types.go +++ b/gen/internal/tests/unions/types.go @@ -434,6 +434,7 @@ func (v *ArbitraryValue) Equals(rhs *ArbitraryValue) bool { type _List_ArbitraryValue_Zapper []*ArbitraryValue +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { @@ -445,6 +446,7 @@ func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { if err := enc.AddObject((string)(k), v); err != nil { diff --git a/plugin/api/types.go b/plugin/api/types.go index e5a7fe4d..7c20755e 100644 --- a/plugin/api/types.go +++ b/plugin/api/types.go @@ -808,6 +808,7 @@ func (v *Function) Equals(rhs *Function) bool { type _List_Argument_Zapper []*Argument +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { @@ -819,6 +820,7 @@ func (vals _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) erro type _Map_String_String_Zapper map[string]string +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { enc.AddString((string)(k), v) @@ -1346,6 +1348,7 @@ func (v *GenerateServiceRequest) Equals(rhs *GenerateServiceRequest) bool { type _List_ServiceID_Zapper []ServiceID +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_ServiceID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { enc.AppendInt32((int32)(val)) @@ -1358,6 +1361,7 @@ type _MapItem_ServiceID_Service_Zapper struct { Value *Service } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_ServiceID_Service_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", (int32)(v.Key)) if err := enc.AddObject("value", v.Value); err != nil { @@ -1368,6 +1372,7 @@ func (v _MapItem_ServiceID_Service_Zapper) MarshalLogObject(enc zapcore.ObjectEn type _Map_ServiceID_Service_Zapper map[ServiceID]*Service +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_ServiceID_Service_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { if err := enc.AppendObject(_MapItem_ServiceID_Service_Zapper{Key: k, Value: v}); err != nil { @@ -1382,6 +1387,7 @@ type _MapItem_ModuleID_Module_Zapper struct { Value *Module } +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (v _MapItem_ModuleID_Module_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", (int32)(v.Key)) if err := enc.AddObject("value", v.Value); err != nil { @@ -1392,6 +1398,7 @@ func (v _MapItem_ModuleID_Module_Zapper) MarshalLogObject(enc zapcore.ObjectEnco type _Map_ModuleID_Module_Zapper map[ModuleID]*Module +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (keyvals _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range keyvals { if err := enc.AppendObject(_MapItem_ModuleID_Module_Zapper{Key: k, Value: v}); err != nil { @@ -1628,6 +1635,7 @@ func (v *GenerateServiceResponse) Equals(rhs *GenerateServiceResponse) bool { type _Map_String_Binary_Zapper map[string][]byte +// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) func (keyvals _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range keyvals { enc.AddString((string)(k), base64.StdEncoding.EncodeToString(v)) @@ -2015,6 +2023,7 @@ func (v *HandshakeResponse) Equals(rhs *HandshakeResponse) bool { type _List_Feature_Zapper []Feature +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Feature_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { @@ -2591,6 +2600,7 @@ func (v *Service) Equals(rhs *Service) bool { type _List_Function_Zapper []*Function +// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) func (vals _List_Function_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, val := range vals { if err := enc.AppendObject(val); err != nil { From eb6b1d79dabcea2657e655bc081169c8a1ad1e0e Mon Sep 17 00:00:00 2001 From: Minho Park Date: Mon, 30 Jul 2018 16:29:12 -0700 Subject: [PATCH 06/25] Add Zap logging tests --- gen/zap_test.go | 449 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 449 insertions(+) create mode 100644 gen/zap_test.go diff --git a/gen/zap_test.go b/gen/zap_test.go new file mode 100644 index 00000000..58e4e6ee --- /dev/null +++ b/gen/zap_test.go @@ -0,0 +1,449 @@ +// Copyright (c) 2015 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package gen + +import ( + "encoding/base64" + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + tc "go.uber.org/thriftrw/gen/internal/tests/containers" + te "go.uber.org/thriftrw/gen/internal/tests/enums" + ts "go.uber.org/thriftrw/gen/internal/tests/structs" + "go.uber.org/zap/zapcore" +) + +func jsonToComparableMap(jsonMap string) (map[string]interface{}, error) { + var retMap map[string]interface{} + if err := json.Unmarshal([]byte(jsonMap), &retMap); err != nil { + return nil, err + } + return retMap, nil +} + +func mapTojson(mapThing map[string]interface{}) (string, error) { + retBytes, err := json.Marshal(mapThing) + if err != nil { + return "", err + } + return string(retBytes), nil +} + +func TestCollectionsOfPrimitivesZapLogging(t *testing.T) { + // These types are created to ease building map[string]interface{} + type o = map[string]interface{} + type a = []interface{} + + b64 := func(byteString string) string { + return base64.StdEncoding.EncodeToString([]byte(byteString)) + } + + tests := []struct { + desc string + p tc.PrimitiveContainers + v interface{} + }{ + // Lists ///////////////////////////////////////////////////////////// + { + "empty list", + tc.PrimitiveContainers{ListOfInts: []int64{}}, + o{"listOfInts": a{}}, + }, + { + "list of ints", + tc.PrimitiveContainers{ListOfInts: []int64{1, 2, 3}}, + o{"listOfInts": a{int64(1), int64(2), int64(3)}}, + }, + { + "list of binary", + tc.PrimitiveContainers{ + ListOfBinary: [][]byte{ + []byte("foo"), {}, []byte("bar"), []byte("baz"), + }, + }, + // base64 + o{"listOfBinary": a{b64("foo"), b64(""), b64("bar"), b64("baz")}}, + }, + // Sets ////////////////////////////////////////////////////////////// + { + "empty set", + tc.PrimitiveContainers{SetOfStrings: map[string]struct{}{}}, + o{"setOfStrings": a{}}, + }, + { + "set of strings", + tc.PrimitiveContainers{SetOfStrings: map[string]struct{}{ + "foo": {}, + "bar": {}, + "baz": {}, + }}, + o{"setOfStrings": a{"foo", "bar", "baz"}}, + }, + { + "set of bytes", + tc.PrimitiveContainers{SetOfBytes: map[int8]struct{}{ + -1: {}, + 1: {}, + 125: {}, + }}, + o{"setOfBytes": a{int8(-1), int8(1), int8(125)}}, + }, + // Maps ////////////////////////////////////////////////////////////// + { + "empty map", + tc.PrimitiveContainers{MapOfStringToBool: map[string]bool{}}, + o{"mapOfStringToBool": o{}}, + }, + { + "map of int to string", + tc.PrimitiveContainers{MapOfIntToString: map[int32]string{ + -1: "foo", + 1234: "bar", + -9876: "baz", + }}, + o{"mapOfIntToString": a{ + o{"key": int32(-1), "value": "foo"}, + o{"key": int32(1234), "value": "bar"}, + o{"key": int32(-9876), "value": "baz"}, + }}, + }, + { + "map of string to bool", + tc.PrimitiveContainers{MapOfStringToBool: map[string]bool{ + "foo": true, + "bar": false, + "baz": true, + }}, + o{"mapOfStringToBool": o{"bar": false, "baz": true, "foo": true}}, + }, + } + + for _, tt := range tests { + mapEncoder := zapcore.NewMapObjectEncoder() + tt.p.MarshalLogObject(mapEncoder) + // mapEncoder.AddObject("actual", &tt.p) + // t.Log(mapTojson(mapEncoder.Fields)) + assert.Equal(t, tt.v, mapEncoder.Fields) + // DeepEquals mapEncoder.Fields and tt.v + } +} + +func TestEnumContainersZapLogging(t *testing.T) { + // These types are created to ease building map[string]interface{} + type o = map[string]interface{} + type a = []interface{} + + tests := []struct { + r tc.EnumContainers + v interface{} + }{ + { + tc.EnumContainers{ + ListOfEnums: []te.EnumDefault{ + te.EnumDefaultFoo, + te.EnumDefaultBar, + }, + }, + o{"listOfEnums": a{ + o{"value": int32(0), "name": "Foo"}, + o{"value": int32(1), "name": "Bar"}}, + }, + }, + { + tc.EnumContainers{ + SetOfEnums: map[te.EnumWithValues]struct{}{ + te.EnumWithValuesX: {}, + te.EnumWithValuesZ: {}, + }, + }, + o{"setOfEnums": a{ + o{"name": "X", "value": 123}, + o{"name": "Z", "value": 789}}}, + }, + { + tc.EnumContainers{ + MapOfEnums: map[te.EnumWithDuplicateValues]int32{ + te.EnumWithDuplicateValuesP: 123, + te.EnumWithDuplicateValuesQ: 456, + }, + }, + o{"mapOfEnums": a{ + o{"key": o{"value": 0, "name": "P"}, "value": 123}, + o{"key": o{"name": "Q", "value": -1}, "value": 456}}}, + }, + { + // this is the same as the one above except we're using "R" intsead + // of "P" (they both have the same value) + tc.EnumContainers{ + MapOfEnums: map[te.EnumWithDuplicateValues]int32{ + te.EnumWithDuplicateValuesR: 123, + te.EnumWithDuplicateValuesQ: 456, + }, + }, + o{"mapOfEnums": a{ + o{"key": o{"value": -1, "name": "Q"}, "value": 456}, + o{"key": o{"value": 0, "name": "P"}, "value": 123}}}, + }, + } + + for _, tt := range tests { + mapEncoder := zapcore.NewMapObjectEncoder() + tt.r.MarshalLogObject(mapEncoder) + // mapEncoder.AddObject("actual", &tt.p) + // t.Log(mapTojson(mapEncoder.Fields)) + assert.Equal(t, tt.v, mapEncoder.Fields) + } +} + +func TestListOfStructsZapLogging(t *testing.T) { + // These types are created to ease building map[string]interface{} + type o = map[string]interface{} + type a = []interface{} + + tests := []struct { + r ts.Graph + v interface{} + }{ + { + ts.Graph{Edges: []*ts.Edge{}}, + o{"edges": a{}}, + }, + { + ts.Graph{Edges: []*ts.Edge{ + { + StartPoint: &ts.Point{X: 1.0, Y: 2.0}, + EndPoint: &ts.Point{X: 3.0, Y: 4.0}, + }, + { + StartPoint: &ts.Point{X: 5.0, Y: 6.0}, + EndPoint: &ts.Point{X: 7.0, Y: 8.0}, + }, + { + StartPoint: &ts.Point{X: 9.0, Y: 10.0}, + EndPoint: &ts.Point{X: 11.0, Y: 12.0}, + }, + }}, + o{"edges": a{ + o{"startPoint": o{"x": float64(1), "y": float64(2)}, + "endPoint": o{"x": float64(3), "y": float64(4)}}, + o{"startPoint": o{"x": float64(5), "y": float64(6)}, + "endPoint": o{"y": float64(8), "x": float64(7)}}, + o{"startPoint": o{"x": float64(9), "y": float64(10)}, + "endPoint": o{"x": float64(11), "y": float64(12)}}}, + }, + }, + } + + for _, tt := range tests { + mapEncoder := zapcore.NewMapObjectEncoder() + tt.r.MarshalLogObject(mapEncoder) + // mapEncoder.AddObject("actual", &tt.p) + // t.Log(mapTojson(mapEncoder.Fields)) + assert.Equal(t, tt.v, mapEncoder.Fields) + } +} + +func TestCrazyTownZapLogging(t *testing.T) { + // These types are created to ease building map[string]interface{} + type o = map[string]interface{} + type a = []interface{} + + tests := []struct { + desc string + r tc.ContainersOfContainers + v interface{} + }{ + { + "ListOfLists", + tc.ContainersOfContainers{ + ListOfLists: [][]int32{ + {1, 2, 3}, + {4, 5, 6}, + }, + }, + o{}, + }, + { + "ListOfSets", + tc.ContainersOfContainers{ + ListOfSets: []map[int32]struct{}{ + { + 1: struct{}{}, + 2: struct{}{}, + 3: struct{}{}, + }, + { + 4: struct{}{}, + 5: struct{}{}, + 6: struct{}{}, + }, + }, + }, + o{}, + }, + { + "ListOfMaps", + tc.ContainersOfContainers{ + ListOfMaps: []map[int32]int32{ + { + 1: 100, + 2: 200, + 3: 300, + }, + { + 4: 400, + 5: 500, + 6: 600, + }, + }, + }, + o{}, + }, + { + "SetOfSets", + tc.ContainersOfContainers{ + SetOfSets: []map[string]struct{}{ + { + "1": struct{}{}, + "2": struct{}{}, + "3": struct{}{}, + }, + { + "4": struct{}{}, + "5": struct{}{}, + "6": struct{}{}, + }, + }, + }, + o{}, + }, + { + "SetOfLists", + tc.ContainersOfContainers{ + SetOfLists: [][]string{ + {"1", "2", "3"}, + {"4", "5", "6"}, + }, + }, + o{}, + }, + { + "SetOfMaps", + tc.ContainersOfContainers{ + SetOfMaps: []map[string]string{ + { + "1": "one", + "2": "two", + "3": "three", + }, + { + "4": "four", + "5": "five", + "6": "six", + }, + }, + }, + o{}, + }, + { + "MapOfMapToInt", + tc.ContainersOfContainers{ + MapOfMapToInt: []struct { + Key map[string]int32 + Value int64 + }{ + { + Key: map[string]int32{"1": 1, "2": 2, "3": 3}, + Value: 123, + }, + { + Key: map[string]int32{"4": 4, "5": 5, "6": 6}, + Value: 456, + }, + }, + }, + o{}, + }, + { + "MapOfListToSet", + tc.ContainersOfContainers{ + MapOfListToSet: []struct { + Key []int32 + Value map[int64]struct{} + }{ + { + Key: []int32{1, 2, 3}, + Value: map[int64]struct{}{ + 1: {}, + 2: {}, + 3: {}, + }, + }, + { + Key: []int32{4, 5, 6}, + Value: map[int64]struct{}{ + 4: {}, + 5: {}, + 6: {}, + }, + }, + }, + }, + o{}, + }, + { + "MapOfSetToListOfDouble", + tc.ContainersOfContainers{ + MapOfSetToListOfDouble: []struct { + Key map[int32]struct{} + Value []float64 + }{ + { + Key: map[int32]struct{}{ + 1: {}, + 2: {}, + 3: {}, + }, + Value: []float64{1.0, 2.0, 3.0}, + }, + { + Key: map[int32]struct{}{ + 4: {}, + 5: {}, + 6: {}, + }, + Value: []float64{4.0, 5.0, 6.0}, + }, + }, + }, + o{}, + }, + } + + for _, tt := range tests { + mapEncoder := zapcore.NewMapObjectEncoder() + tt.r.MarshalLogObject(mapEncoder) + // mapEncoder.AddObject("actual", &tt.p) + // t.Log(mapTojson(mapEncoder.Fields)) + assert.Equal(t, tt.v, mapEncoder.Fields) + } +} From e6c2e024b7658c757ad7179c66b7127e14073c03 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Mon, 30 Jul 2018 18:02:13 -0700 Subject: [PATCH 07/25] Modify Zap logging tests Sets and maps have nondeterministic behavior in iteration, but Zap logs/JSON has arrays that are orderly, causing issues in testing. Instead, we only write one element for those that are affected and test the loop logic separately in TestNondeterministicZapLogging. --- gen/zap_test.go | 226 +++++++++++++++++++++++++++++------------------- 1 file changed, 139 insertions(+), 87 deletions(-) diff --git a/gen/zap_test.go b/gen/zap_test.go index 58e4e6ee..5ced1b6b 100644 --- a/gen/zap_test.go +++ b/gen/zap_test.go @@ -22,7 +22,6 @@ package gen import ( "encoding/base64" - "encoding/json" "testing" "github.com/stretchr/testify/assert" @@ -32,21 +31,21 @@ import ( "go.uber.org/zap/zapcore" ) -func jsonToComparableMap(jsonMap string) (map[string]interface{}, error) { - var retMap map[string]interface{} - if err := json.Unmarshal([]byte(jsonMap), &retMap); err != nil { - return nil, err - } - return retMap, nil -} +// func jsonToComparableMap(jsonMap string) (map[string]interface{}, error) { +// var retMap map[string]interface{} +// if err := json.Unmarshal([]byte(jsonMap), &retMap); err != nil { +// return nil, err +// } +// return retMap, nil +// } -func mapTojson(mapThing map[string]interface{}) (string, error) { - retBytes, err := json.Marshal(mapThing) - if err != nil { - return "", err - } - return string(retBytes), nil -} +// func mapTojson(mapThing map[string]interface{}) (string, error) { +// retBytes, err := json.Marshal(mapThing) +// if err != nil { +// return "", err +// } +// return string(retBytes), nil +// } func TestCollectionsOfPrimitivesZapLogging(t *testing.T) { // These types are created to ease building map[string]interface{} @@ -93,19 +92,15 @@ func TestCollectionsOfPrimitivesZapLogging(t *testing.T) { "set of strings", tc.PrimitiveContainers{SetOfStrings: map[string]struct{}{ "foo": {}, - "bar": {}, - "baz": {}, }}, - o{"setOfStrings": a{"foo", "bar", "baz"}}, + o{"setOfStrings": a{"foo"}}, }, { "set of bytes", tc.PrimitiveContainers{SetOfBytes: map[int8]struct{}{ - -1: {}, - 1: {}, 125: {}, }}, - o{"setOfBytes": a{int8(-1), int8(1), int8(125)}}, + o{"setOfBytes": a{int8(125)}}, }, // Maps ////////////////////////////////////////////////////////////// { @@ -116,24 +111,21 @@ func TestCollectionsOfPrimitivesZapLogging(t *testing.T) { { "map of int to string", tc.PrimitiveContainers{MapOfIntToString: map[int32]string{ - -1: "foo", - 1234: "bar", - -9876: "baz", + 1234: "bar", }}, o{"mapOfIntToString": a{ - o{"key": int32(-1), "value": "foo"}, - o{"key": int32(1234), "value": "bar"}, - o{"key": int32(-9876), "value": "baz"}, + o{"key": int32(1234), + "value": "bar"}, }}, }, { "map of string to bool", tc.PrimitiveContainers{MapOfStringToBool: map[string]bool{ - "foo": true, - "bar": false, + "foo": false, + "bar": true, "baz": true, }}, - o{"mapOfStringToBool": o{"bar": false, "baz": true, "foo": true}}, + o{"mapOfStringToBool": o{"foo": false, "bar": true, "baz": true}}, }, } @@ -147,6 +139,57 @@ func TestCollectionsOfPrimitivesZapLogging(t *testing.T) { } } +func TestNondeterministicZapLogging(t *testing.T) { + mapEncoder := zapcore.NewMapObjectEncoder() + // case SetOfStrings + test1 := tc.PrimitiveContainers{ + SetOfStrings: map[string]struct{}{ + "foo": {}, + "bar": {}, + "baz": {}, + "hello": {}, + "world": {}, + }, + } + test1.MarshalLogObject(mapEncoder) + expected1 := []string{"foo", "bar", "baz", "hello", "world"} + assert.ElementsMatch(t, mapEncoder.Fields["setOfStrings"], expected1) + + // case SetOfBytes + test2 := tc.PrimitiveContainers{ + SetOfBytes: map[int8]struct{}{ + 125: {}, + 1: {}, + 5: {}, + 73: {}, + 42: {}, + }, + } + test2.MarshalLogObject(mapEncoder) + expected2 := []int8{1, 5, 42, 73, 125} + assert.ElementsMatch(t, mapEncoder.Fields["setOfBytes"], expected2) + + // case MapOfIntToString + test3 := tc.PrimitiveContainers{ + MapOfIntToString: map[int32]string{ + 125: "foo", + 1: "bar", + 5: "baz", + 73: "hello", + 42: "world", + }, + } + test3.MarshalLogObject(mapEncoder) + expected3 := []map[string]interface{}{ + {"key": int32(125), "value": "foo"}, + {"key": int32(1), "value": "bar"}, + {"key": int32(5), "value": "baz"}, + {"key": int32(73), "value": "hello"}, + {"key": int32(42), "value": "world"}, + } + assert.ElementsMatch(t, mapEncoder.Fields["mapOfIntToString"], expected3) +} + func TestEnumContainersZapLogging(t *testing.T) { // These types are created to ease building map[string]interface{} type o = map[string]interface{} @@ -159,36 +202,41 @@ func TestEnumContainersZapLogging(t *testing.T) { { tc.EnumContainers{ ListOfEnums: []te.EnumDefault{ - te.EnumDefaultFoo, te.EnumDefaultBar, }, }, o{"listOfEnums": a{ - o{"value": int32(0), "name": "Foo"}, - o{"value": int32(1), "name": "Bar"}}, + o{"name": "Bar", "value": int32(1)}}, }, }, { tc.EnumContainers{ SetOfEnums: map[te.EnumWithValues]struct{}{ - te.EnumWithValuesX: {}, te.EnumWithValuesZ: {}, }, }, o{"setOfEnums": a{ - o{"name": "X", "value": 123}, - o{"name": "Z", "value": 789}}}, + o{"name": "Z", "value": int32(789)}}, + }, }, { tc.EnumContainers{ MapOfEnums: map[te.EnumWithDuplicateValues]int32{ te.EnumWithDuplicateValuesP: 123, - te.EnumWithDuplicateValuesQ: 456, }, }, o{"mapOfEnums": a{ - o{"key": o{"value": 0, "name": "P"}, "value": 123}, - o{"key": o{"name": "Q", "value": -1}, "value": 456}}}, + o{"key": o{"value": int32(0), "name": "P"}, "value": int32(123)}}}, + }, + { + // unknown enum name + tc.EnumContainers{ + MapOfEnums: map[te.EnumWithDuplicateValues]int32{ + te.EnumWithDuplicateValues(1523): 123, + }, + }, + o{"mapOfEnums": a{ + o{"key": o{"value": int32(1523)}, "value": int32(123)}}}, }, { // this is the same as the one above except we're using "R" intsead @@ -196,12 +244,10 @@ func TestEnumContainersZapLogging(t *testing.T) { tc.EnumContainers{ MapOfEnums: map[te.EnumWithDuplicateValues]int32{ te.EnumWithDuplicateValuesR: 123, - te.EnumWithDuplicateValuesQ: 456, }, }, o{"mapOfEnums": a{ - o{"key": o{"value": -1, "name": "Q"}, "value": 456}, - o{"key": o{"value": 0, "name": "P"}, "value": 123}}}, + o{"key": o{"value": int32(0), "name": "P"}, "value": int32(123)}}}, }, } @@ -248,7 +294,8 @@ func TestListOfStructsZapLogging(t *testing.T) { o{"startPoint": o{"x": float64(5), "y": float64(6)}, "endPoint": o{"y": float64(8), "x": float64(7)}}, o{"startPoint": o{"x": float64(9), "y": float64(10)}, - "endPoint": o{"x": float64(11), "y": float64(12)}}}, + "endPoint": o{"x": float64(11), "y": float64(12)}}, + }, }, }, } @@ -280,61 +327,65 @@ func TestCrazyTownZapLogging(t *testing.T) { {4, 5, 6}, }, }, - o{}, + o{"listOfLists": a{ + a{int32(1), int32(2), int32(3)}, + a{int32(4), int32(5), int32(6)}}, + }, }, { "ListOfSets", tc.ContainersOfContainers{ ListOfSets: []map[int32]struct{}{ { - 1: struct{}{}, 2: struct{}{}, - 3: struct{}{}, }, { - 4: struct{}{}, 5: struct{}{}, - 6: struct{}{}, }, }, }, - o{}, + o{"listOfSets": a{ + a{int32(2)}, + a{int32(5)}}, + }, }, { "ListOfMaps", tc.ContainersOfContainers{ ListOfMaps: []map[int32]int32{ { - 1: 100, 2: 200, - 3: 300, }, { - 4: 400, 5: 500, - 6: 600, }, }, }, - o{}, + o{"listOfMaps": a{ + a{ + o{"key": int32(2), + "value": int32(200)}}, + a{ + o{"key": int32(5), + "value": int32(500)}}}, + }, }, { "SetOfSets", tc.ContainersOfContainers{ SetOfSets: []map[string]struct{}{ { - "1": struct{}{}, "2": struct{}{}, - "3": struct{}{}, }, { - "4": struct{}{}, "5": struct{}{}, - "6": struct{}{}, }, }, }, - o{}, + o{"setOfSets": a{ + a{"2"}, + a{"5"}}, + }, }, { "SetOfLists", @@ -344,25 +395,27 @@ func TestCrazyTownZapLogging(t *testing.T) { {"4", "5", "6"}, }, }, - o{}, + o{"setOfLists": a{ + a{"1", "2", "3"}, + a{"4", "5", "6"}}, + }, }, { "SetOfMaps", tc.ContainersOfContainers{ SetOfMaps: []map[string]string{ { - "1": "one", "2": "two", - "3": "three", }, { - "4": "four", - "5": "five", "6": "six", }, }, }, - o{}, + o{"setOfMaps": a{ + o{"2": "two"}, + o{"6": "six"}}, + }, }, { "MapOfMapToInt", @@ -372,16 +425,21 @@ func TestCrazyTownZapLogging(t *testing.T) { Value int64 }{ { - Key: map[string]int32{"1": 1, "2": 2, "3": 3}, + Key: map[string]int32{"2": 2}, Value: 123, }, { - Key: map[string]int32{"4": 4, "5": 5, "6": 6}, - Value: 456, + Key: map[string]int32{"4": 4}, + Value: 135, }, }, }, - o{}, + o{"mapOfMapToInt": a{ + o{"key": o{"2": int32(2)}, + "value": int64(123)}, + o{"key": o{"4": int32(4)}, + "value": int64(135)}}, + }, }, { "MapOfListToSet", @@ -394,21 +452,14 @@ func TestCrazyTownZapLogging(t *testing.T) { Key: []int32{1, 2, 3}, Value: map[int64]struct{}{ 1: {}, - 2: {}, - 3: {}, - }, - }, - { - Key: []int32{4, 5, 6}, - Value: map[int64]struct{}{ - 4: {}, - 5: {}, - 6: {}, }, }, }, }, - o{}, + o{"mapOfListToSet": a{ + o{"value": a{int64(1)}, + "key": a{int32(1), int32(2), int32(3)}}}, + }, }, { "MapOfSetToListOfDouble", @@ -419,23 +470,24 @@ func TestCrazyTownZapLogging(t *testing.T) { }{ { Key: map[int32]struct{}{ - 1: {}, 2: {}, - 3: {}, }, - Value: []float64{1.0, 2.0, 3.0}, + Value: []float64{1.1, 2.2, 3.3}, }, { Key: map[int32]struct{}{ 4: {}, - 5: {}, - 6: {}, }, - Value: []float64{4.0, 5.0, 6.0}, + Value: []float64{2.2, 3.3}, }, }, }, - o{}, + o{"mapOfSetToListOfDouble": a{ + o{"key": a{int32(2)}, + "value": a{float64(1.1), float64(2.2), float64(3.3)}}, + o{"key": a{int32(4)}, + "value": a{float64(2.2), float64(3.3)}}}, + }, }, } From 7eeeaafc975708353a54a6865ac578b2cd62cb98 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Tue, 31 Jul 2018 18:07:32 -0700 Subject: [PATCH 08/25] Delete comments and add tests --- gen/field.go | 11 ++++--- gen/typedef.go | 20 ++++++++++++ gen/zap.go | 63 ++++++++++++++++++++++---------------- gen/zap_test.go | 81 ++++++++++++++++++++++++++++++++++--------------- glide.lock | 24 +++++++++------ glide.yaml | 2 +- 6 files changed, 135 insertions(+), 66 deletions(-) diff --git a/gen/field.go b/gen/field.go index 646eeaa2..7967d898 100644 --- a/gen/field.go +++ b/gen/field.go @@ -470,23 +470,24 @@ func (f fieldGroupGenerator) Zap(g Generator) error { ` <$zapcore := import "go.uber.org/zap/zapcore"> <$v := newVar "v"> - // TODO(minho): Make enc a newVar. + <$enc := newVar "enc"> - // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) - func (<$v> *<.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { + // MarshalLogObject implements zapcore.ObjectMarshaler, allowing + // fast logging of <.Name>. + func (<$v> *<.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { <$fname := goName .> <$fval := printf "%s.%s" $v $fname> <- if .Required -> if err := - enc.Add("<.Name>", ) + <$enc>.Add("<.Name>", ) <- if (zapCanError .Type)>; err != nil { return err } <- else -> if <$fval> != nil { if err := - enc.Add("<.Name>", ) + <$enc>.Add("<.Name>", ) <- if (zapCanError .Type)>; err != nil { return err } diff --git a/gen/typedef.go b/gen/typedef.go index 9da0f5e2..33580265 100644 --- a/gen/typedef.go +++ b/gen/typedef.go @@ -103,6 +103,26 @@ func typedef(g Generator, spec *compile.TypedefSpec) error { return <- end> } + + + <$zapcore := import "go.uber.org/zap/zapcore"> + <$enc := newVar "enc"> + func (<$v> <$typedefType>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { + + return (()(<$v>)).MarshalLogObject(<$enc>) + <- else -> + return ().MarshalLogObject(<$enc>) + <- end> + } + <- end> + + + <$zapcore := import "go.uber.org/zap/zapcore"> + <$enc := newVar "enc"> + func (<$v> <$typedefType>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { + return ().MarshalLogArray(<$enc>) + } + <- end> `, spec, ) diff --git a/gen/zap.go b/gen/zap.go index f9070d97..61dbd852 100644 --- a/gen/zap.go +++ b/gen/zap.go @@ -107,14 +107,16 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string ` type <.Name> <$zapcore := import "go.uber.org/zap/zapcore"> - <$keyvals := newVar "keyvals"> + <$m := newVar "m"> <$k := newVar "k"> <$v := newVar "v"> - // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) - func (<$keyvals> <.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { - for <$k>, <$v> := range <$keyvals> { + <$enc := newVar "enc"> + // MarshalLogObject implements zapcore.ObjectMarshaler, allowing + // fast logging of <.Name>. + func (<$m> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { + for <$k>, <$v> := range <$m> { if err := - enc.Add((string)(<$k>), ) + <$enc>.Add((string)(<$k>), ) <- if (zapCanError .Type.ValueSpec) ->; err != nil { return err } @@ -140,20 +142,22 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string ` type <.Name> <$zapcore := import "go.uber.org/zap/zapcore"> - <$keyvals := newVar "keyvals"> + <$m := newVar "m"> <$k := newVar "k"> <$v := newVar "v"> <$i := newVar "i"> - // MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) - func (<$keyvals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$m> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { <- if isHashable .Type.KeySpec -> - for <$k>, <$v> := range <$keyvals> { + for <$k>, <$v> := range <$m> { - for _, <$i> := range <$keyvals> { + for _, <$i> := range <$m> { <$k> := <$i>.Key <$v> := <$i>.Value - if err := enc.AppendObject(); err != nil { + if err := <$enc>.AppendObject(); err != nil { return err } } @@ -179,17 +183,19 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string ` type <.Name> <$zapcore := import "go.uber.org/zap/zapcore"> - <$vals := newVar "vals"> + <$s := newVar "s"> <$v := newVar "v"> - // MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) - func (<$vals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$s> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { <- if isHashable .Type.ValueSpec -> - for <$v> := range <$vals> { + for <$v> := range <$s> { - for _, <$v> := range <$vals> { + for _, <$v> := range <$s> { if err := - enc.Append() + <$enc>.Append() <- if (zapCanError .Type.ValueSpec)>; err != nil { return err } @@ -215,12 +221,15 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string ` type <.Name> <$zapcore := import "go.uber.org/zap/zapcore"> - <$vals := newVar "vals"> - // MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) - func (<$vals> <.Name>) MarshalLogArray(enc <$zapcore>.ArrayEncoder) error { - for _, val := range <$vals> { + <$l := newVar "l"> + <$v := newVar "v"> + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$l> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { + for _, <$v> := range <$l> { if err := - enc.Append() + <$enc>.Append() <- if (zapCanError .Type.ValueSpec)>; err != nil { return err } @@ -272,15 +281,17 @@ func zapMapItemMarshaler( <$v := newVar "v"> <$key := printf "%s.%s" $v "Key"> <$val := printf "%s.%s" $v "Value"> - // MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) - func (<$v> <.Name>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$v> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { if err := - enc.Add("key", ) + <$enc>.Add("key", ) <- if (zapCanError .KeyType)>; err != nil { return err } if err := - enc.Add("value", ) + <$enc>.Add("value", ) <- if (zapCanError .ValueType)>; err != nil { return err } diff --git a/gen/zap_test.go b/gen/zap_test.go index 5ced1b6b..75c7d8ca 100644 --- a/gen/zap_test.go +++ b/gen/zap_test.go @@ -28,25 +28,10 @@ import ( tc "go.uber.org/thriftrw/gen/internal/tests/containers" te "go.uber.org/thriftrw/gen/internal/tests/enums" ts "go.uber.org/thriftrw/gen/internal/tests/structs" + td "go.uber.org/thriftrw/gen/internal/tests/typedefs" "go.uber.org/zap/zapcore" ) -// func jsonToComparableMap(jsonMap string) (map[string]interface{}, error) { -// var retMap map[string]interface{} -// if err := json.Unmarshal([]byte(jsonMap), &retMap); err != nil { -// return nil, err -// } -// return retMap, nil -// } - -// func mapTojson(mapThing map[string]interface{}) (string, error) { -// retBytes, err := json.Marshal(mapThing) -// if err != nil { -// return "", err -// } -// return string(retBytes), nil -// } - func TestCollectionsOfPrimitivesZapLogging(t *testing.T) { // These types are created to ease building map[string]interface{} type o = map[string]interface{} @@ -132,10 +117,7 @@ func TestCollectionsOfPrimitivesZapLogging(t *testing.T) { for _, tt := range tests { mapEncoder := zapcore.NewMapObjectEncoder() tt.p.MarshalLogObject(mapEncoder) - // mapEncoder.AddObject("actual", &tt.p) - // t.Log(mapTojson(mapEncoder.Fields)) assert.Equal(t, tt.v, mapEncoder.Fields) - // DeepEquals mapEncoder.Fields and tt.v } } @@ -254,8 +236,6 @@ func TestEnumContainersZapLogging(t *testing.T) { for _, tt := range tests { mapEncoder := zapcore.NewMapObjectEncoder() tt.r.MarshalLogObject(mapEncoder) - // mapEncoder.AddObject("actual", &tt.p) - // t.Log(mapTojson(mapEncoder.Fields)) assert.Equal(t, tt.v, mapEncoder.Fields) } } @@ -303,8 +283,6 @@ func TestListOfStructsZapLogging(t *testing.T) { for _, tt := range tests { mapEncoder := zapcore.NewMapObjectEncoder() tt.r.MarshalLogObject(mapEncoder) - // mapEncoder.AddObject("actual", &tt.p) - // t.Log(mapTojson(mapEncoder.Fields)) assert.Equal(t, tt.v, mapEncoder.Fields) } } @@ -494,8 +472,61 @@ func TestCrazyTownZapLogging(t *testing.T) { for _, tt := range tests { mapEncoder := zapcore.NewMapObjectEncoder() tt.r.MarshalLogObject(mapEncoder) - // mapEncoder.AddObject("actual", &tt.p) - // t.Log(mapTojson(mapEncoder.Fields)) assert.Equal(t, tt.v, mapEncoder.Fields) } } + +func TestTypedefsZapLogging(t *testing.T) { + // These types are created to ease building map[string]interface{} + type o = map[string]interface{} + type a = []interface{} + + // test alias of primitive + mapEncoder := zapcore.NewMapObjectEncoder() + testState := td.State("hello") + test1 := td.DefaultPrimitiveTypedef{State: &testState} + test1.MarshalLogObject(mapEncoder) + expected1 := o{"state": "hello"} + assert.Equal(t, expected1, mapEncoder.Fields) + + // test alias of struct + mapEncoder = zapcore.NewMapObjectEncoder() + test2 := td.UUID{High: 123, Low: 456} + test2.MarshalLogObject(mapEncoder) + expected2 := o{"high": int64(123), "low": int64(456)} + assert.Equal(t, expected2, mapEncoder.Fields) + + // test alias of list of structs + mapEncoder = zapcore.NewMapObjectEncoder() + testUUID := td.UUID(td.I128{High: 123, Low: 456}) + testTimestamp := td.Timestamp(123) + test3 := td.EventGroup([]*td.Event{ + &td.Event{ + UUID: &testUUID, + Time: &testTimestamp, + }, + }) + mapEncoder.AddArray("addTypedefArrayTest", test3) + expected3 := o{"addTypedefArrayTest": a{o{"uuid": o{"high": int64(123), "low": int64(456)}, "time": int64(123)}}} + assert.Equal(t, expected3, mapEncoder.Fields) + + // test alias of set + b64 := func(byteString string) string { + return base64.StdEncoding.EncodeToString([]byte(byteString)) + } + mapEncoder = zapcore.NewMapObjectEncoder() + test4 := td.BinarySet([][]byte{ + []byte("foo"), {}, []byte("bar"), []byte("baz"), + }) + mapEncoder.AddArray("addTypedefSetTest", test4) + // base64 + expected4 := o{"addTypedefSetTest": a{b64("foo"), b64(""), b64("bar"), b64("baz")}} + assert.Equal(t, expected4, mapEncoder.Fields) + + // test alias of enums + mapEncoder = zapcore.NewMapObjectEncoder() + test5 := td.MyEnum(te.EnumWithValuesX) + test5.MarshalLogObject(mapEncoder) + expected5 := o{"value": int32(123), "name": "X"} + assert.Equal(t, expected5, mapEncoder.Fields) +} diff --git a/glide.lock b/glide.lock index 1e72b538..881e3d1f 100644 --- a/glide.lock +++ b/glide.lock @@ -1,32 +1,38 @@ -hash: de4f56d34612433b7a80991786d4a9bf401fbd8d74bfd4b53e8a277e7f93bd6e -updated: 2018-07-25T12:58:08.506626687-07:00 +hash: 13611a214fe054d028621ae22f41fa294a2790cd6a0549bdbee33fada7c5bfab +updated: 2018-07-31T17:03:57.682127592-07:00 imports: - name: github.com/anmitsu/go-shlex version: 648efa622239a2f6ff949fed78ee37b48d499ba4 - name: github.com/fatih/structtag version: da3d9ab5b78fdc25d3a7614853b085200bd10da9 - name: github.com/golang/mock - version: c34cdb4725f4c3844d095133c6e40e448b86589b + version: 22bbf0ddf08105dfa364d0a2fa619dfa71014af5 subpackages: - gomock - name: github.com/jessevdk/go-flags - version: 6cf8f02b4ae8ba723ddc64dcfd403e530c06d927 + version: 1c38ed7ad0cc3d9e66649ac398c30e45f395c4eb - name: github.com/kr/pretty - version: cfb55aafdaf3ec08f0db22699ab822c50091b1c4 + version: 73f6ac0b30a98e433b289500d779f50c1a6f0712 - name: github.com/kr/text - version: 7cafcd837844e784b526369c9bce262804aebc60 + version: e2ffdb16a802fe2bb95e2e35ff34f0e53aeef34f - name: go.uber.org/atomic version: 1ea20fb1cbb1cc08cbd0d913a96dead89aa18289 - name: go.uber.org/multierr version: 3c4937480c32f4c13a875a1829af76c98ca3d40a - name: go.uber.org/zap - version: 4d45f9617f7d90f7a663ff21c7a4321dbe78098b + version: 1f8c4cad1e0417712b7d9f130a17b11eba6c8317 + subpackages: + - buffer + - internal/bufferpool + - internal/color + - internal/exit + - zapcore - name: golang.org/x/net - version: d0887baf81f4598189d4e12a37c6da86f0bba4d0 + version: 49c15d80dfbc983ea25246ee959d970efe09ec09 subpackages: - context - name: golang.org/x/tools - version: 4e70a1b26a7875f00ca1916637a876b5ffaeec59 + version: 33176b2029f9538e722efa4a005f7aa00cf60010 subpackages: - go/ast/astutil testImports: diff --git a/glide.yaml b/glide.yaml index 40ba5547..7c54be67 100644 --- a/glide.yaml +++ b/glide.yaml @@ -13,7 +13,7 @@ import: - package: github.com/fatih/structtag version: ^0.1.0 - package: go.uber.org/zap - version: ^1 + version: master testImport: - package: github.com/golang/mock subpackages: From eb8c446ec5d8572477920091a8624733035dfcd7 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Wed, 1 Aug 2018 10:27:51 -0700 Subject: [PATCH 09/25] Add testdata files --- envelope/internal/tests/enums/types.go | 3 +- envelope/internal/tests/exceptions/types.go | 6 +- .../internal/tests/services/cache_clear.go | 3 +- .../tests/services/cache_clearafter.go | 3 +- .../services/conflictingnames_setvalue.go | 6 +- .../tests/services/keyvalue_deletevalue.go | 6 +- .../tests/services/keyvalue_getmanyvalues.go | 24 +- .../tests/services/keyvalue_getvalue.go | 6 +- .../tests/services/keyvalue_setvalue.go | 6 +- .../tests/services/keyvalue_setvaluev2.go | 6 +- .../internal/tests/services/keyvalue_size.go | 6 +- ...service_name_non_standard_function_name.go | 6 +- envelope/internal/tests/services/types.go | 6 +- envelope/internal/tests/structs/types.go | 76 +++-- envelope/internal/tests/typedefs/types.go | 166 +++++++++- envelope/internal/tests/unions/types.go | 25 +- gen/internal/tests/collision/types.go | 47 +-- gen/internal/tests/containers/types.go | 302 ++++++++++-------- gen/internal/tests/enum_conflict/types.go | 3 +- gen/internal/tests/enums/types.go | 3 +- gen/internal/tests/exceptions/types.go | 6 +- gen/internal/tests/services/cache_clear.go | 3 +- .../tests/services/cache_clearafter.go | 3 +- .../services/conflictingnames_setvalue.go | 6 +- .../tests/services/keyvalue_deletevalue.go | 6 +- .../tests/services/keyvalue_getmanyvalues.go | 24 +- .../tests/services/keyvalue_getvalue.go | 6 +- .../tests/services/keyvalue_setvalue.go | 6 +- .../tests/services/keyvalue_setvaluev2.go | 6 +- gen/internal/tests/services/keyvalue_size.go | 6 +- ...service_name_non_standard_function_name.go | 6 +- gen/internal/tests/services/types.go | 6 +- gen/internal/tests/structs/types.go | 76 +++-- gen/internal/tests/typedefs/types.go | 166 +++++++++- gen/internal/tests/unions/types.go | 25 +- gen/internal/tests/uuid_conflict/types.go | 3 +- internal/envelope/exception/types.go | 3 +- plugin/api/plugin_goodbye.go | 6 +- plugin/api/plugin_handshake.go | 6 +- plugin/api/servicegenerator_generate.go | 6 +- plugin/api/types.go | 103 +++--- 41 files changed, 824 insertions(+), 363 deletions(-) diff --git a/envelope/internal/tests/enums/types.go b/envelope/internal/tests/enums/types.go index f9e703ef..29ed63c2 100644 --- a/envelope/internal/tests/enums/types.go +++ b/envelope/internal/tests/enums/types.go @@ -1394,7 +1394,8 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of StructWithOptionalEnum. func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.E != nil { diff --git a/envelope/internal/tests/exceptions/types.go b/envelope/internal/tests/exceptions/types.go index 77303d47..311de9f4 100644 --- a/envelope/internal/tests/exceptions/types.go +++ b/envelope/internal/tests/exceptions/types.go @@ -175,7 +175,8 @@ func (v *DoesNotExistException) Equals(rhs *DoesNotExistException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of DoesNotExistException. func (v *DoesNotExistException) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", v.Key) @@ -281,7 +282,8 @@ func (v *EmptyException) Equals(rhs *EmptyException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EmptyException. func (v *EmptyException) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/envelope/internal/tests/services/cache_clear.go b/envelope/internal/tests/services/cache_clear.go index 3c0672ca..58e09033 100644 --- a/envelope/internal/tests/services/cache_clear.go +++ b/envelope/internal/tests/services/cache_clear.go @@ -109,7 +109,8 @@ func (v *Cache_Clear_Args) Equals(rhs *Cache_Clear_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Cache_Clear_Args. func (v *Cache_Clear_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/envelope/internal/tests/services/cache_clearafter.go b/envelope/internal/tests/services/cache_clearafter.go index 1885a001..27b6757a 100644 --- a/envelope/internal/tests/services/cache_clearafter.go +++ b/envelope/internal/tests/services/cache_clearafter.go @@ -149,7 +149,8 @@ func (v *Cache_ClearAfter_Args) Equals(rhs *Cache_ClearAfter_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Cache_ClearAfter_Args. func (v *Cache_ClearAfter_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DurationMS != nil { diff --git a/envelope/internal/tests/services/conflictingnames_setvalue.go b/envelope/internal/tests/services/conflictingnames_setvalue.go index 91e8ba1d..5658165e 100644 --- a/envelope/internal/tests/services/conflictingnames_setvalue.go +++ b/envelope/internal/tests/services/conflictingnames_setvalue.go @@ -143,7 +143,8 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ConflictingNames_SetValue_Args. func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { @@ -334,7 +335,8 @@ func (v *ConflictingNames_SetValue_Result) Equals(rhs *ConflictingNames_SetValue return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ConflictingNames_SetValue_Result. func (v *ConflictingNames_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/envelope/internal/tests/services/keyvalue_deletevalue.go b/envelope/internal/tests/services/keyvalue_deletevalue.go index 2d43b7e2..539976b8 100644 --- a/envelope/internal/tests/services/keyvalue_deletevalue.go +++ b/envelope/internal/tests/services/keyvalue_deletevalue.go @@ -157,7 +157,8 @@ func (v *KeyValue_DeleteValue_Args) Equals(rhs *KeyValue_DeleteValue_Args) bool return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_DeleteValue_Args. func (v *KeyValue_DeleteValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -451,7 +452,8 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_DeleteValue_Result. func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DoesNotExist != nil { diff --git a/envelope/internal/tests/services/keyvalue_getmanyvalues.go b/envelope/internal/tests/services/keyvalue_getmanyvalues.go index 2fdb755a..aab9ca99 100644 --- a/envelope/internal/tests/services/keyvalue_getmanyvalues.go +++ b/envelope/internal/tests/services/keyvalue_getmanyvalues.go @@ -201,15 +201,17 @@ func (v *KeyValue_GetManyValues_Args) Equals(rhs *KeyValue_GetManyValues_Args) b type _List_Key_Zapper []Key -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendString((string)(val)) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Key_Zapper. +func (l _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendString((string)(v)) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_GetManyValues_Args. func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Range != nil { @@ -560,17 +562,19 @@ func (v *KeyValue_GetManyValues_Result) Equals(rhs *KeyValue_GetManyValues_Resul type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_ArbitraryValue_Zapper. +func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_GetManyValues_Result. func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/envelope/internal/tests/services/keyvalue_getvalue.go b/envelope/internal/tests/services/keyvalue_getvalue.go index 82cfa37e..34afac47 100644 --- a/envelope/internal/tests/services/keyvalue_getvalue.go +++ b/envelope/internal/tests/services/keyvalue_getvalue.go @@ -142,7 +142,8 @@ func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_GetValue_Args. func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -421,7 +422,8 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_GetValue_Result. func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/envelope/internal/tests/services/keyvalue_setvalue.go b/envelope/internal/tests/services/keyvalue_setvalue.go index 79e2aca9..bdb91b5a 100644 --- a/envelope/internal/tests/services/keyvalue_setvalue.go +++ b/envelope/internal/tests/services/keyvalue_setvalue.go @@ -164,7 +164,8 @@ func (v *KeyValue_SetValue_Args) Equals(rhs *KeyValue_SetValue_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_SetValue_Args. func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -372,7 +373,8 @@ func (v *KeyValue_SetValue_Result) Equals(rhs *KeyValue_SetValue_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_SetValue_Result. func (v *KeyValue_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/envelope/internal/tests/services/keyvalue_setvaluev2.go b/envelope/internal/tests/services/keyvalue_setvaluev2.go index 53c5b664..15451e33 100644 --- a/envelope/internal/tests/services/keyvalue_setvaluev2.go +++ b/envelope/internal/tests/services/keyvalue_setvaluev2.go @@ -173,7 +173,8 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_SetValueV2_Args. func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", (string)(v.Key)) @@ -365,7 +366,8 @@ func (v *KeyValue_SetValueV2_Result) Equals(rhs *KeyValue_SetValueV2_Result) boo return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_SetValueV2_Result. func (v *KeyValue_SetValueV2_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/envelope/internal/tests/services/keyvalue_size.go b/envelope/internal/tests/services/keyvalue_size.go index cb4fbe93..668089e5 100644 --- a/envelope/internal/tests/services/keyvalue_size.go +++ b/envelope/internal/tests/services/keyvalue_size.go @@ -110,7 +110,8 @@ func (v *KeyValue_Size_Args) Equals(rhs *KeyValue_Size_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_Size_Args. func (v *KeyValue_Size_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil @@ -330,7 +331,8 @@ func (v *KeyValue_Size_Result) Equals(rhs *KeyValue_Size_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_Size_Result. func (v *KeyValue_Size_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go b/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go index cccb8aab..711bc3b3 100644 --- a/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go +++ b/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go @@ -109,7 +109,8 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Args) Equals(rhs *NonSta return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of NonStandardServiceName_NonStandardFunctionName_Args. func (v *NonStandardServiceName_NonStandardFunctionName_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil @@ -278,7 +279,8 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Result) Equals(rhs *NonS return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of NonStandardServiceName_NonStandardFunctionName_Result. func (v *NonStandardServiceName_NonStandardFunctionName_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/envelope/internal/tests/services/types.go b/envelope/internal/tests/services/types.go index 094496c3..a5345ac8 100644 --- a/envelope/internal/tests/services/types.go +++ b/envelope/internal/tests/services/types.go @@ -167,7 +167,8 @@ func (v *ConflictingNamesSetValueArgs) Equals(rhs *ConflictingNamesSetValueArgs) return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ConflictingNamesSetValueArgs. func (v *ConflictingNamesSetValueArgs) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", v.Key) @@ -301,7 +302,8 @@ func (v *InternalError) Equals(rhs *InternalError) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of InternalError. func (v *InternalError) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Message != nil { diff --git a/envelope/internal/tests/structs/types.go b/envelope/internal/tests/structs/types.go index 8fa9b752..cb45b5f0 100644 --- a/envelope/internal/tests/structs/types.go +++ b/envelope/internal/tests/structs/types.go @@ -141,7 +141,8 @@ func (v *ContactInfo) Equals(rhs *ContactInfo) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ContactInfo. func (v *ContactInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("emailAddress", v.EmailAddress) @@ -701,25 +702,28 @@ func (v *DefaultsStruct) Equals(rhs *DefaultsStruct) bool { type _List_String_Zapper []string -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendString(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_String_Zapper. +func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendString(v) } return nil } type _List_Double_Zapper []float64 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendFloat64(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Double_Zapper. +func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendFloat64(v) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of DefaultsStruct. func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.RequiredPrimitive != nil { @@ -1017,7 +1021,8 @@ func (v *Edge) Equals(rhs *Edge) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Edge. func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("startPoint", v.StartPoint); err != nil { @@ -1115,7 +1120,8 @@ func (v *EmptyStruct) Equals(rhs *EmptyStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EmptyStruct. func (v *EmptyStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil @@ -1264,7 +1270,8 @@ func (v *Frame) Equals(rhs *Frame) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Frame. func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("topLeft", v.TopLeft); err != nil { @@ -1534,7 +1541,8 @@ func (v *GoTags) Equals(rhs *GoTags) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of GoTags. func (v *GoTags) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("Foo", v.Foo) @@ -1769,17 +1777,19 @@ func (v *Graph) Equals(rhs *Graph) bool { type _List_Edge_Zapper []*Edge -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Edge_Zapper. +func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Graph. func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { @@ -1822,6 +1832,10 @@ func (lhs *List) Equals(rhs *List) bool { return (*Node)(lhs).Equals((*Node)(rhs)) } +func (v *List) MarshalLogObject(enc zapcore.ObjectEncoder) error { + return ((*Node)(v)).MarshalLogObject(enc) +} + // Node is linked list of values. // All values are 32-bit integers. type Node struct { @@ -1960,7 +1974,8 @@ func (v *Node) Equals(rhs *Node) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Node. func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", v.Value) @@ -2120,7 +2135,8 @@ func (v *Omit) Equals(rhs *Omit) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Omit. func (v *Omit) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("serialized", v.Serialized) @@ -2271,7 +2287,8 @@ func (v *Point) Equals(rhs *Point) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Point. func (v *Point) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddFloat64("x", v.X) @@ -2628,7 +2645,8 @@ func (v *PrimitiveOptionalStruct) Equals(rhs *PrimitiveOptionalStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of PrimitiveOptionalStruct. func (v *PrimitiveOptionalStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BoolField != nil { @@ -3039,7 +3057,8 @@ func (v *PrimitiveRequiredStruct) Equals(rhs *PrimitiveRequiredStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of PrimitiveRequiredStruct. func (v *PrimitiveRequiredStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddBool("boolField", v.BoolField) @@ -3225,7 +3244,8 @@ func (v *Rename) Equals(rhs *Rename) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Rename. func (v *Rename) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("Default", v.Default) @@ -3378,7 +3398,8 @@ func (v *Size) Equals(rhs *Size) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Size. func (v *Size) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddFloat64("width", v.Width) @@ -3532,7 +3553,8 @@ func (v *User) Equals(rhs *User) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of User. func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) diff --git a/envelope/internal/tests/typedefs/types.go b/envelope/internal/tests/typedefs/types.go index 0feb70b4..d6f4d1a8 100644 --- a/envelope/internal/tests/typedefs/types.go +++ b/envelope/internal/tests/typedefs/types.go @@ -25,6 +25,7 @@ package typedefs import ( "bytes" + "encoding/base64" "errors" "fmt" "go.uber.org/thriftrw/envelope/internal/tests/enums" @@ -103,6 +104,17 @@ func _Set_Binary_Equals(lhs, rhs [][]byte) bool { return true } +type _BinarySet_Zapper [][]byte + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _BinarySet_Zapper. +func (s _BinarySet_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range s { + enc.AppendString(base64.StdEncoding.EncodeToString(v)) + } + return nil +} + type BinarySet [][]byte // ToWire translates BinarySet into a Thrift-level intermediate @@ -134,6 +146,10 @@ func (lhs BinarySet) Equals(rhs BinarySet) bool { return _Set_Binary_Equals(lhs, rhs) } +func (v BinarySet) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_BinarySet_Zapper)(([][]byte)(v))).MarshalLogArray(enc) +} + type DefaultPrimitiveTypedef struct { State *State `json:"state,omitempty"` } @@ -267,7 +283,8 @@ func (v *DefaultPrimitiveTypedef) Equals(rhs *DefaultPrimitiveTypedef) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of DefaultPrimitiveTypedef. func (v *DefaultPrimitiveTypedef) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.State != nil { @@ -409,6 +426,41 @@ func _Map_Edge_Edge_Equals(lhs, rhs []struct { return true } +type _MapItem_Edge_Edge_Zapper struct { + Key *structs.Edge + Value *structs.Edge +} + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_Edge_Edge_Zapper. +func (v _MapItem_Edge_Edge_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("key", v.Key); err != nil { + return err + } + if err := enc.AddObject("value", v.Value); err != nil { + return err + } + return nil +} + +type _EdgeMap_Zapper []struct { + Key *structs.Edge + Value *structs.Edge +} + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _EdgeMap_Zapper. +func (m _EdgeMap_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range m { + k := i.Key + v := i.Value + if err := enc.AppendObject(_MapItem_Edge_Edge_Zapper{Key: k, Value: v}); err != nil { + return err + } + } + return nil +} + type EdgeMap []struct { Key *structs.Edge Value *structs.Edge @@ -449,6 +501,13 @@ func (lhs EdgeMap) Equals(rhs EdgeMap) bool { return _Map_Edge_Edge_Equals(lhs, rhs) } +func (v EdgeMap) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_EdgeMap_Zapper)(([]struct { + Key *structs.Edge + Value *structs.Edge + })(v))).MarshalLogArray(enc) +} + type Event struct { UUID *UUID `json:"uuid,required"` Time *Timestamp `json:"time,omitempty"` @@ -606,7 +665,8 @@ func (v *Event) Equals(rhs *Event) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Event. func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { @@ -702,6 +762,19 @@ func _List_Event_Equals(lhs, rhs []*Event) bool { return true } +type _EventGroup_Zapper []*Event + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _EventGroup_Zapper. +func (l _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { + return err + } + } + return nil +} + type EventGroup []*Event // ToWire translates EventGroup into a Thrift-level intermediate @@ -733,6 +806,10 @@ func (lhs EventGroup) Equals(rhs EventGroup) bool { return _List_Event_Equals(lhs, rhs) } +func (v EventGroup) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_EventGroup_Zapper)(([]*Event)(v))).MarshalLogArray(enc) +} + type _Set_Frame_ValueList []*structs.Frame func (v _Set_Frame_ValueList) ForEach(f func(wire.Value) error) error { @@ -808,6 +885,19 @@ func _Set_Frame_Equals(lhs, rhs []*structs.Frame) bool { return true } +type _FrameGroup_Zapper []*structs.Frame + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _FrameGroup_Zapper. +func (s _FrameGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range s { + if err := enc.AppendObject(v); err != nil { + return err + } + } + return nil +} + type FrameGroup []*structs.Frame // ToWire translates FrameGroup into a Thrift-level intermediate @@ -839,6 +929,10 @@ func (lhs FrameGroup) Equals(rhs FrameGroup) bool { return _Set_Frame_Equals(lhs, rhs) } +func (v FrameGroup) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_FrameGroup_Zapper)(([]*structs.Frame)(v))).MarshalLogArray(enc) +} + func _EnumWithValues_Read(w wire.Value) (enums.EnumWithValues, error) { var v enums.EnumWithValues err := v.FromWire(w) @@ -876,6 +970,10 @@ func (lhs MyEnum) Equals(rhs MyEnum) bool { return lhs.Equals(rhs) } +func (v MyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + return ((enums.EnumWithValues)(v)).MarshalLogObject(enc) +} + type PDF []byte // ToWire translates PDF into a Thrift-level intermediate @@ -1029,6 +1127,41 @@ func _Map_Point_Point_Equals(lhs, rhs []struct { return true } +type _MapItem_Point_Point_Zapper struct { + Key *structs.Point + Value *structs.Point +} + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_Point_Point_Zapper. +func (v _MapItem_Point_Point_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("key", v.Key); err != nil { + return err + } + if err := enc.AddObject("value", v.Value); err != nil { + return err + } + return nil +} + +type _PointMap_Zapper []struct { + Key *structs.Point + Value *structs.Point +} + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _PointMap_Zapper. +func (m _PointMap_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range m { + k := i.Key + v := i.Value + if err := enc.AppendObject(_MapItem_Point_Point_Zapper{Key: k, Value: v}); err != nil { + return err + } + } + return nil +} + type PointMap []struct { Key *structs.Point Value *structs.Point @@ -1069,6 +1202,13 @@ func (lhs PointMap) Equals(rhs PointMap) bool { return _Map_Point_Point_Equals(lhs, rhs) } +func (v PointMap) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_PointMap_Zapper)(([]struct { + Key *structs.Point + Value *structs.Point + })(v))).MarshalLogArray(enc) +} + type State string // ToWire translates State into a Thrift-level intermediate @@ -1296,19 +1436,8 @@ func (v *Transition) Equals(rhs *Transition) bool { return true } -type _EventGroup_Zapper []*Event - -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { - return err - } - } - return nil -} - -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Transition. func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("fromState", (string)(v.FromState)) @@ -1371,6 +1500,10 @@ func (lhs *UUID) Equals(rhs *UUID) bool { return (*I128)(lhs).Equals((*I128)(rhs)) } +func (v *UUID) MarshalLogObject(enc zapcore.ObjectEncoder) error { + return ((*I128)(v)).MarshalLogObject(enc) +} + type I128 struct { High int64 `json:"high,required"` Low int64 `json:"low,required"` @@ -1503,7 +1636,8 @@ func (v *I128) Equals(rhs *I128) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of I128. func (v *I128) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt64("high", v.High) diff --git a/envelope/internal/tests/unions/types.go b/envelope/internal/tests/unions/types.go index 87cd43ec..449a7e91 100644 --- a/envelope/internal/tests/unions/types.go +++ b/envelope/internal/tests/unions/types.go @@ -454,10 +454,11 @@ func (v *ArbitraryValue) Equals(rhs *ArbitraryValue) bool { type _List_ArbitraryValue_Zapper []*ArbitraryValue -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_ArbitraryValue_Zapper. +func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } @@ -466,9 +467,10 @@ func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_ArbitraryValue_Zapper. +func (m _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { if err := enc.AddObject((string)(k), v); err != nil { return err } @@ -476,7 +478,8 @@ func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.Ob return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ArbitraryValue. func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BoolValue != nil { @@ -707,7 +710,8 @@ func (v *Document) Equals(rhs *Document) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Document. func (v *Document) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Pdf != nil { @@ -817,7 +821,8 @@ func (v *EmptyUnion) Equals(rhs *EmptyUnion) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EmptyUnion. func (v *EmptyUnion) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/gen/internal/tests/collision/types.go b/gen/internal/tests/collision/types.go index 2cd6bc9b..d6776ba2 100644 --- a/gen/internal/tests/collision/types.go +++ b/gen/internal/tests/collision/types.go @@ -157,7 +157,8 @@ func (v *AccessorConflict) Equals(rhs *AccessorConflict) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of AccessorConflict. func (v *AccessorConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Name != nil { @@ -323,7 +324,8 @@ func (v *AccessorNoConflict) Equals(rhs *AccessorNoConflict) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of AccessorNoConflict. func (v *AccessorNoConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Getname != nil { @@ -942,19 +944,21 @@ func (v *PrimitiveContainers) Equals(rhs *PrimitiveContainers) bool { type _List_String_Zapper []string -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendString(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_String_Zapper. +func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendString(v) } return nil } type _Set_String_Zapper map[string]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_String_Zapper. +func (s _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range s { enc.AppendString(v) } return nil @@ -962,15 +966,17 @@ func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Map_String_String_Zapper map[string]string -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_String_Zapper. +func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { enc.AddString((string)(k), v) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of PrimitiveContainers. func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.A != nil { @@ -1156,7 +1162,8 @@ func (v *StructCollision) Equals(rhs *StructCollision) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of StructCollision. func (v *StructCollision) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddBool("collisionField", v.CollisionField) @@ -1331,7 +1338,8 @@ func (v *UnionCollision) Equals(rhs *UnionCollision) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of UnionCollision. func (v *UnionCollision) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.CollisionField != nil { @@ -1488,7 +1496,8 @@ func (v *WithDefault) Equals(rhs *WithDefault) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of WithDefault. func (v *WithDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Pouet != nil { @@ -1852,7 +1861,8 @@ func (v *StructCollision2) Equals(rhs *StructCollision2) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of StructCollision2. func (v *StructCollision2) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddBool("collisionField", v.CollisionField) @@ -2017,7 +2027,8 @@ func (v *UnionCollision2) Equals(rhs *UnionCollision2) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of UnionCollision2. func (v *UnionCollision2) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.CollisionField != nil { diff --git a/gen/internal/tests/containers/types.go b/gen/internal/tests/containers/types.go index 4b6b56fb..e26f5e50 100644 --- a/gen/internal/tests/containers/types.go +++ b/gen/internal/tests/containers/types.go @@ -1656,20 +1656,22 @@ func (v *ContainersOfContainers) Equals(rhs *ContainersOfContainers) bool { type _List_I32_Zapper []int32 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendInt32(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_I32_Zapper. +func (l _List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendInt32(v) } return nil } type _List_List_I32_Zapper [][]int32 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendArray((_List_I32_Zapper)(val)); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_List_I32_Zapper. +func (l _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendArray((_List_I32_Zapper)(v)); err != nil { return err } } @@ -1678,9 +1680,10 @@ func (vals _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) erro type _Set_I32_Zapper map[int32]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_I32_Zapper. +func (s _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range s { enc.AppendInt32(v) } return nil @@ -1688,10 +1691,11 @@ func (vals _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_Set_I32_Zapper []map[int32]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendArray((_Set_I32_Zapper)(val)); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Set_I32_Zapper. +func (l _List_Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendArray((_Set_I32_Zapper)(v)); err != nil { return err } } @@ -1703,7 +1707,8 @@ type _MapItem_I32_I32_Zapper struct { Value int32 } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_I32_I32_Zapper. func (v _MapItem_I32_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", v.Key) enc.AddInt32("value", v.Value) @@ -1712,9 +1717,10 @@ func (v _MapItem_I32_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) err type _Map_I32_I32_Zapper map[int32]int32 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for k, v := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_I32_I32_Zapper. +func (m _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range m { if err := enc.AppendObject(_MapItem_I32_I32_Zapper{Key: k, Value: v}); err != nil { return err } @@ -1724,10 +1730,11 @@ func (keyvals _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) err type _List_Map_I32_I32_Zapper []map[int32]int32 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendArray((_Map_I32_I32_Zapper)(val)); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Map_I32_I32_Zapper. +func (l _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendArray((_Map_I32_I32_Zapper)(v)); err != nil { return err } } @@ -1736,9 +1743,10 @@ func (vals _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e type _Set_String_Zapper map[string]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_String_Zapper. +func (s _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range s { enc.AppendString(v) } return nil @@ -1746,9 +1754,10 @@ func (vals _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Set_Set_String_Zapper []map[string]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_Set_String_Zapper. +func (s _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range s { if err := enc.AppendArray((_Set_String_Zapper)(v)); err != nil { return err } @@ -1758,19 +1767,21 @@ func (vals _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) err type _List_String_Zapper []string -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendString(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_String_Zapper. +func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendString(v) } return nil } type _Set_List_String_Zapper [][]string -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_List_String_Zapper. +func (s _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range s { if err := enc.AppendArray((_List_String_Zapper)(v)); err != nil { return err } @@ -1780,9 +1791,10 @@ func (vals _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) er type _Map_String_String_Zapper map[string]string -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_String_Zapper. +func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { enc.AddString((string)(k), v) } return nil @@ -1790,9 +1802,10 @@ func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEnco type _Set_Map_String_String_Zapper []map[string]string -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_Map_String_String_Zapper. +func (s _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range s { if err := enc.AppendObject((_Map_String_String_Zapper)(v)); err != nil { return err } @@ -1802,9 +1815,10 @@ func (vals _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncod type _Map_String_I32_Zapper map[string]int32 -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_I32_Zapper. +func (m _Map_String_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { enc.AddInt32((string)(k), v) } return nil @@ -1815,7 +1829,8 @@ type _MapItem_Map_String_I32_I64_Zapper struct { Value int64 } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_Map_String_I32_I64_Zapper. func (v _MapItem_Map_String_I32_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", (_Map_String_I32_Zapper)(v.Key)); err != nil { return err @@ -1829,9 +1844,10 @@ type _Map_Map_String_I32_I64_Zapper []struct { Value int64 } -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, i := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_Map_String_I32_I64_Zapper. +func (m _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range m { k := i.Key v := i.Value if err := enc.AppendObject(_MapItem_Map_String_I32_I64_Zapper{Key: k, Value: v}); err != nil { @@ -1843,9 +1859,10 @@ func (keyvals _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayE type _Set_I64_Zapper map[int64]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_I64_Zapper. +func (s _Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range s { enc.AppendInt64(v) } return nil @@ -1856,7 +1873,8 @@ type _MapItem_List_I32_Set_I64_Zapper struct { Value map[int64]struct{} } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_List_I32_Set_I64_Zapper. func (v _MapItem_List_I32_Set_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("key", (_List_I32_Zapper)(v.Key)); err != nil { return err @@ -1872,9 +1890,10 @@ type _Map_List_I32_Set_I64_Zapper []struct { Value map[int64]struct{} } -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, i := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_List_I32_Set_I64_Zapper. +func (m _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range m { k := i.Key v := i.Value if err := enc.AppendObject(_MapItem_List_I32_Set_I64_Zapper{Key: k, Value: v}); err != nil { @@ -1886,10 +1905,11 @@ func (keyvals _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEnc type _List_Double_Zapper []float64 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendFloat64(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Double_Zapper. +func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendFloat64(v) } return nil } @@ -1899,7 +1919,8 @@ type _MapItem_Set_I32_List_Double_Zapper struct { Value []float64 } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_Set_I32_List_Double_Zapper. func (v _MapItem_Set_I32_List_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("key", (_Set_I32_Zapper)(v.Key)); err != nil { return err @@ -1915,9 +1936,10 @@ type _Map_Set_I32_List_Double_Zapper []struct { Value []float64 } -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, i := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_Set_I32_List_Double_Zapper. +func (m _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range m { k := i.Key v := i.Value if err := enc.AppendObject(_MapItem_Set_I32_List_Double_Zapper{Key: k, Value: v}); err != nil { @@ -1927,7 +1949,8 @@ func (keyvals _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.Array return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ContainersOfContainers. func (v *ContainersOfContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfLists != nil { @@ -2456,10 +2479,11 @@ func (v *EnumContainers) Equals(rhs *EnumContainers) bool { type _List_EnumDefault_Zapper []enums.EnumDefault -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_EnumDefault_Zapper. +func (l _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } @@ -2468,9 +2492,10 @@ func (vals _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e type _Set_EnumWithValues_Zapper map[enums.EnumWithValues]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_EnumWithValues_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_EnumWithValues_Zapper. +func (s _Set_EnumWithValues_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range s { if err := enc.AppendObject(v); err != nil { return err } @@ -2483,7 +2508,8 @@ type _MapItem_EnumWithDuplicateValues_I32_Zapper struct { Value int32 } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_EnumWithDuplicateValues_I32_Zapper. func (v _MapItem_EnumWithDuplicateValues_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", v.Key); err != nil { return err @@ -2494,9 +2520,10 @@ func (v _MapItem_EnumWithDuplicateValues_I32_Zapper) MarshalLogObject(enc zapcor type _Map_EnumWithDuplicateValues_I32_Zapper map[enums.EnumWithDuplicateValues]int32 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for k, v := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_EnumWithDuplicateValues_I32_Zapper. +func (m _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range m { if err := enc.AppendObject(_MapItem_EnumWithDuplicateValues_I32_Zapper{Key: k, Value: v}); err != nil { return err } @@ -2504,7 +2531,8 @@ func (keyvals _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapco return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumContainers. func (v *EnumContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfEnums != nil { @@ -2827,10 +2855,11 @@ func (v *ListOfConflictingEnums) Equals(rhs *ListOfConflictingEnums) bool { type _List_RecordType_Zapper []enum_conflict.RecordType -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_RecordType_Zapper. +func (l _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } @@ -2839,17 +2868,19 @@ func (vals _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) er type _List_RecordType_1_Zapper []enums.RecordType -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_RecordType_1_Zapper. +func (l _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ListOfConflictingEnums. func (v *ListOfConflictingEnums) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("records", (_List_RecordType_Zapper)(v.Records)); err != nil { @@ -3143,10 +3174,11 @@ func (v *ListOfConflictingUUIDs) Equals(rhs *ListOfConflictingUUIDs) bool { type _List_UUID_Zapper []*typedefs.UUID -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject((*typedefs.I128)(val)); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_UUID_Zapper. +func (l _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject((*typedefs.I128)(v)); err != nil { return err } } @@ -3155,15 +3187,17 @@ func (vals _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_UUID_1_Zapper []uuid_conflict.UUID -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendString((string)(val)) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_UUID_1_Zapper. +func (l _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendString((string)(v)) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ListOfConflictingUUIDs. func (v *ListOfConflictingUUIDs) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("uuids", (_List_UUID_Zapper)(v.Uuids)); err != nil { @@ -3517,7 +3551,8 @@ type _MapItem_Binary_String_Zapper struct { Value string } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_Binary_String_Zapper. func (v _MapItem_Binary_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", base64.StdEncoding.EncodeToString(v.Key)) enc.AddString("value", v.Value) @@ -3529,9 +3564,10 @@ type _Map_Binary_String_Zapper []struct { Value string } -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, i := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_Binary_String_Zapper. +func (m _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range m { k := i.Key v := i.Value if err := enc.AppendObject(_MapItem_Binary_String_Zapper{Key: k, Value: v}); err != nil { @@ -3543,15 +3579,17 @@ func (keyvals _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncode type _Map_String_Binary_Zapper map[string][]byte -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_Binary_Zapper. +func (m _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { enc.AddString((string)(k), base64.StdEncoding.EncodeToString(v)) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of MapOfBinaryAndString. func (v *MapOfBinaryAndString) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BinaryToString != nil { @@ -4158,29 +4196,32 @@ func (v *PrimitiveContainers) Equals(rhs *PrimitiveContainers) bool { type _List_Binary_Zapper [][]byte -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Binary_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendString(base64.StdEncoding.EncodeToString(val)) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Binary_Zapper. +func (l _List_Binary_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendString(base64.StdEncoding.EncodeToString(v)) } return nil } type _List_I64_Zapper []int64 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendInt64(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_I64_Zapper. +func (l _List_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendInt64(v) } return nil } type _Set_Byte_Zapper map[int8]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _Set_Byte_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for v := range vals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Set_Byte_Zapper. +func (s _Set_Byte_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for v := range s { enc.AppendInt8(v) } return nil @@ -4191,7 +4232,8 @@ type _MapItem_I32_String_Zapper struct { Value string } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_I32_String_Zapper. func (v _MapItem_I32_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", v.Key) enc.AddString("value", v.Value) @@ -4200,9 +4242,10 @@ func (v _MapItem_I32_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) type _Map_I32_String_Zapper map[int32]string -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for k, v := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_I32_String_Zapper. +func (m _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range m { if err := enc.AppendObject(_MapItem_I32_String_Zapper{Key: k, Value: v}); err != nil { return err } @@ -4212,15 +4255,17 @@ func (keyvals _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) type _Map_String_Bool_Zapper map[string]bool -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_Bool_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_Bool_Zapper. +func (m _Map_String_Bool_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { enc.AddBool((string)(k), v) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of PrimitiveContainers. func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfBinary != nil { @@ -4572,7 +4617,8 @@ type _MapItem_I64_Double_Zapper struct { Value float64 } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_I64_Double_Zapper. func (v _MapItem_I64_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt64("key", v.Key) enc.AddFloat64("value", v.Value) @@ -4581,9 +4627,10 @@ func (v _MapItem_I64_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) type _Map_I64_Double_Zapper map[int64]float64 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for k, v := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_I64_Double_Zapper. +func (m _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range m { if err := enc.AppendObject(_MapItem_I64_Double_Zapper{Key: k, Value: v}); err != nil { return err } @@ -4591,7 +4638,8 @@ func (keyvals _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of PrimitiveContainersRequired. func (v *PrimitiveContainersRequired) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("listOfStrings", (_List_String_Zapper)(v.ListOfStrings)); err != nil { diff --git a/gen/internal/tests/enum_conflict/types.go b/gen/internal/tests/enum_conflict/types.go index 03a3d583..0a0c2dc0 100644 --- a/gen/internal/tests/enum_conflict/types.go +++ b/gen/internal/tests/enum_conflict/types.go @@ -364,7 +364,8 @@ func (v *Records) Equals(rhs *Records) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Records. func (v *Records) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.RecordType != nil { diff --git a/gen/internal/tests/enums/types.go b/gen/internal/tests/enums/types.go index 3388aced..83daa024 100644 --- a/gen/internal/tests/enums/types.go +++ b/gen/internal/tests/enums/types.go @@ -1374,7 +1374,8 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of StructWithOptionalEnum. func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.E != nil { diff --git a/gen/internal/tests/exceptions/types.go b/gen/internal/tests/exceptions/types.go index 27a164d1..47384ca4 100644 --- a/gen/internal/tests/exceptions/types.go +++ b/gen/internal/tests/exceptions/types.go @@ -155,7 +155,8 @@ func (v *DoesNotExistException) Equals(rhs *DoesNotExistException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of DoesNotExistException. func (v *DoesNotExistException) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", v.Key) @@ -261,7 +262,8 @@ func (v *EmptyException) Equals(rhs *EmptyException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EmptyException. func (v *EmptyException) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/gen/internal/tests/services/cache_clear.go b/gen/internal/tests/services/cache_clear.go index ba96159e..dcb615b5 100644 --- a/gen/internal/tests/services/cache_clear.go +++ b/gen/internal/tests/services/cache_clear.go @@ -89,7 +89,8 @@ func (v *Cache_Clear_Args) Equals(rhs *Cache_Clear_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Cache_Clear_Args. func (v *Cache_Clear_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/gen/internal/tests/services/cache_clearafter.go b/gen/internal/tests/services/cache_clearafter.go index c41302ab..071f3d40 100644 --- a/gen/internal/tests/services/cache_clearafter.go +++ b/gen/internal/tests/services/cache_clearafter.go @@ -129,7 +129,8 @@ func (v *Cache_ClearAfter_Args) Equals(rhs *Cache_ClearAfter_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Cache_ClearAfter_Args. func (v *Cache_ClearAfter_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DurationMS != nil { diff --git a/gen/internal/tests/services/conflictingnames_setvalue.go b/gen/internal/tests/services/conflictingnames_setvalue.go index 993bc12a..81e9a13f 100644 --- a/gen/internal/tests/services/conflictingnames_setvalue.go +++ b/gen/internal/tests/services/conflictingnames_setvalue.go @@ -123,7 +123,8 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ConflictingNames_SetValue_Args. func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { @@ -314,7 +315,8 @@ func (v *ConflictingNames_SetValue_Result) Equals(rhs *ConflictingNames_SetValue return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ConflictingNames_SetValue_Result. func (v *ConflictingNames_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/gen/internal/tests/services/keyvalue_deletevalue.go b/gen/internal/tests/services/keyvalue_deletevalue.go index 62897187..918f6b5a 100644 --- a/gen/internal/tests/services/keyvalue_deletevalue.go +++ b/gen/internal/tests/services/keyvalue_deletevalue.go @@ -137,7 +137,8 @@ func (v *KeyValue_DeleteValue_Args) Equals(rhs *KeyValue_DeleteValue_Args) bool return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_DeleteValue_Args. func (v *KeyValue_DeleteValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -431,7 +432,8 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_DeleteValue_Result. func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DoesNotExist != nil { diff --git a/gen/internal/tests/services/keyvalue_getmanyvalues.go b/gen/internal/tests/services/keyvalue_getmanyvalues.go index b23a85db..90d11c29 100644 --- a/gen/internal/tests/services/keyvalue_getmanyvalues.go +++ b/gen/internal/tests/services/keyvalue_getmanyvalues.go @@ -181,15 +181,17 @@ func (v *KeyValue_GetManyValues_Args) Equals(rhs *KeyValue_GetManyValues_Args) b type _List_Key_Zapper []Key -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendString((string)(val)) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Key_Zapper. +func (l _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendString((string)(v)) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_GetManyValues_Args. func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Range != nil { @@ -540,17 +542,19 @@ func (v *KeyValue_GetManyValues_Result) Equals(rhs *KeyValue_GetManyValues_Resul type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_ArbitraryValue_Zapper. +func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_GetManyValues_Result. func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/gen/internal/tests/services/keyvalue_getvalue.go b/gen/internal/tests/services/keyvalue_getvalue.go index bf796ad6..252c11fd 100644 --- a/gen/internal/tests/services/keyvalue_getvalue.go +++ b/gen/internal/tests/services/keyvalue_getvalue.go @@ -122,7 +122,8 @@ func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_GetValue_Args. func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -401,7 +402,8 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_GetValue_Result. func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/gen/internal/tests/services/keyvalue_setvalue.go b/gen/internal/tests/services/keyvalue_setvalue.go index b6730ae5..5db74323 100644 --- a/gen/internal/tests/services/keyvalue_setvalue.go +++ b/gen/internal/tests/services/keyvalue_setvalue.go @@ -144,7 +144,8 @@ func (v *KeyValue_SetValue_Args) Equals(rhs *KeyValue_SetValue_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_SetValue_Args. func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -352,7 +353,8 @@ func (v *KeyValue_SetValue_Result) Equals(rhs *KeyValue_SetValue_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_SetValue_Result. func (v *KeyValue_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/gen/internal/tests/services/keyvalue_setvaluev2.go b/gen/internal/tests/services/keyvalue_setvaluev2.go index 9601bab8..4559b43b 100644 --- a/gen/internal/tests/services/keyvalue_setvaluev2.go +++ b/gen/internal/tests/services/keyvalue_setvaluev2.go @@ -153,7 +153,8 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_SetValueV2_Args. func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", (string)(v.Key)) @@ -345,7 +346,8 @@ func (v *KeyValue_SetValueV2_Result) Equals(rhs *KeyValue_SetValueV2_Result) boo return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_SetValueV2_Result. func (v *KeyValue_SetValueV2_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/gen/internal/tests/services/keyvalue_size.go b/gen/internal/tests/services/keyvalue_size.go index b88793b7..4f2e232a 100644 --- a/gen/internal/tests/services/keyvalue_size.go +++ b/gen/internal/tests/services/keyvalue_size.go @@ -90,7 +90,8 @@ func (v *KeyValue_Size_Args) Equals(rhs *KeyValue_Size_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_Size_Args. func (v *KeyValue_Size_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil @@ -310,7 +311,8 @@ func (v *KeyValue_Size_Result) Equals(rhs *KeyValue_Size_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of KeyValue_Size_Result. func (v *KeyValue_Size_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go b/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go index f34ee6c5..172dc17a 100644 --- a/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go +++ b/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go @@ -89,7 +89,8 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Args) Equals(rhs *NonSta return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of NonStandardServiceName_NonStandardFunctionName_Args. func (v *NonStandardServiceName_NonStandardFunctionName_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil @@ -258,7 +259,8 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Result) Equals(rhs *NonS return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of NonStandardServiceName_NonStandardFunctionName_Result. func (v *NonStandardServiceName_NonStandardFunctionName_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/gen/internal/tests/services/types.go b/gen/internal/tests/services/types.go index 2283fb97..720ef3dc 100644 --- a/gen/internal/tests/services/types.go +++ b/gen/internal/tests/services/types.go @@ -147,7 +147,8 @@ func (v *ConflictingNamesSetValueArgs) Equals(rhs *ConflictingNamesSetValueArgs) return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ConflictingNamesSetValueArgs. func (v *ConflictingNamesSetValueArgs) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", v.Key) @@ -281,7 +282,8 @@ func (v *InternalError) Equals(rhs *InternalError) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of InternalError. func (v *InternalError) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Message != nil { diff --git a/gen/internal/tests/structs/types.go b/gen/internal/tests/structs/types.go index 2b3327ce..4040c2a5 100644 --- a/gen/internal/tests/structs/types.go +++ b/gen/internal/tests/structs/types.go @@ -121,7 +121,8 @@ func (v *ContactInfo) Equals(rhs *ContactInfo) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ContactInfo. func (v *ContactInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("emailAddress", v.EmailAddress) @@ -681,25 +682,28 @@ func (v *DefaultsStruct) Equals(rhs *DefaultsStruct) bool { type _List_String_Zapper []string -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendString(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_String_Zapper. +func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendString(v) } return nil } type _List_Double_Zapper []float64 -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendFloat64(val) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Double_Zapper. +func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendFloat64(v) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of DefaultsStruct. func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.RequiredPrimitive != nil { @@ -997,7 +1001,8 @@ func (v *Edge) Equals(rhs *Edge) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Edge. func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("startPoint", v.StartPoint); err != nil { @@ -1095,7 +1100,8 @@ func (v *EmptyStruct) Equals(rhs *EmptyStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EmptyStruct. func (v *EmptyStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil @@ -1244,7 +1250,8 @@ func (v *Frame) Equals(rhs *Frame) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Frame. func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("topLeft", v.TopLeft); err != nil { @@ -1514,7 +1521,8 @@ func (v *GoTags) Equals(rhs *GoTags) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of GoTags. func (v *GoTags) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("Foo", v.Foo) @@ -1749,17 +1757,19 @@ func (v *Graph) Equals(rhs *Graph) bool { type _List_Edge_Zapper []*Edge -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Edge_Zapper. +func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Graph. func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { @@ -1802,6 +1812,10 @@ func (lhs *List) Equals(rhs *List) bool { return (*Node)(lhs).Equals((*Node)(rhs)) } +func (v *List) MarshalLogObject(enc zapcore.ObjectEncoder) error { + return ((*Node)(v)).MarshalLogObject(enc) +} + // Node is linked list of values. // All values are 32-bit integers. type Node struct { @@ -1940,7 +1954,8 @@ func (v *Node) Equals(rhs *Node) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Node. func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", v.Value) @@ -2100,7 +2115,8 @@ func (v *Omit) Equals(rhs *Omit) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Omit. func (v *Omit) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("serialized", v.Serialized) @@ -2251,7 +2267,8 @@ func (v *Point) Equals(rhs *Point) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Point. func (v *Point) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddFloat64("x", v.X) @@ -2608,7 +2625,8 @@ func (v *PrimitiveOptionalStruct) Equals(rhs *PrimitiveOptionalStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of PrimitiveOptionalStruct. func (v *PrimitiveOptionalStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BoolField != nil { @@ -3019,7 +3037,8 @@ func (v *PrimitiveRequiredStruct) Equals(rhs *PrimitiveRequiredStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of PrimitiveRequiredStruct. func (v *PrimitiveRequiredStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddBool("boolField", v.BoolField) @@ -3205,7 +3224,8 @@ func (v *Rename) Equals(rhs *Rename) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Rename. func (v *Rename) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("Default", v.Default) @@ -3358,7 +3378,8 @@ func (v *Size) Equals(rhs *Size) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Size. func (v *Size) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddFloat64("width", v.Width) @@ -3512,7 +3533,8 @@ func (v *User) Equals(rhs *User) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of User. func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) diff --git a/gen/internal/tests/typedefs/types.go b/gen/internal/tests/typedefs/types.go index 9253922f..1ef45b10 100644 --- a/gen/internal/tests/typedefs/types.go +++ b/gen/internal/tests/typedefs/types.go @@ -5,6 +5,7 @@ package typedefs import ( "bytes" + "encoding/base64" "errors" "fmt" "go.uber.org/thriftrw/gen/internal/tests/enums" @@ -83,6 +84,17 @@ func _Set_Binary_Equals(lhs, rhs [][]byte) bool { return true } +type _BinarySet_Zapper [][]byte + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _BinarySet_Zapper. +func (s _BinarySet_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range s { + enc.AppendString(base64.StdEncoding.EncodeToString(v)) + } + return nil +} + type BinarySet [][]byte // ToWire translates BinarySet into a Thrift-level intermediate @@ -114,6 +126,10 @@ func (lhs BinarySet) Equals(rhs BinarySet) bool { return _Set_Binary_Equals(lhs, rhs) } +func (v BinarySet) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_BinarySet_Zapper)(([][]byte)(v))).MarshalLogArray(enc) +} + type DefaultPrimitiveTypedef struct { State *State `json:"state,omitempty"` } @@ -247,7 +263,8 @@ func (v *DefaultPrimitiveTypedef) Equals(rhs *DefaultPrimitiveTypedef) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of DefaultPrimitiveTypedef. func (v *DefaultPrimitiveTypedef) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.State != nil { @@ -389,6 +406,41 @@ func _Map_Edge_Edge_Equals(lhs, rhs []struct { return true } +type _MapItem_Edge_Edge_Zapper struct { + Key *structs.Edge + Value *structs.Edge +} + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_Edge_Edge_Zapper. +func (v _MapItem_Edge_Edge_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("key", v.Key); err != nil { + return err + } + if err := enc.AddObject("value", v.Value); err != nil { + return err + } + return nil +} + +type _EdgeMap_Zapper []struct { + Key *structs.Edge + Value *structs.Edge +} + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _EdgeMap_Zapper. +func (m _EdgeMap_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range m { + k := i.Key + v := i.Value + if err := enc.AppendObject(_MapItem_Edge_Edge_Zapper{Key: k, Value: v}); err != nil { + return err + } + } + return nil +} + type EdgeMap []struct { Key *structs.Edge Value *structs.Edge @@ -429,6 +481,13 @@ func (lhs EdgeMap) Equals(rhs EdgeMap) bool { return _Map_Edge_Edge_Equals(lhs, rhs) } +func (v EdgeMap) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_EdgeMap_Zapper)(([]struct { + Key *structs.Edge + Value *structs.Edge + })(v))).MarshalLogArray(enc) +} + type Event struct { UUID *UUID `json:"uuid,required"` Time *Timestamp `json:"time,omitempty"` @@ -586,7 +645,8 @@ func (v *Event) Equals(rhs *Event) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Event. func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { @@ -682,6 +742,19 @@ func _List_Event_Equals(lhs, rhs []*Event) bool { return true } +type _EventGroup_Zapper []*Event + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _EventGroup_Zapper. +func (l _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { + return err + } + } + return nil +} + type EventGroup []*Event // ToWire translates EventGroup into a Thrift-level intermediate @@ -713,6 +786,10 @@ func (lhs EventGroup) Equals(rhs EventGroup) bool { return _List_Event_Equals(lhs, rhs) } +func (v EventGroup) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_EventGroup_Zapper)(([]*Event)(v))).MarshalLogArray(enc) +} + type _Set_Frame_ValueList []*structs.Frame func (v _Set_Frame_ValueList) ForEach(f func(wire.Value) error) error { @@ -788,6 +865,19 @@ func _Set_Frame_Equals(lhs, rhs []*structs.Frame) bool { return true } +type _FrameGroup_Zapper []*structs.Frame + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _FrameGroup_Zapper. +func (s _FrameGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range s { + if err := enc.AppendObject(v); err != nil { + return err + } + } + return nil +} + type FrameGroup []*structs.Frame // ToWire translates FrameGroup into a Thrift-level intermediate @@ -819,6 +909,10 @@ func (lhs FrameGroup) Equals(rhs FrameGroup) bool { return _Set_Frame_Equals(lhs, rhs) } +func (v FrameGroup) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_FrameGroup_Zapper)(([]*structs.Frame)(v))).MarshalLogArray(enc) +} + func _EnumWithValues_Read(w wire.Value) (enums.EnumWithValues, error) { var v enums.EnumWithValues err := v.FromWire(w) @@ -856,6 +950,10 @@ func (lhs MyEnum) Equals(rhs MyEnum) bool { return lhs.Equals(rhs) } +func (v MyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { + return ((enums.EnumWithValues)(v)).MarshalLogObject(enc) +} + type PDF []byte // ToWire translates PDF into a Thrift-level intermediate @@ -1009,6 +1107,41 @@ func _Map_Point_Point_Equals(lhs, rhs []struct { return true } +type _MapItem_Point_Point_Zapper struct { + Key *structs.Point + Value *structs.Point +} + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_Point_Point_Zapper. +func (v _MapItem_Point_Point_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("key", v.Key); err != nil { + return err + } + if err := enc.AddObject("value", v.Value); err != nil { + return err + } + return nil +} + +type _PointMap_Zapper []struct { + Key *structs.Point + Value *structs.Point +} + +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _PointMap_Zapper. +func (m _PointMap_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, i := range m { + k := i.Key + v := i.Value + if err := enc.AppendObject(_MapItem_Point_Point_Zapper{Key: k, Value: v}); err != nil { + return err + } + } + return nil +} + type PointMap []struct { Key *structs.Point Value *structs.Point @@ -1049,6 +1182,13 @@ func (lhs PointMap) Equals(rhs PointMap) bool { return _Map_Point_Point_Equals(lhs, rhs) } +func (v PointMap) MarshalLogArray(enc zapcore.ArrayEncoder) error { + return ((_PointMap_Zapper)(([]struct { + Key *structs.Point + Value *structs.Point + })(v))).MarshalLogArray(enc) +} + type State string // ToWire translates State into a Thrift-level intermediate @@ -1276,19 +1416,8 @@ func (v *Transition) Equals(rhs *Transition) bool { return true } -type _EventGroup_Zapper []*Event - -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { - return err - } - } - return nil -} - -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Transition. func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("fromState", (string)(v.FromState)) @@ -1351,6 +1480,10 @@ func (lhs *UUID) Equals(rhs *UUID) bool { return (*I128)(lhs).Equals((*I128)(rhs)) } +func (v *UUID) MarshalLogObject(enc zapcore.ObjectEncoder) error { + return ((*I128)(v)).MarshalLogObject(enc) +} + type I128 struct { High int64 `json:"high,required"` Low int64 `json:"low,required"` @@ -1483,7 +1616,8 @@ func (v *I128) Equals(rhs *I128) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of I128. func (v *I128) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt64("high", v.High) diff --git a/gen/internal/tests/unions/types.go b/gen/internal/tests/unions/types.go index 3971a732..90b85c24 100644 --- a/gen/internal/tests/unions/types.go +++ b/gen/internal/tests/unions/types.go @@ -434,10 +434,11 @@ func (v *ArbitraryValue) Equals(rhs *ArbitraryValue) bool { type _List_ArbitraryValue_Zapper []*ArbitraryValue -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_ArbitraryValue_Zapper. +func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } @@ -446,9 +447,10 @@ func (vals _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_ArbitraryValue_Zapper. +func (m _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { if err := enc.AddObject((string)(k), v); err != nil { return err } @@ -456,7 +458,8 @@ func (keyvals _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.Ob return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ArbitraryValue. func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BoolValue != nil { @@ -687,7 +690,8 @@ func (v *Document) Equals(rhs *Document) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Document. func (v *Document) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Pdf != nil { @@ -797,7 +801,8 @@ func (v *EmptyUnion) Equals(rhs *EmptyUnion) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EmptyUnion. func (v *EmptyUnion) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/gen/internal/tests/uuid_conflict/types.go b/gen/internal/tests/uuid_conflict/types.go index 32be3b31..4eac67b2 100644 --- a/gen/internal/tests/uuid_conflict/types.go +++ b/gen/internal/tests/uuid_conflict/types.go @@ -189,7 +189,8 @@ func (v *UUIDConflict) Equals(rhs *UUIDConflict) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of UUIDConflict. func (v *UUIDConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("localUUID", (string)(v.LocalUUID)) diff --git a/internal/envelope/exception/types.go b/internal/envelope/exception/types.go index f0aae8fe..dcbf1d92 100644 --- a/internal/envelope/exception/types.go +++ b/internal/envelope/exception/types.go @@ -472,7 +472,8 @@ func (v *TApplicationException) Equals(rhs *TApplicationException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of TApplicationException. func (v *TApplicationException) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Message != nil { diff --git a/plugin/api/plugin_goodbye.go b/plugin/api/plugin_goodbye.go index 9c893c6e..180f0da5 100644 --- a/plugin/api/plugin_goodbye.go +++ b/plugin/api/plugin_goodbye.go @@ -109,7 +109,8 @@ func (v *Plugin_Goodbye_Args) Equals(rhs *Plugin_Goodbye_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Plugin_Goodbye_Args. func (v *Plugin_Goodbye_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil @@ -278,7 +279,8 @@ func (v *Plugin_Goodbye_Result) Equals(rhs *Plugin_Goodbye_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Plugin_Goodbye_Result. func (v *Plugin_Goodbye_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil diff --git a/plugin/api/plugin_handshake.go b/plugin/api/plugin_handshake.go index e23cf07f..8bda939c 100644 --- a/plugin/api/plugin_handshake.go +++ b/plugin/api/plugin_handshake.go @@ -144,7 +144,8 @@ func (v *Plugin_Handshake_Args) Equals(rhs *Plugin_Handshake_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Plugin_Handshake_Args. func (v *Plugin_Handshake_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { @@ -390,7 +391,8 @@ func (v *Plugin_Handshake_Result) Equals(rhs *Plugin_Handshake_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Plugin_Handshake_Result. func (v *Plugin_Handshake_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/plugin/api/servicegenerator_generate.go b/plugin/api/servicegenerator_generate.go index b8ea96e0..d231546e 100644 --- a/plugin/api/servicegenerator_generate.go +++ b/plugin/api/servicegenerator_generate.go @@ -144,7 +144,8 @@ func (v *ServiceGenerator_Generate_Args) Equals(rhs *ServiceGenerator_Generate_A return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ServiceGenerator_Generate_Args. func (v *ServiceGenerator_Generate_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { @@ -390,7 +391,8 @@ func (v *ServiceGenerator_Generate_Result) Equals(rhs *ServiceGenerator_Generate return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ServiceGenerator_Generate_Result. func (v *ServiceGenerator_Generate_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/plugin/api/types.go b/plugin/api/types.go index 7c20755e..1c36f51b 100644 --- a/plugin/api/types.go +++ b/plugin/api/types.go @@ -189,7 +189,8 @@ func (v *Argument) Equals(rhs *Argument) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Argument. func (v *Argument) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) @@ -808,10 +809,11 @@ func (v *Function) Equals(rhs *Function) bool { type _List_Argument_Zapper []*Argument -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Argument_Zapper. +func (l _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } @@ -820,15 +822,17 @@ func (vals _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) erro type _Map_String_String_Zapper map[string]string -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_String_Zapper. +func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { enc.AddString((string)(k), v) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Function. func (v *Function) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) @@ -1348,10 +1352,11 @@ func (v *GenerateServiceRequest) Equals(rhs *GenerateServiceRequest) bool { type _List_ServiceID_Zapper []ServiceID -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_ServiceID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - enc.AppendInt32((int32)(val)) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_ServiceID_Zapper. +func (l _List_ServiceID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + enc.AppendInt32((int32)(v)) } return nil } @@ -1361,7 +1366,8 @@ type _MapItem_ServiceID_Service_Zapper struct { Value *Service } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_ServiceID_Service_Zapper. func (v _MapItem_ServiceID_Service_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", (int32)(v.Key)) if err := enc.AddObject("value", v.Value); err != nil { @@ -1372,9 +1378,10 @@ func (v _MapItem_ServiceID_Service_Zapper) MarshalLogObject(enc zapcore.ObjectEn type _Map_ServiceID_Service_Zapper map[ServiceID]*Service -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_ServiceID_Service_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for k, v := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_ServiceID_Service_Zapper. +func (m _Map_ServiceID_Service_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range m { if err := enc.AppendObject(_MapItem_ServiceID_Service_Zapper{Key: k, Value: v}); err != nil { return err } @@ -1387,7 +1394,8 @@ type _MapItem_ModuleID_Module_Zapper struct { Value *Module } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _MapItem_ModuleID_Module_Zapper. func (v _MapItem_ModuleID_Module_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", (int32)(v.Key)) if err := enc.AddObject("value", v.Value); err != nil { @@ -1398,9 +1406,10 @@ func (v _MapItem_ModuleID_Module_Zapper) MarshalLogObject(enc zapcore.ObjectEnco type _Map_ModuleID_Module_Zapper map[ModuleID]*Module -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (keyvals _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for k, v := range keyvals { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _Map_ModuleID_Module_Zapper. +func (m _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for k, v := range m { if err := enc.AppendObject(_MapItem_ModuleID_Module_Zapper{Key: k, Value: v}); err != nil { return err } @@ -1408,7 +1417,8 @@ func (keyvals _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEnco return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of GenerateServiceRequest. func (v *GenerateServiceRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("rootServices", (_List_ServiceID_Zapper)(v.RootServices)); err != nil { @@ -1635,15 +1645,17 @@ func (v *GenerateServiceResponse) Equals(rhs *GenerateServiceResponse) bool { type _Map_String_Binary_Zapper map[string][]byte -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) -func (keyvals _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { - for k, v := range keyvals { +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of _Map_String_Binary_Zapper. +func (m _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { + for k, v := range m { enc.AddString((string)(k), base64.StdEncoding.EncodeToString(v)) } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of GenerateServiceResponse. func (v *GenerateServiceResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Files != nil { @@ -1743,7 +1755,8 @@ func (v *HandshakeRequest) Equals(rhs *HandshakeRequest) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of HandshakeRequest. func (v *HandshakeRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { return nil @@ -2023,17 +2036,19 @@ func (v *HandshakeResponse) Equals(rhs *HandshakeResponse) bool { type _List_Feature_Zapper []Feature -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Feature_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Feature_Zapper. +func (l _List_Feature_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of HandshakeResponse. func (v *HandshakeResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) @@ -2214,7 +2229,8 @@ func (v *Module) Equals(rhs *Module) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Module. func (v *Module) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("importPath", v.ImportPath) @@ -2600,17 +2616,19 @@ func (v *Service) Equals(rhs *Service) bool { type _List_Function_Zapper []*Function -// MarshalLogArray implements zapcore.ArrayMarshaler. (TODO) -func (vals _List_Function_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { - for _, val := range vals { - if err := enc.AppendObject(val); err != nil { +// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// fast logging of _List_Function_Zapper. +func (l _List_Function_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { + for _, v := range l { + if err := enc.AppendObject(v); err != nil { return err } } return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Service. func (v *Service) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) @@ -3253,7 +3271,8 @@ func (v *Type) Equals(rhs *Type) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Type. func (v *Type) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.SimpleType != nil { @@ -3493,7 +3512,8 @@ func (v *TypePair) Equals(rhs *TypePair) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of TypePair. func (v *TypePair) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("left", v.Left); err != nil { @@ -3691,7 +3711,8 @@ func (v *TypeReference) Equals(rhs *TypeReference) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler. (TODO) +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of TypeReference. func (v *TypeReference) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) From e886c900f2a650a22e714182239bb42c6980fc49 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Wed, 1 Aug 2018 10:33:28 -0700 Subject: [PATCH 10/25] Drop go version 1.7/1.8 in travis --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13ed7ff3..cc0bdd71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,6 @@ go_import_path: go.uber.org/thriftrw matrix: include: - - go: 1.7 - - go: 1.8 - go: 1.9 - go: '1.10' env: LINT=1 From ba7e94ef6c019a6ee1454cb57fd96fd9be3288ea Mon Sep 17 00:00:00 2001 From: Minho Park Date: Wed, 1 Aug 2018 11:30:59 -0700 Subject: [PATCH 11/25] Refactor Zap funcs --- gen/generator.go | 48 ++++----- gen/list.go | 45 ++++++++- gen/map.go | 135 +++++++++++++++++++++++++ gen/set.go | 49 +++++++++- gen/type.go | 4 + gen/zap.go | 249 +++++------------------------------------------ 6 files changed, 281 insertions(+), 249 deletions(-) diff --git a/gen/generator.go b/gen/generator.go index 836cb806..f69ad2dc 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -128,6 +128,7 @@ type generator struct { w WireGenerator e equalsGenerator + z zapGenerator decls []ast.Decl thriftImporter ThriftPackageImporter mangler *mangler @@ -196,30 +197,29 @@ func (g *generator) LookupConstantName(c *compile.Constant) (string, error) { // TextTemplate renders the given template with the given template context. func (g *generator) TextTemplate(s string, data interface{}, opts ...TemplateOption) (string, error) { templateFuncs := template.FuncMap{ - "formatDoc": formatDoc, - "goCase": goCase, - "goName": goName, - "import": g.Import, - "isHashable": isHashable, - "isPrimitiveType": isPrimitiveType, - "isStructType": isStructType, - "newNamespace": g.Namespace.Child, - "newVar": g.Namespace.Child().NewName, - "typeName": curryGenerator(typeName, g), - "typeReference": curryGenerator(typeReference, g), - "typeReferencePtr": curryGenerator(typeReferencePtr, g), - "fromWire": curryGenerator(g.w.FromWire, g), - "fromWirePtr": curryGenerator(g.w.FromWirePtr, g), - "toWire": curryGenerator(g.w.ToWire, g), - "toWirePtr": curryGenerator(g.w.ToWirePtr, g), - "typeCode": curryGenerator(TypeCode, g), - "equals": curryGenerator(g.e.Equals, g), - "equalsPtr": curryGenerator(g.e.EqualsPtr, g), - "zapCanError": zapCanError, - "zapEncoder": curryGenerator(zapEncoder, g), - "zapMarshaler": curryGenerator(zapMarshaler, g), - "zapMarshalerPtr": curryGenerator(zapMarshalerPtr, g), - "zapMapItemMarshaler": curryGenerator(zapMapItemMarshaler, g), + "formatDoc": formatDoc, + "goCase": goCase, + "goName": goName, + "import": g.Import, + "isHashable": isHashable, + "isPrimitiveType": isPrimitiveType, + "isStructType": isStructType, + "newNamespace": g.Namespace.Child, + "newVar": g.Namespace.Child().NewName, + "typeName": curryGenerator(typeName, g), + "typeReference": curryGenerator(typeReference, g), + "typeReferencePtr": curryGenerator(typeReferencePtr, g), + "fromWire": curryGenerator(g.w.FromWire, g), + "fromWirePtr": curryGenerator(g.w.FromWirePtr, g), + "toWire": curryGenerator(g.w.ToWire, g), + "toWirePtr": curryGenerator(g.w.ToWirePtr, g), + "typeCode": curryGenerator(TypeCode, g), + "equals": curryGenerator(g.e.Equals, g), + "equalsPtr": curryGenerator(g.e.EqualsPtr, g), + "zapCanError": g.z.zapCanError, + "zapEncoder": curryGenerator(g.z.zapEncoder, g), + "zapMarshaler": curryGenerator(g.z.zapMarshaler, g), + "zapMarshalerPtr": curryGenerator(g.z.zapMarshalerPtr, g), } tmpl := template.New("thriftrw").Delims("<", ">").Funcs(templateFuncs) diff --git a/gen/list.go b/gen/list.go index bac379d0..1c10fa27 100644 --- a/gen/list.go +++ b/gen/list.go @@ -20,7 +20,11 @@ package gen -import "go.uber.org/thriftrw/compile" +import ( + "fmt" + + "go.uber.org/thriftrw/compile" +) // listGenerator generates logic to convert lists of arbitrary Thrift types to // and from ValueLists. @@ -177,3 +181,42 @@ func (l *listGenerator) Equals(g Generator, spec *compile.ListSpec) (string, err return name, wrapGenerateError(spec.ThriftName(), err) } + +func (l *listGenerator) zapMarshaler( + g Generator, + spec compile.TypeSpec, + root *compile.ListSpec, + fieldValue string, +) (string, error) { + name := zapperName(g, spec) + if err := g.EnsureDeclared( + ` + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$l := newVar "l"> + <$v := newVar "v"> + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$l> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { + for _, <$v> := range <$l> { + if err := + <$enc>.Append() + <- if (zapCanError .Type.ValueSpec)>; err != nil { + return err + } + } + return nil + } + `, struct { + Name string + Type *compile.ListSpec + }{ + Name: name, + Type: root, + }, + ); err != nil { + return "", err + } + return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil +} diff --git a/gen/map.go b/gen/map.go index d901b815..1c6bb27b 100644 --- a/gen/map.go +++ b/gen/map.go @@ -281,3 +281,138 @@ func (m *mapGenerator) equalsUnhashable(g Generator, spec *compile.MapSpec) (str return name, wrapGenerateError(spec.ThriftName(), err) } + +func (m *mapGenerator) zapMarshaler( + g Generator, + spec compile.TypeSpec, + root *compile.MapSpec, + fieldValue string, +) (string, error) { + name := zapperName(g, spec) + switch root.KeySpec.(type) { + case *compile.StringSpec: + // We are already at the root, so no need to check if it is a typedef of a + // string. For simplicity, we always cast the key to a string when logging this way. + if err := g.EnsureDeclared( + ` + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$m := newVar "m"> + <$k := newVar "k"> + <$v := newVar "v"> + <$enc := newVar "enc"> + // MarshalLogObject implements zapcore.ObjectMarshaler, allowing + // fast logging of <.Name>. + func (<$m> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { + for <$k>, <$v> := range <$m> { + if err := + <$enc>.Add((string)(<$k>), ) + <- if (zapCanError .Type.ValueSpec) ->; err != nil { + return err + } + } + return nil + } + `, struct { + Name string + Type *compile.MapSpec + }{ + Name: name, + Type: root, + }, + ); err != nil { + return "", err + } + + // TODO: generate wrapper types for sets and use those here + return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil + // // return fieldValue, nil + default: + if err := g.EnsureDeclared( + ` + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$m := newVar "m"> + <$k := newVar "k"> + <$v := newVar "v"> + <$i := newVar "i"> + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$m> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { + <- if isHashable .Type.KeySpec -> + for <$k>, <$v> := range <$m> { + + for _, <$i> := range <$m> { + <$k> := <$i>.Key + <$v> := <$i>.Value + + if err := <$enc>.AppendObject(); err != nil { + return err + } + } + return nil + } + `, struct { + Name string + Type *compile.MapSpec + }{ + Name: name, + Type: root, + }, + TemplateFunc("zapMapItemMarshaler", curryGenerator(m.zapMapItemMarshaler, g)), + ); err != nil { + return "", err + } + return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil + } +} + +func (m *mapGenerator) zapMapItemMarshaler( + g Generator, + keySpec compile.TypeSpec, + keyVar string, + valueSpec compile.TypeSpec, + valueVar string, +) (string, error) { + name := fmt.Sprintf("_MapItem_%s_%s_Zapper", g.MangleType(keySpec), g.MangleType(valueSpec)) + if err := g.EnsureDeclared( + ` + type <.Name> struct { + Key + Value + } + <$zapcore := import "go.uber.org/zap/zapcore"> + <$v := newVar "v"> + <$key := printf "%s.%s" $v "Key"> + <$val := printf "%s.%s" $v "Value"> + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$v> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { + if err := + <$enc>.Add("key", ) + <- if (zapCanError .KeyType)>; err != nil { + return err + } + if err := + <$enc>.Add("value", ) + <- if (zapCanError .ValueType)>; err != nil { + return err + } + return nil + } + `, struct { + Name string + KeyType compile.TypeSpec + ValueType compile.TypeSpec + }{ + Name: name, + KeyType: keySpec, + ValueType: valueSpec, + }, + ); err != nil { + return "", err + } + return fmt.Sprintf("%v{Key: %v, Value: %v}", name, keyVar, valueVar), nil +} diff --git a/gen/set.go b/gen/set.go index fe246a73..2fadffc0 100644 --- a/gen/set.go +++ b/gen/set.go @@ -20,7 +20,11 @@ package gen -import "go.uber.org/thriftrw/compile" +import ( + "fmt" + + "go.uber.org/thriftrw/compile" +) // setGenerator generates logic to convert lists of arbitrary Thrift types to // and from ValueLists. @@ -197,3 +201,46 @@ func (s *setGenerator) Equals(g Generator, spec *compile.SetSpec) (string, error return name, wrapGenerateError(spec.ThriftName(), err) } + +func (s *setGenerator) zapMarshaler( + g Generator, + spec compile.TypeSpec, + root *compile.SetSpec, + fieldValue string, +) (string, error) { + name := zapperName(g, spec) + if err := g.EnsureDeclared( + ` + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$s := newVar "s"> + <$v := newVar "v"> + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$s> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { + <- if isHashable .Type.ValueSpec -> + for <$v> := range <$s> { + + for _, <$v> := range <$s> { + + if err := + <$enc>.Append() + <- if (zapCanError .Type.ValueSpec)>; err != nil { + return err + } + } + return nil + } + `, struct { + Name string + Type *compile.SetSpec + }{ + Name: name, + Type: root, + }, + ); err != nil { + return "", err + } + return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil +} diff --git a/gen/type.go b/gen/type.go index fa5fc2bd..61ba8697 100644 --- a/gen/type.go +++ b/gen/type.go @@ -193,6 +193,10 @@ func valueListName(g Generator, spec compile.TypeSpec) string { return fmt.Sprintf("_%s_ValueList", g.MangleType(spec)) } +func zapperName(g Generator, spec compile.TypeSpec) string { + return fmt.Sprintf("_%s_Zapper", g.MangleType(spec)) +} + // canBeConstant returns true if the given type can be a constant. func canBeConstant(t compile.TypeSpec) bool { // Only primitives can use const declarations. Everything else has to be a diff --git a/gen/zap.go b/gen/zap.go index 61dbd852..c9fbed89 100644 --- a/gen/zap.go +++ b/gen/zap.go @@ -26,27 +26,33 @@ import ( "go.uber.org/thriftrw/compile" ) -func zapEncoder(g Generator, spec compile.TypeSpec) string { +type zapGenerator struct { + mapG mapGenerator + setG setGenerator + listG listGenerator +} + +func (z *zapGenerator) zapEncoder(g Generator, spec compile.TypeSpec) string { root := compile.RootTypeSpec(spec) switch t := root.(type) { // Primitives case *compile.BoolSpec: - return ("Bool") + return "Bool" case *compile.I8Spec: - return ("Int8") + return "Int8" case *compile.I16Spec: - return ("Int16") + return "Int16" case *compile.I32Spec: - return ("Int32") + return "Int32" case *compile.I64Spec: - return ("Int64") + return "Int64" case *compile.DoubleSpec: - return ("Float64") + return "Float64" case *compile.StringSpec: - return ("String") + return "String" case *compile.BinarySpec: - return ("String") + return "String" // Containers case *compile.MapSpec: @@ -57,23 +63,18 @@ func zapEncoder(g Generator, spec compile.TypeSpec) string { default: return "Array" } - case *compile.SetSpec: - // TODO: generate wrapper types for sets and use those here - return ("Array") - case *compile.ListSpec: - return ("Array") + case *compile.SetSpec, *compile.ListSpec: + return "Array" // User-defined - case *compile.EnumSpec: - return ("Object") - case *compile.StructSpec: - return ("Object") + case *compile.EnumSpec, *compile.StructSpec: + return "Object" default: } panic(root) } -func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string, error) { +func (z *zapGenerator) zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string, error) { root := compile.RootTypeSpec(spec) if _, ok := spec.(*compile.TypedefSpec); ok { @@ -97,158 +98,11 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string base64 := g.Import("encoding/base64") return fmt.Sprintf("%v.StdEncoding.EncodeToString(%v)", base64, fieldValue), nil case *compile.MapSpec: - // TODO: use objects if the key is a string or array if not. - name := "_" + g.MangleType(spec) + "_Zapper" - switch t.KeySpec.(type) { - case *compile.StringSpec: - // t should already be the root type, so there's no need to check if it is a typedef of a - // string. For simplicity, we always cast the key to a string when logging this way. - if err := g.EnsureDeclared( - ` - type <.Name> - <$zapcore := import "go.uber.org/zap/zapcore"> - <$m := newVar "m"> - <$k := newVar "k"> - <$v := newVar "v"> - <$enc := newVar "enc"> - // MarshalLogObject implements zapcore.ObjectMarshaler, allowing - // fast logging of <.Name>. - func (<$m> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { - for <$k>, <$v> := range <$m> { - if err := - <$enc>.Add((string)(<$k>), ) - <- if (zapCanError .Type.ValueSpec) ->; err != nil { - return err - } - } - return nil - } - `, struct { - Name string - Type compile.TypeSpec - }{ - Name: name, - Type: root, - }, - ); err != nil { - return "", err - } - - // TODO: generate wrapper types for sets and use those here - return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil - // // return fieldValue, nil - default: - if err := g.EnsureDeclared( - ` - type <.Name> - <$zapcore := import "go.uber.org/zap/zapcore"> - <$m := newVar "m"> - <$k := newVar "k"> - <$v := newVar "v"> - <$i := newVar "i"> - <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing - // fast logging of <.Name>. - func (<$m> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { - <- if isHashable .Type.KeySpec -> - for <$k>, <$v> := range <$m> { - - for _, <$i> := range <$m> { - <$k> := <$i>.Key - <$v> := <$i>.Value - - if err := <$enc>.AppendObject(); err != nil { - return err - } - } - return nil - } - `, struct { - Name string - Type compile.TypeSpec - }{ - Name: name, - Type: root, - }, - ); err != nil { - return "", err - } - - // TODO: generate wrapper types for sets and use those here - return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil - } + return z.mapG.zapMarshaler(g, spec, t, fieldValue) case *compile.SetSpec: - name := "_" + g.MangleType(spec) + "_Zapper" - if err := g.EnsureDeclared( - ` - type <.Name> - <$zapcore := import "go.uber.org/zap/zapcore"> - <$s := newVar "s"> - <$v := newVar "v"> - <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing - // fast logging of <.Name>. - func (<$s> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { - <- if isHashable .Type.ValueSpec -> - for <$v> := range <$s> { - - for _, <$v> := range <$s> { - - if err := - <$enc>.Append() - <- if (zapCanError .Type.ValueSpec)>; err != nil { - return err - } - } - return nil - } - `, struct { - Name string - Type compile.TypeSpec - }{ - Name: name, - Type: root, - }, - ); err != nil { - return "", err - } - - // TODO: generate wrapper types for sets and use those here - return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil + return z.setG.zapMarshaler(g, spec, t, fieldValue) case *compile.ListSpec: - name := "_" + g.MangleType(spec) + "_Zapper" - if err := g.EnsureDeclared( - ` - type <.Name> - <$zapcore := import "go.uber.org/zap/zapcore"> - <$l := newVar "l"> - <$v := newVar "v"> - <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing - // fast logging of <.Name>. - func (<$l> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { - for _, <$v> := range <$l> { - if err := - <$enc>.Append() - <- if (zapCanError .Type.ValueSpec)>; err != nil { - return err - } - } - return nil - } - `, struct { - Name string - Type compile.TypeSpec - }{ - Name: name, - Type: root, - }, - ); err != nil { - return "", err - } - - // TODO: generate wrapper types for sets and use those here - return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil + return z.listG.zapMarshaler(g, spec, t, fieldValue) case *compile.StructSpec: return fieldValue, nil default: @@ -256,65 +110,14 @@ func zapMarshaler(g Generator, spec compile.TypeSpec, fieldValue string) (string panic(root) } -func zapMarshalerPtr(g Generator, spec compile.TypeSpec, fieldValue string) (string, error) { +func (z *zapGenerator) zapMarshalerPtr(g Generator, spec compile.TypeSpec, fieldValue string) (string, error) { if isPrimitiveType(spec) { fieldValue = "*" + fieldValue } - return zapMarshaler(g, spec, fieldValue) -} - -func zapMapItemMarshaler( - g Generator, - keySpec compile.TypeSpec, - keyVar string, - valueSpec compile.TypeSpec, - valueVar string, -) (string, error) { - name := "_MapItem_" + g.MangleType(keySpec) + "_" + g.MangleType(valueSpec) + "_Zapper" - if err := g.EnsureDeclared( - ` - type <.Name> struct { - Key - Value - } - <$zapcore := import "go.uber.org/zap/zapcore"> - <$v := newVar "v"> - <$key := printf "%s.%s" $v "Key"> - <$val := printf "%s.%s" $v "Value"> - <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing - // fast logging of <.Name>. - func (<$v> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { - if err := - <$enc>.Add("key", ) - <- if (zapCanError .KeyType)>; err != nil { - return err - } - if err := - <$enc>.Add("value", ) - <- if (zapCanError .ValueType)>; err != nil { - return err - } - return nil - } - `, struct { - Name string - KeyType compile.TypeSpec - ValueType compile.TypeSpec - }{ - Name: name, - KeyType: keySpec, - ValueType: valueSpec, - }, - ); err != nil { - return "", err - } - - // TODO: generate wrapper types for sets and use those here - return fmt.Sprintf("%v{Key: %v, Value: %v}", name, keyVar, valueVar), nil + return z.zapMarshaler(g, spec, fieldValue) } -func zapCanError(spec compile.TypeSpec) bool { +func (z *zapGenerator) zapCanError(spec compile.TypeSpec) bool { root := compile.RootTypeSpec(spec) switch root.(type) { From 169840e569a4677d0c3bffe6253e4f4552dd5eaa Mon Sep 17 00:00:00 2001 From: Minho Park Date: Wed, 1 Aug 2018 12:58:52 -0700 Subject: [PATCH 12/25] Fix template spacing --- gen/set.go | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/gen/set.go b/gen/set.go index 2fadffc0..951e3cf9 100644 --- a/gen/set.go +++ b/gen/set.go @@ -211,28 +211,28 @@ func (s *setGenerator) zapMarshaler( name := zapperName(g, spec) if err := g.EnsureDeclared( ` - type <.Name> - <$zapcore := import "go.uber.org/zap/zapcore"> - <$s := newVar "s"> - <$v := newVar "v"> - <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing - // fast logging of <.Name>. - func (<$s> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { - <- if isHashable .Type.ValueSpec -> - for <$v> := range <$s> { - - for _, <$v> := range <$s> { - - if err := - <$enc>.Append() - <- if (zapCanError .Type.ValueSpec)>; err != nil { - return err - } - } - return nil + type <.Name> + <$zapcore := import "go.uber.org/zap/zapcore"> + <$s := newVar "s"> + <$v := newVar "v"> + <$enc := newVar "enc"> + // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // fast logging of <.Name>. + func (<$s> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { + <- if isHashable .Type.ValueSpec -> + for <$v> := range <$s> { + + for _, <$v> := range <$s> { + + if err := + <$enc>.Append() + <- if (zapCanError .Type.ValueSpec)>; err != nil { + return err + } } - `, struct { + return nil + } + `, struct { Name string Type *compile.SetSpec }{ From 6406b677c78d49b19c458994e4a6fb0b67e0fdf3 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Wed, 1 Aug 2018 13:58:39 -0700 Subject: [PATCH 13/25] Fix formatting and delete useless comments --- gen/enum.go | 3 ++- gen/field.go | 14 +++++++------- gen/map.go | 3 --- gen/zap.go | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/gen/enum.go b/gen/enum.go index 844faa2a..1b8e09fb 100644 --- a/gen/enum.go +++ b/gen/enum.go @@ -127,7 +127,8 @@ func enum(g Generator, spec *compile.EnumSpec) error { <$zapcore := import "go.uber.org/zap/zapcore"> - // TODO() + // MarshalLogObject implements zapcore.ObjectMarshaler, allowing + // fast logging of <$enumName>. func (<$v> <$enumName>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { enc.AddInt32("value", int32(<$v>)) diff --git a/gen/field.go b/gen/field.go index 7967d898..75ce53e8 100644 --- a/gen/field.go +++ b/gen/field.go @@ -476,24 +476,24 @@ func (f fieldGroupGenerator) Zap(g Generator) error { // fast logging of <.Name>. func (<$v> *<.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { - <$fname := goName .> - <$fval := printf "%s.%s" $v $fname> + <- $fname := goName . -> + <- $fval := printf "%s.%s" $v $fname -> <- if .Required -> - if err := + <- if (zapCanError .Type)>if err := <$enc>.Add("<.Name>", ) <- if (zapCanError .Type)>; err != nil { return err - } + } <- else -> if <$fval> != nil { - if err := + <- if (zapCanError .Type)>if err := <$enc>.Add("<.Name>", ) <- if (zapCanError .Type)>; err != nil { return err - } + } } <- end> - + <- end> return nil } `, f) diff --git a/gen/map.go b/gen/map.go index 1c6bb27b..3c57dd05 100644 --- a/gen/map.go +++ b/gen/map.go @@ -323,10 +323,7 @@ func (m *mapGenerator) zapMarshaler( ); err != nil { return "", err } - - // TODO: generate wrapper types for sets and use those here return fmt.Sprintf("(%v)(%v)", name, fieldValue), nil - // // return fieldValue, nil default: if err := g.EnsureDeclared( ` diff --git a/gen/zap.go b/gen/zap.go index c9fbed89..0b5d257a 100644 --- a/gen/zap.go +++ b/gen/zap.go @@ -56,7 +56,6 @@ func (z *zapGenerator) zapEncoder(g Generator, spec compile.TypeSpec) string { // Containers case *compile.MapSpec: - // TODO: use objects if the key is a string or array if not. switch t.KeySpec.(type) { case *compile.StringSpec: return "Object" @@ -126,6 +125,7 @@ func (z *zapGenerator) zapCanError(spec compile.TypeSpec) bool { *compile.I64Spec, *compile.DoubleSpec, *compile.StringSpec, *compile.BinarySpec: return false + // Else case *compile.MapSpec, *compile.SetSpec, *compile.ListSpec, *compile.EnumSpec, *compile.StructSpec: return true From dc4783542b19266daffb30e0a6b46610de0a022e Mon Sep 17 00:00:00 2001 From: Minho Park Date: Wed, 1 Aug 2018 14:46:37 -0700 Subject: [PATCH 14/25] oops --- gen/field.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/field.go b/gen/field.go index 75ce53e8..afd012d2 100644 --- a/gen/field.go +++ b/gen/field.go @@ -493,7 +493,7 @@ func (f fieldGroupGenerator) Zap(g Generator) error { } } <- end> - <- end> + return nil } `, f) From e0703a3af504f10af787c6430fa34c5a9aefaa0a Mon Sep 17 00:00:00 2001 From: Minho Park Date: Wed, 1 Aug 2018 14:50:13 -0700 Subject: [PATCH 15/25] Add testdata --- envelope/internal/tests/enums/types.go | 25 ++++++---- envelope/internal/tests/exceptions/types.go | 2 - .../tests/services/cache_clearafter.go | 1 - .../services/conflictingnames_setvalue.go | 1 - .../tests/services/keyvalue_deletevalue.go | 3 -- .../tests/services/keyvalue_getmanyvalues.go | 3 -- .../tests/services/keyvalue_getvalue.go | 3 -- .../tests/services/keyvalue_setvalue.go | 2 - .../tests/services/keyvalue_setvaluev2.go | 2 - .../internal/tests/services/keyvalue_size.go | 1 - envelope/internal/tests/services/types.go | 3 -- envelope/internal/tests/structs/types.go | 48 ------------------- envelope/internal/tests/typedefs/types.go | 8 ---- envelope/internal/tests/unions/types.go | 7 --- gen/internal/tests/collision/types.go | 22 ++------- gen/internal/tests/containers/types.go | 27 ----------- gen/internal/tests/enum_conflict/types.go | 5 +- gen/internal/tests/enums/types.go | 25 ++++++---- gen/internal/tests/exceptions/types.go | 2 - .../tests/services/cache_clearafter.go | 1 - .../services/conflictingnames_setvalue.go | 1 - .../tests/services/keyvalue_deletevalue.go | 3 -- .../tests/services/keyvalue_getmanyvalues.go | 3 -- .../tests/services/keyvalue_getvalue.go | 3 -- .../tests/services/keyvalue_setvalue.go | 2 - .../tests/services/keyvalue_setvaluev2.go | 2 - gen/internal/tests/services/keyvalue_size.go | 1 - gen/internal/tests/services/types.go | 3 -- gen/internal/tests/structs/types.go | 48 ------------------- gen/internal/tests/typedefs/types.go | 8 ---- gen/internal/tests/unions/types.go | 7 --- gen/internal/tests/uuid_conflict/types.go | 2 - internal/envelope/exception/types.go | 5 +- plugin/api/plugin_handshake.go | 2 - plugin/api/servicegenerator_generate.go | 2 - plugin/api/types.go | 42 ++-------------- 36 files changed, 44 insertions(+), 281 deletions(-) diff --git a/envelope/internal/tests/enums/types.go b/envelope/internal/tests/enums/types.go index 29ed63c2..e4ed4946 100644 --- a/envelope/internal/tests/enums/types.go +++ b/envelope/internal/tests/enums/types.go @@ -55,7 +55,8 @@ func (v EmptyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EmptyEnum. func (v EmptyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) return nil @@ -207,7 +208,8 @@ func (v EnumDefault) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumDefault. func (v EnumDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -425,7 +427,8 @@ func (v EnumWithDuplicateName) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumWithDuplicateName. func (v EnumWithDuplicateName) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -635,7 +638,8 @@ func (v EnumWithDuplicateValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumWithDuplicateValues. func (v EnumWithDuplicateValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -805,7 +809,8 @@ func (v EnumWithValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumWithValues. func (v EnumWithValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -989,7 +994,8 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of RecordType. func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -1158,7 +1164,8 @@ func (v RecordTypeValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of RecordTypeValues. func (v RecordTypeValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -1397,7 +1404,6 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of StructWithOptionalEnum. func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.E != nil { if err := enc.AddObject("e", *v.E); err != nil { return err @@ -1473,7 +1479,8 @@ func (v LowerCaseEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of LowerCaseEnum. func (v LowerCaseEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { diff --git a/envelope/internal/tests/exceptions/types.go b/envelope/internal/tests/exceptions/types.go index 311de9f4..b53d4472 100644 --- a/envelope/internal/tests/exceptions/types.go +++ b/envelope/internal/tests/exceptions/types.go @@ -178,9 +178,7 @@ func (v *DoesNotExistException) Equals(rhs *DoesNotExistException) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of DoesNotExistException. func (v *DoesNotExistException) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("key", v.Key) - if v.Error2 != nil { enc.AddString("Error", *v.Error2) } diff --git a/envelope/internal/tests/services/cache_clearafter.go b/envelope/internal/tests/services/cache_clearafter.go index 27b6757a..b8524760 100644 --- a/envelope/internal/tests/services/cache_clearafter.go +++ b/envelope/internal/tests/services/cache_clearafter.go @@ -152,7 +152,6 @@ func (v *Cache_ClearAfter_Args) Equals(rhs *Cache_ClearAfter_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Cache_ClearAfter_Args. func (v *Cache_ClearAfter_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.DurationMS != nil { enc.AddInt64("durationMS", *v.DurationMS) } diff --git a/envelope/internal/tests/services/conflictingnames_setvalue.go b/envelope/internal/tests/services/conflictingnames_setvalue.go index 5658165e..efcc7127 100644 --- a/envelope/internal/tests/services/conflictingnames_setvalue.go +++ b/envelope/internal/tests/services/conflictingnames_setvalue.go @@ -146,7 +146,6 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ConflictingNames_SetValue_Args. func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Request != nil { if err := enc.AddObject("request", v.Request); err != nil { return err diff --git a/envelope/internal/tests/services/keyvalue_deletevalue.go b/envelope/internal/tests/services/keyvalue_deletevalue.go index 539976b8..54d16fa2 100644 --- a/envelope/internal/tests/services/keyvalue_deletevalue.go +++ b/envelope/internal/tests/services/keyvalue_deletevalue.go @@ -160,7 +160,6 @@ func (v *KeyValue_DeleteValue_Args) Equals(rhs *KeyValue_DeleteValue_Args) bool // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_DeleteValue_Args. func (v *KeyValue_DeleteValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Key != nil { enc.AddString("key", (string)(*v.Key)) } @@ -455,13 +454,11 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_DeleteValue_Result. func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.DoesNotExist != nil { if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { return err } } - if v.InternalError != nil { if err := enc.AddObject("internalError", v.InternalError); err != nil { return err diff --git a/envelope/internal/tests/services/keyvalue_getmanyvalues.go b/envelope/internal/tests/services/keyvalue_getmanyvalues.go index aab9ca99..3c654084 100644 --- a/envelope/internal/tests/services/keyvalue_getmanyvalues.go +++ b/envelope/internal/tests/services/keyvalue_getmanyvalues.go @@ -213,7 +213,6 @@ func (l _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_GetManyValues_Args. func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Range != nil { if err := enc.AddArray("range", (_List_Key_Zapper)(v.Range)); err != nil { return err @@ -576,13 +575,11 @@ func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_GetManyValues_Result. func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Success != nil { if err := enc.AddArray("success", (_List_ArbitraryValue_Zapper)(v.Success)); err != nil { return err } } - if v.DoesNotExist != nil { if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { return err diff --git a/envelope/internal/tests/services/keyvalue_getvalue.go b/envelope/internal/tests/services/keyvalue_getvalue.go index 34afac47..052bd64c 100644 --- a/envelope/internal/tests/services/keyvalue_getvalue.go +++ b/envelope/internal/tests/services/keyvalue_getvalue.go @@ -145,7 +145,6 @@ func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_GetValue_Args. func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Key != nil { enc.AddString("key", (string)(*v.Key)) } @@ -425,13 +424,11 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_GetValue_Result. func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Success != nil { if err := enc.AddObject("success", v.Success); err != nil { return err } } - if v.DoesNotExist != nil { if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { return err diff --git a/envelope/internal/tests/services/keyvalue_setvalue.go b/envelope/internal/tests/services/keyvalue_setvalue.go index bdb91b5a..4380491c 100644 --- a/envelope/internal/tests/services/keyvalue_setvalue.go +++ b/envelope/internal/tests/services/keyvalue_setvalue.go @@ -167,11 +167,9 @@ func (v *KeyValue_SetValue_Args) Equals(rhs *KeyValue_SetValue_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_SetValue_Args. func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Key != nil { enc.AddString("key", (string)(*v.Key)) } - if v.Value != nil { if err := enc.AddObject("value", v.Value); err != nil { return err diff --git a/envelope/internal/tests/services/keyvalue_setvaluev2.go b/envelope/internal/tests/services/keyvalue_setvaluev2.go index 15451e33..bae24940 100644 --- a/envelope/internal/tests/services/keyvalue_setvaluev2.go +++ b/envelope/internal/tests/services/keyvalue_setvaluev2.go @@ -176,9 +176,7 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_SetValueV2_Args. func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("key", (string)(v.Key)) - if err := enc.AddObject("value", v.Value); err != nil { return err } diff --git a/envelope/internal/tests/services/keyvalue_size.go b/envelope/internal/tests/services/keyvalue_size.go index 668089e5..7d788e29 100644 --- a/envelope/internal/tests/services/keyvalue_size.go +++ b/envelope/internal/tests/services/keyvalue_size.go @@ -334,7 +334,6 @@ func (v *KeyValue_Size_Result) Equals(rhs *KeyValue_Size_Result) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_Size_Result. func (v *KeyValue_Size_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Success != nil { enc.AddInt64("success", *v.Success) } diff --git a/envelope/internal/tests/services/types.go b/envelope/internal/tests/services/types.go index a5345ac8..d5e4ca6e 100644 --- a/envelope/internal/tests/services/types.go +++ b/envelope/internal/tests/services/types.go @@ -170,9 +170,7 @@ func (v *ConflictingNamesSetValueArgs) Equals(rhs *ConflictingNamesSetValueArgs) // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ConflictingNamesSetValueArgs. func (v *ConflictingNamesSetValueArgs) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("key", v.Key) - enc.AddString("value", base64.StdEncoding.EncodeToString(v.Value)) return nil @@ -305,7 +303,6 @@ func (v *InternalError) Equals(rhs *InternalError) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of InternalError. func (v *InternalError) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Message != nil { enc.AddString("message", *v.Message) } diff --git a/envelope/internal/tests/structs/types.go b/envelope/internal/tests/structs/types.go index cb45b5f0..585012ec 100644 --- a/envelope/internal/tests/structs/types.go +++ b/envelope/internal/tests/structs/types.go @@ -144,7 +144,6 @@ func (v *ContactInfo) Equals(rhs *ContactInfo) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ContactInfo. func (v *ContactInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("emailAddress", v.EmailAddress) return nil @@ -725,45 +724,37 @@ func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of DefaultsStruct. func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.RequiredPrimitive != nil { enc.AddInt32("requiredPrimitive", *v.RequiredPrimitive) } - if v.OptionalPrimitive != nil { enc.AddInt32("optionalPrimitive", *v.OptionalPrimitive) } - if v.RequiredEnum != nil { if err := enc.AddObject("requiredEnum", *v.RequiredEnum); err != nil { return err } } - if v.OptionalEnum != nil { if err := enc.AddObject("optionalEnum", *v.OptionalEnum); err != nil { return err } } - if v.RequiredList != nil { if err := enc.AddArray("requiredList", (_List_String_Zapper)(v.RequiredList)); err != nil { return err } } - if v.OptionalList != nil { if err := enc.AddArray("optionalList", (_List_Double_Zapper)(v.OptionalList)); err != nil { return err } } - if v.RequiredStruct != nil { if err := enc.AddObject("requiredStruct", v.RequiredStruct); err != nil { return err } } - if v.OptionalStruct != nil { if err := enc.AddObject("optionalStruct", v.OptionalStruct); err != nil { return err @@ -1024,11 +1015,9 @@ func (v *Edge) Equals(rhs *Edge) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Edge. func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("startPoint", v.StartPoint); err != nil { return err } - if err := enc.AddObject("endPoint", v.EndPoint); err != nil { return err } @@ -1273,11 +1262,9 @@ func (v *Frame) Equals(rhs *Frame) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Frame. func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("topLeft", v.TopLeft); err != nil { return err } - if err := enc.AddObject("size", v.Size); err != nil { return err } @@ -1544,21 +1531,15 @@ func (v *GoTags) Equals(rhs *GoTags) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of GoTags. func (v *GoTags) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("Foo", v.Foo) - if v.Bar != nil { enc.AddString("Bar", *v.Bar) } - enc.AddString("FooBar", v.FooBar) - enc.AddString("FooBarWithSpace", v.FooBarWithSpace) - if v.FooBarWithOmitEmpty != nil { enc.AddString("FooBarWithOmitEmpty", *v.FooBarWithOmitEmpty) } - enc.AddString("FooBarWithRequired", v.FooBarWithRequired) return nil @@ -1791,7 +1772,6 @@ func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Graph. func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { return err } @@ -1977,9 +1957,7 @@ func (v *Node) Equals(rhs *Node) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Node. func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddInt32("value", v.Value) - if v.Tail != nil { if err := enc.AddObject("tail", (*Node)(v.Tail)); err != nil { return err @@ -2138,9 +2116,7 @@ func (v *Omit) Equals(rhs *Omit) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Omit. func (v *Omit) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("serialized", v.Serialized) - enc.AddString("hidden", v.Hidden) return nil @@ -2290,9 +2266,7 @@ func (v *Point) Equals(rhs *Point) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Point. func (v *Point) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddFloat64("x", v.X) - enc.AddFloat64("y", v.Y) return nil @@ -2648,35 +2622,27 @@ func (v *PrimitiveOptionalStruct) Equals(rhs *PrimitiveOptionalStruct) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of PrimitiveOptionalStruct. func (v *PrimitiveOptionalStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.BoolField != nil { enc.AddBool("boolField", *v.BoolField) } - if v.ByteField != nil { enc.AddInt8("byteField", *v.ByteField) } - if v.Int16Field != nil { enc.AddInt16("int16Field", *v.Int16Field) } - if v.Int32Field != nil { enc.AddInt32("int32Field", *v.Int32Field) } - if v.Int64Field != nil { enc.AddInt64("int64Field", *v.Int64Field) } - if v.DoubleField != nil { enc.AddFloat64("doubleField", *v.DoubleField) } - if v.StringField != nil { enc.AddString("stringField", *v.StringField) } - if v.BinaryField != nil { enc.AddString("binaryField", base64.StdEncoding.EncodeToString(v.BinaryField)) } @@ -3060,21 +3026,13 @@ func (v *PrimitiveRequiredStruct) Equals(rhs *PrimitiveRequiredStruct) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of PrimitiveRequiredStruct. func (v *PrimitiveRequiredStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddBool("boolField", v.BoolField) - enc.AddInt8("byteField", v.ByteField) - enc.AddInt16("int16Field", v.Int16Field) - enc.AddInt32("int32Field", v.Int32Field) - enc.AddInt64("int64Field", v.Int64Field) - enc.AddFloat64("doubleField", v.DoubleField) - enc.AddString("stringField", v.StringField) - enc.AddString("binaryField", base64.StdEncoding.EncodeToString(v.BinaryField)) return nil @@ -3247,9 +3205,7 @@ func (v *Rename) Equals(rhs *Rename) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Rename. func (v *Rename) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("Default", v.Default) - enc.AddString("camelCase", v.CamelCase) return nil @@ -3401,9 +3357,7 @@ func (v *Size) Equals(rhs *Size) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Size. func (v *Size) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddFloat64("width", v.Width) - enc.AddFloat64("height", v.Height) return nil @@ -3556,9 +3510,7 @@ func (v *User) Equals(rhs *User) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of User. func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("name", v.Name) - if v.Contact != nil { if err := enc.AddObject("contact", v.Contact); err != nil { return err diff --git a/envelope/internal/tests/typedefs/types.go b/envelope/internal/tests/typedefs/types.go index d6f4d1a8..56ca391f 100644 --- a/envelope/internal/tests/typedefs/types.go +++ b/envelope/internal/tests/typedefs/types.go @@ -286,7 +286,6 @@ func (v *DefaultPrimitiveTypedef) Equals(rhs *DefaultPrimitiveTypedef) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of DefaultPrimitiveTypedef. func (v *DefaultPrimitiveTypedef) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.State != nil { enc.AddString("state", (string)(*v.State)) } @@ -668,11 +667,9 @@ func (v *Event) Equals(rhs *Event) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Event. func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { return err } - if v.Time != nil { enc.AddInt64("time", (int64)(*v.Time)) } @@ -1439,11 +1436,8 @@ func (v *Transition) Equals(rhs *Transition) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Transition. func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("fromState", (string)(v.FromState)) - enc.AddString("toState", (string)(v.ToState)) - if v.Events != nil { if err := enc.AddArray("events", (_EventGroup_Zapper)(([]*Event)(v.Events))); err != nil { return err @@ -1639,9 +1633,7 @@ func (v *I128) Equals(rhs *I128) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of I128. func (v *I128) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddInt64("high", v.High) - enc.AddInt64("low", v.Low) return nil diff --git a/envelope/internal/tests/unions/types.go b/envelope/internal/tests/unions/types.go index 449a7e91..d9332e87 100644 --- a/envelope/internal/tests/unions/types.go +++ b/envelope/internal/tests/unions/types.go @@ -481,25 +481,20 @@ func (m _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEn // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ArbitraryValue. func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.BoolValue != nil { enc.AddBool("boolValue", *v.BoolValue) } - if v.Int64Value != nil { enc.AddInt64("int64Value", *v.Int64Value) } - if v.StringValue != nil { enc.AddString("stringValue", *v.StringValue) } - if v.ListValue != nil { if err := enc.AddArray("listValue", (_List_ArbitraryValue_Zapper)(v.ListValue)); err != nil { return err } } - if v.MapValue != nil { if err := enc.AddObject("mapValue", (_Map_String_ArbitraryValue_Zapper)(v.MapValue)); err != nil { return err @@ -713,11 +708,9 @@ func (v *Document) Equals(rhs *Document) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Document. func (v *Document) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Pdf != nil { enc.AddString("pdf", base64.StdEncoding.EncodeToString(([]byte)(v.Pdf))) } - if v.PlainText != nil { enc.AddString("plainText", *v.PlainText) } diff --git a/gen/internal/tests/collision/types.go b/gen/internal/tests/collision/types.go index d6776ba2..e8a06e14 100644 --- a/gen/internal/tests/collision/types.go +++ b/gen/internal/tests/collision/types.go @@ -160,11 +160,9 @@ func (v *AccessorConflict) Equals(rhs *AccessorConflict) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of AccessorConflict. func (v *AccessorConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Name != nil { enc.AddString("name", *v.Name) } - if v.GetName2 != nil { enc.AddString("get_name", *v.GetName2) } @@ -327,11 +325,9 @@ func (v *AccessorNoConflict) Equals(rhs *AccessorNoConflict) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of AccessorNoConflict. func (v *AccessorNoConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Getname != nil { enc.AddString("getname", *v.Getname) } - if v.GetName != nil { enc.AddString("get_name", *v.GetName) } @@ -460,7 +456,8 @@ func (v MyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of MyEnum. func (v MyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -978,19 +975,16 @@ func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of PrimitiveContainers. func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.A != nil { if err := enc.AddArray("ListOrSetOrMap", (_List_String_Zapper)(v.A)); err != nil { return err } } - if v.B != nil { if err := enc.AddArray("List_Or_SetOrMap", (_Set_String_Zapper)(v.B)); err != nil { return err } } - if v.C != nil { if err := enc.AddObject("ListOrSet_Or_Map", (_Map_String_String_Zapper)(v.C)); err != nil { return err @@ -1165,9 +1159,7 @@ func (v *StructCollision) Equals(rhs *StructCollision) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of StructCollision. func (v *StructCollision) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddBool("collisionField", v.CollisionField) - enc.AddString("collision_field", v.CollisionField2) return nil @@ -1341,11 +1333,9 @@ func (v *UnionCollision) Equals(rhs *UnionCollision) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of UnionCollision. func (v *UnionCollision) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.CollisionField != nil { enc.AddBool("collisionField", *v.CollisionField) } - if v.CollisionField2 != nil { enc.AddString("collision_field", *v.CollisionField2) } @@ -1499,7 +1489,6 @@ func (v *WithDefault) Equals(rhs *WithDefault) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of WithDefault. func (v *WithDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Pouet != nil { if err := enc.AddObject("pouet", v.Pouet); err != nil { return err @@ -1609,7 +1598,8 @@ func (v MyEnum2) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of MyEnum2. func (v MyEnum2) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -1864,9 +1854,7 @@ func (v *StructCollision2) Equals(rhs *StructCollision2) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of StructCollision2. func (v *StructCollision2) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddBool("collisionField", v.CollisionField) - enc.AddString("collision_field", v.CollisionField2) return nil @@ -2030,11 +2018,9 @@ func (v *UnionCollision2) Equals(rhs *UnionCollision2) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of UnionCollision2. func (v *UnionCollision2) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.CollisionField != nil { enc.AddBool("collisionField", *v.CollisionField) } - if v.CollisionField2 != nil { enc.AddString("collision_field", *v.CollisionField2) } diff --git a/gen/internal/tests/containers/types.go b/gen/internal/tests/containers/types.go index e26f5e50..f93714f8 100644 --- a/gen/internal/tests/containers/types.go +++ b/gen/internal/tests/containers/types.go @@ -1952,55 +1952,46 @@ func (m _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncode // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ContainersOfContainers. func (v *ContainersOfContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.ListOfLists != nil { if err := enc.AddArray("listOfLists", (_List_List_I32_Zapper)(v.ListOfLists)); err != nil { return err } } - if v.ListOfSets != nil { if err := enc.AddArray("listOfSets", (_List_Set_I32_Zapper)(v.ListOfSets)); err != nil { return err } } - if v.ListOfMaps != nil { if err := enc.AddArray("listOfMaps", (_List_Map_I32_I32_Zapper)(v.ListOfMaps)); err != nil { return err } } - if v.SetOfSets != nil { if err := enc.AddArray("setOfSets", (_Set_Set_String_Zapper)(v.SetOfSets)); err != nil { return err } } - if v.SetOfLists != nil { if err := enc.AddArray("setOfLists", (_Set_List_String_Zapper)(v.SetOfLists)); err != nil { return err } } - if v.SetOfMaps != nil { if err := enc.AddArray("setOfMaps", (_Set_Map_String_String_Zapper)(v.SetOfMaps)); err != nil { return err } } - if v.MapOfMapToInt != nil { if err := enc.AddArray("mapOfMapToInt", (_Map_Map_String_I32_I64_Zapper)(v.MapOfMapToInt)); err != nil { return err } } - if v.MapOfListToSet != nil { if err := enc.AddArray("mapOfListToSet", (_Map_List_I32_Set_I64_Zapper)(v.MapOfListToSet)); err != nil { return err } } - if v.MapOfSetToListOfDouble != nil { if err := enc.AddArray("mapOfSetToListOfDouble", (_Map_Set_I32_List_Double_Zapper)(v.MapOfSetToListOfDouble)); err != nil { return err @@ -2534,19 +2525,16 @@ func (m _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapcore.Arr // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of EnumContainers. func (v *EnumContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.ListOfEnums != nil { if err := enc.AddArray("listOfEnums", (_List_EnumDefault_Zapper)(v.ListOfEnums)); err != nil { return err } } - if v.SetOfEnums != nil { if err := enc.AddArray("setOfEnums", (_Set_EnumWithValues_Zapper)(v.SetOfEnums)); err != nil { return err } } - if v.MapOfEnums != nil { if err := enc.AddArray("mapOfEnums", (_Map_EnumWithDuplicateValues_I32_Zapper)(v.MapOfEnums)); err != nil { return err @@ -2882,11 +2870,9 @@ func (l _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) err // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ListOfConflictingEnums. func (v *ListOfConflictingEnums) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("records", (_List_RecordType_Zapper)(v.Records)); err != nil { return err } - if err := enc.AddArray("otherRecords", (_List_RecordType_1_Zapper)(v.OtherRecords)); err != nil { return err } @@ -3199,11 +3185,9 @@ func (l _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ListOfConflictingUUIDs. func (v *ListOfConflictingUUIDs) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("uuids", (_List_UUID_Zapper)(v.Uuids)); err != nil { return err } - if err := enc.AddArray("otherUUIDs", (_List_UUID_1_Zapper)(v.OtherUUIDs)); err != nil { return err } @@ -3591,13 +3575,11 @@ func (m _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of MapOfBinaryAndString. func (v *MapOfBinaryAndString) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.BinaryToString != nil { if err := enc.AddArray("binaryToString", (_Map_Binary_String_Zapper)(v.BinaryToString)); err != nil { return err } } - if v.StringToBinary != nil { if err := enc.AddObject("stringToBinary", (_Map_String_Binary_Zapper)(v.StringToBinary)); err != nil { return err @@ -4267,37 +4249,31 @@ func (m _Map_String_Bool_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) err // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of PrimitiveContainers. func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.ListOfBinary != nil { if err := enc.AddArray("listOfBinary", (_List_Binary_Zapper)(v.ListOfBinary)); err != nil { return err } } - if v.ListOfInts != nil { if err := enc.AddArray("listOfInts", (_List_I64_Zapper)(v.ListOfInts)); err != nil { return err } } - if v.SetOfStrings != nil { if err := enc.AddArray("setOfStrings", (_Set_String_Zapper)(v.SetOfStrings)); err != nil { return err } } - if v.SetOfBytes != nil { if err := enc.AddArray("setOfBytes", (_Set_Byte_Zapper)(v.SetOfBytes)); err != nil { return err } } - if v.MapOfIntToString != nil { if err := enc.AddArray("mapOfIntToString", (_Map_I32_String_Zapper)(v.MapOfIntToString)); err != nil { return err } } - if v.MapOfStringToBool != nil { if err := enc.AddObject("mapOfStringToBool", (_Map_String_Bool_Zapper)(v.MapOfStringToBool)); err != nil { return err @@ -4641,15 +4617,12 @@ func (m _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of PrimitiveContainersRequired. func (v *PrimitiveContainersRequired) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("listOfStrings", (_List_String_Zapper)(v.ListOfStrings)); err != nil { return err } - if err := enc.AddArray("setOfInts", (_Set_I32_Zapper)(v.SetOfInts)); err != nil { return err } - if err := enc.AddArray("mapOfIntsToDoubles", (_Map_I64_Double_Zapper)(v.MapOfIntsToDoubles)); err != nil { return err } diff --git a/gen/internal/tests/enum_conflict/types.go b/gen/internal/tests/enum_conflict/types.go index 0a0c2dc0..8f2cc36e 100644 --- a/gen/internal/tests/enum_conflict/types.go +++ b/gen/internal/tests/enum_conflict/types.go @@ -64,7 +64,8 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of RecordType. func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -367,13 +368,11 @@ func (v *Records) Equals(rhs *Records) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Records. func (v *Records) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.RecordType != nil { if err := enc.AddObject("recordType", *v.RecordType); err != nil { return err } } - if v.OtherRecordType != nil { if err := enc.AddObject("otherRecordType", *v.OtherRecordType); err != nil { return err diff --git a/gen/internal/tests/enums/types.go b/gen/internal/tests/enums/types.go index 83daa024..73a87759 100644 --- a/gen/internal/tests/enums/types.go +++ b/gen/internal/tests/enums/types.go @@ -35,7 +35,8 @@ func (v EmptyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EmptyEnum. func (v EmptyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) return nil @@ -187,7 +188,8 @@ func (v EnumDefault) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumDefault. func (v EnumDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -405,7 +407,8 @@ func (v EnumWithDuplicateName) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumWithDuplicateName. func (v EnumWithDuplicateName) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -615,7 +618,8 @@ func (v EnumWithDuplicateValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumWithDuplicateValues. func (v EnumWithDuplicateValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -785,7 +789,8 @@ func (v EnumWithValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of EnumWithValues. func (v EnumWithValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -969,7 +974,8 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of RecordType. func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -1138,7 +1144,8 @@ func (v RecordTypeValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of RecordTypeValues. func (v RecordTypeValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -1377,7 +1384,6 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of StructWithOptionalEnum. func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.E != nil { if err := enc.AddObject("e", *v.E); err != nil { return err @@ -1453,7 +1459,8 @@ func (v LowerCaseEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of LowerCaseEnum. func (v LowerCaseEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { diff --git a/gen/internal/tests/exceptions/types.go b/gen/internal/tests/exceptions/types.go index 47384ca4..4991ce6f 100644 --- a/gen/internal/tests/exceptions/types.go +++ b/gen/internal/tests/exceptions/types.go @@ -158,9 +158,7 @@ func (v *DoesNotExistException) Equals(rhs *DoesNotExistException) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of DoesNotExistException. func (v *DoesNotExistException) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("key", v.Key) - if v.Error2 != nil { enc.AddString("Error", *v.Error2) } diff --git a/gen/internal/tests/services/cache_clearafter.go b/gen/internal/tests/services/cache_clearafter.go index 071f3d40..01eae563 100644 --- a/gen/internal/tests/services/cache_clearafter.go +++ b/gen/internal/tests/services/cache_clearafter.go @@ -132,7 +132,6 @@ func (v *Cache_ClearAfter_Args) Equals(rhs *Cache_ClearAfter_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Cache_ClearAfter_Args. func (v *Cache_ClearAfter_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.DurationMS != nil { enc.AddInt64("durationMS", *v.DurationMS) } diff --git a/gen/internal/tests/services/conflictingnames_setvalue.go b/gen/internal/tests/services/conflictingnames_setvalue.go index 81e9a13f..e4ae7dd6 100644 --- a/gen/internal/tests/services/conflictingnames_setvalue.go +++ b/gen/internal/tests/services/conflictingnames_setvalue.go @@ -126,7 +126,6 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ConflictingNames_SetValue_Args. func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Request != nil { if err := enc.AddObject("request", v.Request); err != nil { return err diff --git a/gen/internal/tests/services/keyvalue_deletevalue.go b/gen/internal/tests/services/keyvalue_deletevalue.go index 918f6b5a..babd4c0d 100644 --- a/gen/internal/tests/services/keyvalue_deletevalue.go +++ b/gen/internal/tests/services/keyvalue_deletevalue.go @@ -140,7 +140,6 @@ func (v *KeyValue_DeleteValue_Args) Equals(rhs *KeyValue_DeleteValue_Args) bool // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_DeleteValue_Args. func (v *KeyValue_DeleteValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Key != nil { enc.AddString("key", (string)(*v.Key)) } @@ -435,13 +434,11 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_DeleteValue_Result. func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.DoesNotExist != nil { if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { return err } } - if v.InternalError != nil { if err := enc.AddObject("internalError", v.InternalError); err != nil { return err diff --git a/gen/internal/tests/services/keyvalue_getmanyvalues.go b/gen/internal/tests/services/keyvalue_getmanyvalues.go index 90d11c29..18bed748 100644 --- a/gen/internal/tests/services/keyvalue_getmanyvalues.go +++ b/gen/internal/tests/services/keyvalue_getmanyvalues.go @@ -193,7 +193,6 @@ func (l _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_GetManyValues_Args. func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Range != nil { if err := enc.AddArray("range", (_List_Key_Zapper)(v.Range)); err != nil { return err @@ -556,13 +555,11 @@ func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_GetManyValues_Result. func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Success != nil { if err := enc.AddArray("success", (_List_ArbitraryValue_Zapper)(v.Success)); err != nil { return err } } - if v.DoesNotExist != nil { if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { return err diff --git a/gen/internal/tests/services/keyvalue_getvalue.go b/gen/internal/tests/services/keyvalue_getvalue.go index 252c11fd..83d70757 100644 --- a/gen/internal/tests/services/keyvalue_getvalue.go +++ b/gen/internal/tests/services/keyvalue_getvalue.go @@ -125,7 +125,6 @@ func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_GetValue_Args. func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Key != nil { enc.AddString("key", (string)(*v.Key)) } @@ -405,13 +404,11 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_GetValue_Result. func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Success != nil { if err := enc.AddObject("success", v.Success); err != nil { return err } } - if v.DoesNotExist != nil { if err := enc.AddObject("doesNotExist", v.DoesNotExist); err != nil { return err diff --git a/gen/internal/tests/services/keyvalue_setvalue.go b/gen/internal/tests/services/keyvalue_setvalue.go index 5db74323..36923cc5 100644 --- a/gen/internal/tests/services/keyvalue_setvalue.go +++ b/gen/internal/tests/services/keyvalue_setvalue.go @@ -147,11 +147,9 @@ func (v *KeyValue_SetValue_Args) Equals(rhs *KeyValue_SetValue_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_SetValue_Args. func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Key != nil { enc.AddString("key", (string)(*v.Key)) } - if v.Value != nil { if err := enc.AddObject("value", v.Value); err != nil { return err diff --git a/gen/internal/tests/services/keyvalue_setvaluev2.go b/gen/internal/tests/services/keyvalue_setvaluev2.go index 4559b43b..4ab582b2 100644 --- a/gen/internal/tests/services/keyvalue_setvaluev2.go +++ b/gen/internal/tests/services/keyvalue_setvaluev2.go @@ -156,9 +156,7 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_SetValueV2_Args. func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("key", (string)(v.Key)) - if err := enc.AddObject("value", v.Value); err != nil { return err } diff --git a/gen/internal/tests/services/keyvalue_size.go b/gen/internal/tests/services/keyvalue_size.go index 4f2e232a..318dc33b 100644 --- a/gen/internal/tests/services/keyvalue_size.go +++ b/gen/internal/tests/services/keyvalue_size.go @@ -314,7 +314,6 @@ func (v *KeyValue_Size_Result) Equals(rhs *KeyValue_Size_Result) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of KeyValue_Size_Result. func (v *KeyValue_Size_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Success != nil { enc.AddInt64("success", *v.Success) } diff --git a/gen/internal/tests/services/types.go b/gen/internal/tests/services/types.go index 720ef3dc..0684e29a 100644 --- a/gen/internal/tests/services/types.go +++ b/gen/internal/tests/services/types.go @@ -150,9 +150,7 @@ func (v *ConflictingNamesSetValueArgs) Equals(rhs *ConflictingNamesSetValueArgs) // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ConflictingNamesSetValueArgs. func (v *ConflictingNamesSetValueArgs) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("key", v.Key) - enc.AddString("value", base64.StdEncoding.EncodeToString(v.Value)) return nil @@ -285,7 +283,6 @@ func (v *InternalError) Equals(rhs *InternalError) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of InternalError. func (v *InternalError) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Message != nil { enc.AddString("message", *v.Message) } diff --git a/gen/internal/tests/structs/types.go b/gen/internal/tests/structs/types.go index 4040c2a5..f2d9112a 100644 --- a/gen/internal/tests/structs/types.go +++ b/gen/internal/tests/structs/types.go @@ -124,7 +124,6 @@ func (v *ContactInfo) Equals(rhs *ContactInfo) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ContactInfo. func (v *ContactInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("emailAddress", v.EmailAddress) return nil @@ -705,45 +704,37 @@ func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of DefaultsStruct. func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.RequiredPrimitive != nil { enc.AddInt32("requiredPrimitive", *v.RequiredPrimitive) } - if v.OptionalPrimitive != nil { enc.AddInt32("optionalPrimitive", *v.OptionalPrimitive) } - if v.RequiredEnum != nil { if err := enc.AddObject("requiredEnum", *v.RequiredEnum); err != nil { return err } } - if v.OptionalEnum != nil { if err := enc.AddObject("optionalEnum", *v.OptionalEnum); err != nil { return err } } - if v.RequiredList != nil { if err := enc.AddArray("requiredList", (_List_String_Zapper)(v.RequiredList)); err != nil { return err } } - if v.OptionalList != nil { if err := enc.AddArray("optionalList", (_List_Double_Zapper)(v.OptionalList)); err != nil { return err } } - if v.RequiredStruct != nil { if err := enc.AddObject("requiredStruct", v.RequiredStruct); err != nil { return err } } - if v.OptionalStruct != nil { if err := enc.AddObject("optionalStruct", v.OptionalStruct); err != nil { return err @@ -1004,11 +995,9 @@ func (v *Edge) Equals(rhs *Edge) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Edge. func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("startPoint", v.StartPoint); err != nil { return err } - if err := enc.AddObject("endPoint", v.EndPoint); err != nil { return err } @@ -1253,11 +1242,9 @@ func (v *Frame) Equals(rhs *Frame) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Frame. func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("topLeft", v.TopLeft); err != nil { return err } - if err := enc.AddObject("size", v.Size); err != nil { return err } @@ -1524,21 +1511,15 @@ func (v *GoTags) Equals(rhs *GoTags) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of GoTags. func (v *GoTags) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("Foo", v.Foo) - if v.Bar != nil { enc.AddString("Bar", *v.Bar) } - enc.AddString("FooBar", v.FooBar) - enc.AddString("FooBarWithSpace", v.FooBarWithSpace) - if v.FooBarWithOmitEmpty != nil { enc.AddString("FooBarWithOmitEmpty", *v.FooBarWithOmitEmpty) } - enc.AddString("FooBarWithRequired", v.FooBarWithRequired) return nil @@ -1771,7 +1752,6 @@ func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Graph. func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { return err } @@ -1957,9 +1937,7 @@ func (v *Node) Equals(rhs *Node) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Node. func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddInt32("value", v.Value) - if v.Tail != nil { if err := enc.AddObject("tail", (*Node)(v.Tail)); err != nil { return err @@ -2118,9 +2096,7 @@ func (v *Omit) Equals(rhs *Omit) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Omit. func (v *Omit) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("serialized", v.Serialized) - enc.AddString("hidden", v.Hidden) return nil @@ -2270,9 +2246,7 @@ func (v *Point) Equals(rhs *Point) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Point. func (v *Point) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddFloat64("x", v.X) - enc.AddFloat64("y", v.Y) return nil @@ -2628,35 +2602,27 @@ func (v *PrimitiveOptionalStruct) Equals(rhs *PrimitiveOptionalStruct) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of PrimitiveOptionalStruct. func (v *PrimitiveOptionalStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.BoolField != nil { enc.AddBool("boolField", *v.BoolField) } - if v.ByteField != nil { enc.AddInt8("byteField", *v.ByteField) } - if v.Int16Field != nil { enc.AddInt16("int16Field", *v.Int16Field) } - if v.Int32Field != nil { enc.AddInt32("int32Field", *v.Int32Field) } - if v.Int64Field != nil { enc.AddInt64("int64Field", *v.Int64Field) } - if v.DoubleField != nil { enc.AddFloat64("doubleField", *v.DoubleField) } - if v.StringField != nil { enc.AddString("stringField", *v.StringField) } - if v.BinaryField != nil { enc.AddString("binaryField", base64.StdEncoding.EncodeToString(v.BinaryField)) } @@ -3040,21 +3006,13 @@ func (v *PrimitiveRequiredStruct) Equals(rhs *PrimitiveRequiredStruct) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of PrimitiveRequiredStruct. func (v *PrimitiveRequiredStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddBool("boolField", v.BoolField) - enc.AddInt8("byteField", v.ByteField) - enc.AddInt16("int16Field", v.Int16Field) - enc.AddInt32("int32Field", v.Int32Field) - enc.AddInt64("int64Field", v.Int64Field) - enc.AddFloat64("doubleField", v.DoubleField) - enc.AddString("stringField", v.StringField) - enc.AddString("binaryField", base64.StdEncoding.EncodeToString(v.BinaryField)) return nil @@ -3227,9 +3185,7 @@ func (v *Rename) Equals(rhs *Rename) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Rename. func (v *Rename) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("Default", v.Default) - enc.AddString("camelCase", v.CamelCase) return nil @@ -3381,9 +3337,7 @@ func (v *Size) Equals(rhs *Size) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Size. func (v *Size) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddFloat64("width", v.Width) - enc.AddFloat64("height", v.Height) return nil @@ -3536,9 +3490,7 @@ func (v *User) Equals(rhs *User) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of User. func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("name", v.Name) - if v.Contact != nil { if err := enc.AddObject("contact", v.Contact); err != nil { return err diff --git a/gen/internal/tests/typedefs/types.go b/gen/internal/tests/typedefs/types.go index 1ef45b10..0538527e 100644 --- a/gen/internal/tests/typedefs/types.go +++ b/gen/internal/tests/typedefs/types.go @@ -266,7 +266,6 @@ func (v *DefaultPrimitiveTypedef) Equals(rhs *DefaultPrimitiveTypedef) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of DefaultPrimitiveTypedef. func (v *DefaultPrimitiveTypedef) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.State != nil { enc.AddString("state", (string)(*v.State)) } @@ -648,11 +647,9 @@ func (v *Event) Equals(rhs *Event) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Event. func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { return err } - if v.Time != nil { enc.AddInt64("time", (int64)(*v.Time)) } @@ -1419,11 +1416,8 @@ func (v *Transition) Equals(rhs *Transition) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Transition. func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("fromState", (string)(v.FromState)) - enc.AddString("toState", (string)(v.ToState)) - if v.Events != nil { if err := enc.AddArray("events", (_EventGroup_Zapper)(([]*Event)(v.Events))); err != nil { return err @@ -1619,9 +1613,7 @@ func (v *I128) Equals(rhs *I128) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of I128. func (v *I128) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddInt64("high", v.High) - enc.AddInt64("low", v.Low) return nil diff --git a/gen/internal/tests/unions/types.go b/gen/internal/tests/unions/types.go index 90b85c24..0a56edbd 100644 --- a/gen/internal/tests/unions/types.go +++ b/gen/internal/tests/unions/types.go @@ -461,25 +461,20 @@ func (m _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEn // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ArbitraryValue. func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.BoolValue != nil { enc.AddBool("boolValue", *v.BoolValue) } - if v.Int64Value != nil { enc.AddInt64("int64Value", *v.Int64Value) } - if v.StringValue != nil { enc.AddString("stringValue", *v.StringValue) } - if v.ListValue != nil { if err := enc.AddArray("listValue", (_List_ArbitraryValue_Zapper)(v.ListValue)); err != nil { return err } } - if v.MapValue != nil { if err := enc.AddObject("mapValue", (_Map_String_ArbitraryValue_Zapper)(v.MapValue)); err != nil { return err @@ -693,11 +688,9 @@ func (v *Document) Equals(rhs *Document) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Document. func (v *Document) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Pdf != nil { enc.AddString("pdf", base64.StdEncoding.EncodeToString(([]byte)(v.Pdf))) } - if v.PlainText != nil { enc.AddString("plainText", *v.PlainText) } diff --git a/gen/internal/tests/uuid_conflict/types.go b/gen/internal/tests/uuid_conflict/types.go index 4eac67b2..37d5067c 100644 --- a/gen/internal/tests/uuid_conflict/types.go +++ b/gen/internal/tests/uuid_conflict/types.go @@ -192,9 +192,7 @@ func (v *UUIDConflict) Equals(rhs *UUIDConflict) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of UUIDConflict. func (v *UUIDConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("localUUID", (string)(v.LocalUUID)) - if err := enc.AddObject("importedUUID", (*typedefs.I128)(v.ImportedUUID)); err != nil { return err } diff --git a/internal/envelope/exception/types.go b/internal/envelope/exception/types.go index dcbf1d92..c407dc2a 100644 --- a/internal/envelope/exception/types.go +++ b/internal/envelope/exception/types.go @@ -146,7 +146,8 @@ func (v ExceptionType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of ExceptionType. func (v ExceptionType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -475,11 +476,9 @@ func (v *TApplicationException) Equals(rhs *TApplicationException) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of TApplicationException. func (v *TApplicationException) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Message != nil { enc.AddString("message", *v.Message) } - if v.Type != nil { if err := enc.AddObject("type", *v.Type); err != nil { return err diff --git a/plugin/api/plugin_handshake.go b/plugin/api/plugin_handshake.go index 8bda939c..ac7b0966 100644 --- a/plugin/api/plugin_handshake.go +++ b/plugin/api/plugin_handshake.go @@ -147,7 +147,6 @@ func (v *Plugin_Handshake_Args) Equals(rhs *Plugin_Handshake_Args) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Plugin_Handshake_Args. func (v *Plugin_Handshake_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Request != nil { if err := enc.AddObject("request", v.Request); err != nil { return err @@ -394,7 +393,6 @@ func (v *Plugin_Handshake_Result) Equals(rhs *Plugin_Handshake_Result) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Plugin_Handshake_Result. func (v *Plugin_Handshake_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Success != nil { if err := enc.AddObject("success", v.Success); err != nil { return err diff --git a/plugin/api/servicegenerator_generate.go b/plugin/api/servicegenerator_generate.go index d231546e..4bb9bd1d 100644 --- a/plugin/api/servicegenerator_generate.go +++ b/plugin/api/servicegenerator_generate.go @@ -147,7 +147,6 @@ func (v *ServiceGenerator_Generate_Args) Equals(rhs *ServiceGenerator_Generate_A // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ServiceGenerator_Generate_Args. func (v *ServiceGenerator_Generate_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Request != nil { if err := enc.AddObject("request", v.Request); err != nil { return err @@ -394,7 +393,6 @@ func (v *ServiceGenerator_Generate_Result) Equals(rhs *ServiceGenerator_Generate // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of ServiceGenerator_Generate_Result. func (v *ServiceGenerator_Generate_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Success != nil { if err := enc.AddObject("success", v.Success); err != nil { return err diff --git a/plugin/api/types.go b/plugin/api/types.go index 1c36f51b..72d8428d 100644 --- a/plugin/api/types.go +++ b/plugin/api/types.go @@ -192,9 +192,7 @@ func (v *Argument) Equals(rhs *Argument) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Argument. func (v *Argument) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("name", v.Name) - if err := enc.AddObject("type", v.Type); err != nil { return err } @@ -258,7 +256,8 @@ func (v Feature) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of Feature. func (v Feature) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -834,31 +833,24 @@ func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Function. func (v *Function) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("name", v.Name) - enc.AddString("thriftName", v.ThriftName) - if err := enc.AddArray("arguments", (_List_Argument_Zapper)(v.Arguments)); err != nil { return err } - if v.ReturnType != nil { if err := enc.AddObject("returnType", v.ReturnType); err != nil { return err } } - if v.Exceptions != nil { if err := enc.AddArray("exceptions", (_List_Argument_Zapper)(v.Exceptions)); err != nil { return err } } - if v.OneWay != nil { enc.AddBool("oneWay", *v.OneWay) } - if v.Annotations != nil { if err := enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)); err != nil { return err @@ -1420,15 +1412,12 @@ func (m _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of GenerateServiceRequest. func (v *GenerateServiceRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("rootServices", (_List_ServiceID_Zapper)(v.RootServices)); err != nil { return err } - if err := enc.AddArray("services", (_Map_ServiceID_Service_Zapper)(v.Services)); err != nil { return err } - if err := enc.AddArray("modules", (_Map_ModuleID_Module_Zapper)(v.Modules)); err != nil { return err } @@ -1657,7 +1646,6 @@ func (m _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of GenerateServiceResponse. func (v *GenerateServiceResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.Files != nil { if err := enc.AddObject("files", (_Map_String_Binary_Zapper)(v.Files)); err != nil { return err @@ -2050,15 +2038,11 @@ func (l _List_Feature_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of HandshakeResponse. func (v *HandshakeResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("name", v.Name) - enc.AddInt32("apiVersion", v.APIVersion) - if err := enc.AddArray("features", (_List_Feature_Zapper)(v.Features)); err != nil { return err } - if v.LibraryVersion != nil { enc.AddString("libraryVersion", *v.LibraryVersion) } @@ -2232,9 +2216,7 @@ func (v *Module) Equals(rhs *Module) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Module. func (v *Module) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("importPath", v.ImportPath) - enc.AddString("directory", v.Directory) return nil @@ -2630,21 +2612,15 @@ func (l _List_Function_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Service. func (v *Service) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("name", v.Name) - enc.AddString("thriftName", v.ThriftName) - if v.ParentID != nil { enc.AddInt32("parentID", (int32)(*v.ParentID)) } - if err := enc.AddArray("functions", (_List_Function_Zapper)(v.Functions)); err != nil { return err } - enc.AddInt32("moduleID", (int32)(v.ModuleID)) - if v.Annotations != nil { if err := enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)); err != nil { return err @@ -2822,7 +2798,8 @@ func (v SimpleType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// TODO() +// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// fast logging of SimpleType. func (v SimpleType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) switch int32(v) { @@ -3274,37 +3251,31 @@ func (v *Type) Equals(rhs *Type) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of Type. func (v *Type) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if v.SimpleType != nil { if err := enc.AddObject("simpleType", *v.SimpleType); err != nil { return err } } - if v.SliceType != nil { if err := enc.AddObject("sliceType", v.SliceType); err != nil { return err } } - if v.KeyValueSliceType != nil { if err := enc.AddObject("keyValueSliceType", v.KeyValueSliceType); err != nil { return err } } - if v.MapType != nil { if err := enc.AddObject("mapType", v.MapType); err != nil { return err } } - if v.ReferenceType != nil { if err := enc.AddObject("referenceType", v.ReferenceType); err != nil { return err } } - if v.PointerType != nil { if err := enc.AddObject("pointerType", v.PointerType); err != nil { return err @@ -3515,11 +3486,9 @@ func (v *TypePair) Equals(rhs *TypePair) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of TypePair. func (v *TypePair) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("left", v.Left); err != nil { return err } - if err := enc.AddObject("right", v.Right); err != nil { return err } @@ -3714,11 +3683,8 @@ func (v *TypeReference) Equals(rhs *TypeReference) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, allowing // fast logging of TypeReference. func (v *TypeReference) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("name", v.Name) - enc.AddString("importPath", v.ImportPath) - if v.Annotations != nil { if err := enc.AddObject("annotations", (_Map_String_String_Zapper)(v.Annotations)); err != nil { return err From ac7fb4be506d9d020d3e290c6fce4fca05214694 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Thu, 2 Aug 2018 11:35:55 -0700 Subject: [PATCH 16/25] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a3d0e85..90fa5628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] -- No changes yet. +- All structs and its underlying components, enums, and typedefs of non-primitives + now implement `zapcore.ObjectMarshaler` or `zapcore.ArrayMarshaler`, depending + on its underlying type. ## [1.12.0] - 2018-06-25 ### Added From a3a379fb77404dd5313215f6bbf20b59f38f13ba Mon Sep 17 00:00:00 2001 From: Minho Park Date: Thu, 2 Aug 2018 15:21:01 -0700 Subject: [PATCH 17/25] WIP --- CHANGELOG.md | 2 +- gen/enum.go | 2 +- gen/field.go | 22 +++++++++++++--------- gen/list.go | 2 +- gen/map.go | 6 +++--- gen/set.go | 2 +- gen/zap.go | 5 +---- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90fa5628..5510e71d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] - All structs and its underlying components, enums, and typedefs of non-primitives now implement `zapcore.ObjectMarshaler` or `zapcore.ArrayMarshaler`, depending - on its underlying type. + on its underlying type. For typedefs of primitives, the logging is up to the user, simply by casting it down to the root type and using the respective Add/Append... method of the Zap encoder. ## [1.12.0] - 2018-06-25 ### Added diff --git a/gen/enum.go b/gen/enum.go index 1b8e09fb..03470d60 100644 --- a/gen/enum.go +++ b/gen/enum.go @@ -127,7 +127,7 @@ func enum(g Generator, spec *compile.EnumSpec) error { <$zapcore := import "go.uber.org/zap/zapcore"> - // MarshalLogObject implements zapcore.ObjectMarshaler, allowing + // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of <$enumName>. func (<$v> <$enumName>) MarshalLogObject(enc <$zapcore>.ObjectEncoder) error { enc.AddInt32("value", int32(<$v>)) diff --git a/gen/field.go b/gen/field.go index afd012d2..67b87c32 100644 --- a/gen/field.go +++ b/gen/field.go @@ -472,25 +472,29 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <$v := newVar "v"> <$enc := newVar "enc"> - // MarshalLogObject implements zapcore.ObjectMarshaler, allowing + // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of <.Name>. func (<$v> *<.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { <- $fname := goName . -> <- $fval := printf "%s.%s" $v $fname -> <- if .Required -> - <- if (zapCanError .Type)>if err := - <$enc>.Add("<.Name>", ) - <- if (zapCanError .Type)>; err != nil { + <- if (zapCanError .Type)> + if err := <$enc>.Add("<.Name>", ); err != nil { return err - } + } + <- else -> + <$enc>.Add("<.Name>", ) + <- end -> <- else -> if <$fval> != nil { - <- if (zapCanError .Type)>if err := - <$enc>.Add("<.Name>", ) - <- if (zapCanError .Type)>; err != nil { + <- if (zapCanError .Type)> + if err := <$enc>.Add("<.Name>", ); err != nil { return err - } + } + <- else -> + <$enc>.Add("<.Name>", ) + <- end -> } <- end> diff --git a/gen/list.go b/gen/list.go index 1c10fa27..8bca2d2c 100644 --- a/gen/list.go +++ b/gen/list.go @@ -196,7 +196,7 @@ func (l *listGenerator) zapMarshaler( <$l := newVar "l"> <$v := newVar "v"> <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$l> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { for _, <$v> := range <$l> { diff --git a/gen/map.go b/gen/map.go index 3c57dd05..3f286727 100644 --- a/gen/map.go +++ b/gen/map.go @@ -301,7 +301,7 @@ func (m *mapGenerator) zapMarshaler( <$k := newVar "k"> <$v := newVar "v"> <$enc := newVar "enc"> - // MarshalLogObject implements zapcore.ObjectMarshaler, allowing + // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of <.Name>. func (<$m> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { for <$k>, <$v> := range <$m> { @@ -334,7 +334,7 @@ func (m *mapGenerator) zapMarshaler( <$v := newVar "v"> <$i := newVar "i"> <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$m> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { <- if isHashable .Type.KeySpec -> @@ -384,7 +384,7 @@ func (m *mapGenerator) zapMapItemMarshaler( <$key := printf "%s.%s" $v "Key"> <$val := printf "%s.%s" $v "Value"> <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$v> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { if err := diff --git a/gen/set.go b/gen/set.go index 951e3cf9..9cac89b6 100644 --- a/gen/set.go +++ b/gen/set.go @@ -216,7 +216,7 @@ func (s *setGenerator) zapMarshaler( <$s := newVar "s"> <$v := newVar "v"> <$enc := newVar "enc"> - // MarshalLogArray implements zapcore.ArrayMarshaler, allowing + // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$s> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { <- if isHashable .Type.ValueSpec -> diff --git a/gen/zap.go b/gen/zap.go index 0b5d257a..68522118 100644 --- a/gen/zap.go +++ b/gen/zap.go @@ -68,7 +68,6 @@ func (z *zapGenerator) zapEncoder(g Generator, spec compile.TypeSpec) string { // User-defined case *compile.EnumSpec, *compile.StructSpec: return "Object" - default: } panic(root) } @@ -104,7 +103,6 @@ func (z *zapGenerator) zapMarshaler(g Generator, spec compile.TypeSpec, fieldVal return z.listG.zapMarshaler(g, spec, t, fieldValue) case *compile.StructSpec: return fieldValue, nil - default: } panic(root) } @@ -125,11 +123,10 @@ func (z *zapGenerator) zapCanError(spec compile.TypeSpec) bool { *compile.I64Spec, *compile.DoubleSpec, *compile.StringSpec, *compile.BinarySpec: return false - // Else + // Non-primitives case *compile.MapSpec, *compile.SetSpec, *compile.ListSpec, *compile.EnumSpec, *compile.StructSpec: return true - default: } panic(root) } From 323ec36e49318070859ed11e0031fca3763a8fad Mon Sep 17 00:00:00 2001 From: Minho Park Date: Thu, 2 Aug 2018 15:51:38 -0700 Subject: [PATCH 18/25] code review --- gen/field.go | 16 ++++++++-------- gen/list.go | 10 ++++++---- gen/map.go | 32 +++++++++++++++++++------------- gen/set.go | 10 ++++++---- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/gen/field.go b/gen/field.go index 67b87c32..92f7b23f 100644 --- a/gen/field.go +++ b/gen/field.go @@ -480,20 +480,20 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <- $fval := printf "%s.%s" $v $fname -> <- if .Required -> <- if (zapCanError .Type)> - if err := <$enc>.Add("<.Name>", ); err != nil { - return err - } + if err := <$enc>.Add("<.Name>", ); err != nil { + return err + } <- else -> - <$enc>.Add("<.Name>", ) + <$enc>.Add("<.Name>", ) <- end -> <- else -> if <$fval> != nil { <- if (zapCanError .Type)> - if err := <$enc>.Add("<.Name>", ); err != nil { - return err - } + if err := <$enc>.Add("<.Name>", ); err != nil { + return err + } <- else -> - <$enc>.Add("<.Name>", ) + <$enc>.Add("<.Name>", ) <- end -> } <- end> diff --git a/gen/list.go b/gen/list.go index 8bca2d2c..36e06dd4 100644 --- a/gen/list.go +++ b/gen/list.go @@ -200,11 +200,13 @@ func (l *listGenerator) zapMarshaler( // fast logging of <.Name>. func (<$l> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { for _, <$v> := range <$l> { - if err := + + if err := <$enc>.Append(); err != nil { + return err + } + <- else -> <$enc>.Append() - <- if (zapCanError .Type.ValueSpec)>; err != nil { - return err - } + <- end> } return nil } diff --git a/gen/map.go b/gen/map.go index 3f286727..48aa1174 100644 --- a/gen/map.go +++ b/gen/map.go @@ -305,11 +305,13 @@ func (m *mapGenerator) zapMarshaler( // fast logging of <.Name>. func (<$m> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { for <$k>, <$v> := range <$m> { - if err := - <$enc>.Add((string)(<$k>), ) - <- if (zapCanError .Type.ValueSpec) ->; err != nil { + + if err := <$enc>.Add((string)(<$k>), ); err != nil { return err - } + } + <- else -> + <$enc>.Add((string)(<$k>), ) + <- end> } return nil } @@ -387,16 +389,20 @@ func (m *mapGenerator) zapMapItemMarshaler( // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$v> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { - if err := - <$enc>.Add("key", ) - <- if (zapCanError .KeyType)>; err != nil { + + if err := <$enc>.Add("key", ); err != nil { + return err + } + <- else -> + <$enc>.Add("key", ) + <- end> + + if err := <$enc>.Add("value", ); err != nil { return err - } - if err := - <$enc>.Add("value", ) - <- if (zapCanError .ValueType)>; err != nil { - return err - } + } + <- else -> + <$enc>.Add("value", ) + <- end> return nil } `, struct { diff --git a/gen/set.go b/gen/set.go index 9cac89b6..1eed3970 100644 --- a/gen/set.go +++ b/gen/set.go @@ -224,11 +224,13 @@ func (s *setGenerator) zapMarshaler( for _, <$v> := range <$s> { - if err := + + if err := <$enc>.Append(); err != nil { + return err + } + <- else -> <$enc>.Append() - <- if (zapCanError .Type.ValueSpec)>; err != nil { - return err - } + <- end> } return nil } From 95c440c9a1fa9dad809bf4ac0a09da3323cd1ea2 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Thu, 2 Aug 2018 16:04:46 -0700 Subject: [PATCH 19/25] Add testdata --- envelope/internal/tests/enums/types.go | 18 +-- envelope/internal/tests/exceptions/types.go | 4 +- .../internal/tests/services/cache_clear.go | 2 +- .../tests/services/cache_clearafter.go | 2 +- .../services/conflictingnames_setvalue.go | 4 +- .../tests/services/keyvalue_deletevalue.go | 4 +- .../tests/services/keyvalue_getmanyvalues.go | 8 +- .../tests/services/keyvalue_getvalue.go | 4 +- .../tests/services/keyvalue_setvalue.go | 4 +- .../tests/services/keyvalue_setvaluev2.go | 5 +- .../internal/tests/services/keyvalue_size.go | 4 +- ...service_name_non_standard_function_name.go | 4 +- envelope/internal/tests/services/types.go | 4 +- envelope/internal/tests/structs/types.go | 41 ++++--- envelope/internal/tests/typedefs/types.go | 23 ++-- envelope/internal/tests/unions/types.go | 10 +- gen/internal/tests/collision/types.go | 26 ++--- gen/internal/tests/containers/types.go | 103 ++++++++++-------- gen/internal/tests/enum_conflict/types.go | 4 +- gen/internal/tests/enums/types.go | 18 +-- gen/internal/tests/exceptions/types.go | 4 +- gen/internal/tests/services/cache_clear.go | 2 +- .../tests/services/cache_clearafter.go | 2 +- .../services/conflictingnames_setvalue.go | 4 +- .../tests/services/keyvalue_deletevalue.go | 4 +- .../tests/services/keyvalue_getmanyvalues.go | 8 +- .../tests/services/keyvalue_getvalue.go | 4 +- .../tests/services/keyvalue_setvalue.go | 4 +- .../tests/services/keyvalue_setvaluev2.go | 5 +- gen/internal/tests/services/keyvalue_size.go | 4 +- ...service_name_non_standard_function_name.go | 4 +- gen/internal/tests/services/types.go | 4 +- gen/internal/tests/structs/types.go | 41 ++++--- gen/internal/tests/typedefs/types.go | 23 ++-- gen/internal/tests/unions/types.go | 10 +- gen/internal/tests/uuid_conflict/types.go | 3 +- internal/envelope/exception/types.go | 4 +- plugin/api/plugin_goodbye.go | 4 +- plugin/api/plugin_handshake.go | 4 +- plugin/api/servicegenerator_generate.go | 4 +- plugin/api/types.go | 55 ++++++---- 41 files changed, 260 insertions(+), 229 deletions(-) diff --git a/envelope/internal/tests/enums/types.go b/envelope/internal/tests/enums/types.go index e4ed4946..a83648a6 100644 --- a/envelope/internal/tests/enums/types.go +++ b/envelope/internal/tests/enums/types.go @@ -55,7 +55,7 @@ func (v EmptyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EmptyEnum. func (v EmptyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -208,7 +208,7 @@ func (v EnumDefault) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumDefault. func (v EnumDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -427,7 +427,7 @@ func (v EnumWithDuplicateName) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumWithDuplicateName. func (v EnumWithDuplicateName) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -638,7 +638,7 @@ func (v EnumWithDuplicateValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumWithDuplicateValues. func (v EnumWithDuplicateValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -809,7 +809,7 @@ func (v EnumWithValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumWithValues. func (v EnumWithValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -994,7 +994,7 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of RecordType. func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -1164,7 +1164,7 @@ func (v RecordTypeValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of RecordTypeValues. func (v RecordTypeValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -1401,7 +1401,7 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of StructWithOptionalEnum. func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.E != nil { @@ -1479,7 +1479,7 @@ func (v LowerCaseEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of LowerCaseEnum. func (v LowerCaseEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) diff --git a/envelope/internal/tests/exceptions/types.go b/envelope/internal/tests/exceptions/types.go index b53d4472..68367d58 100644 --- a/envelope/internal/tests/exceptions/types.go +++ b/envelope/internal/tests/exceptions/types.go @@ -175,7 +175,7 @@ func (v *DoesNotExistException) Equals(rhs *DoesNotExistException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of DoesNotExistException. func (v *DoesNotExistException) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", v.Key) @@ -280,7 +280,7 @@ func (v *EmptyException) Equals(rhs *EmptyException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EmptyException. func (v *EmptyException) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/envelope/internal/tests/services/cache_clear.go b/envelope/internal/tests/services/cache_clear.go index 58e09033..c4504f33 100644 --- a/envelope/internal/tests/services/cache_clear.go +++ b/envelope/internal/tests/services/cache_clear.go @@ -109,7 +109,7 @@ func (v *Cache_Clear_Args) Equals(rhs *Cache_Clear_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Cache_Clear_Args. func (v *Cache_Clear_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/envelope/internal/tests/services/cache_clearafter.go b/envelope/internal/tests/services/cache_clearafter.go index b8524760..ad3cef6f 100644 --- a/envelope/internal/tests/services/cache_clearafter.go +++ b/envelope/internal/tests/services/cache_clearafter.go @@ -149,7 +149,7 @@ func (v *Cache_ClearAfter_Args) Equals(rhs *Cache_ClearAfter_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Cache_ClearAfter_Args. func (v *Cache_ClearAfter_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DurationMS != nil { diff --git a/envelope/internal/tests/services/conflictingnames_setvalue.go b/envelope/internal/tests/services/conflictingnames_setvalue.go index efcc7127..dc125706 100644 --- a/envelope/internal/tests/services/conflictingnames_setvalue.go +++ b/envelope/internal/tests/services/conflictingnames_setvalue.go @@ -143,7 +143,7 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ConflictingNames_SetValue_Args. func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { @@ -334,7 +334,7 @@ func (v *ConflictingNames_SetValue_Result) Equals(rhs *ConflictingNames_SetValue return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ConflictingNames_SetValue_Result. func (v *ConflictingNames_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/envelope/internal/tests/services/keyvalue_deletevalue.go b/envelope/internal/tests/services/keyvalue_deletevalue.go index 54d16fa2..3845f651 100644 --- a/envelope/internal/tests/services/keyvalue_deletevalue.go +++ b/envelope/internal/tests/services/keyvalue_deletevalue.go @@ -157,7 +157,7 @@ func (v *KeyValue_DeleteValue_Args) Equals(rhs *KeyValue_DeleteValue_Args) bool return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_DeleteValue_Args. func (v *KeyValue_DeleteValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -451,7 +451,7 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_DeleteValue_Result. func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DoesNotExist != nil { diff --git a/envelope/internal/tests/services/keyvalue_getmanyvalues.go b/envelope/internal/tests/services/keyvalue_getmanyvalues.go index 3c654084..9125451c 100644 --- a/envelope/internal/tests/services/keyvalue_getmanyvalues.go +++ b/envelope/internal/tests/services/keyvalue_getmanyvalues.go @@ -201,7 +201,7 @@ func (v *KeyValue_GetManyValues_Args) Equals(rhs *KeyValue_GetManyValues_Args) b type _List_Key_Zapper []Key -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Key_Zapper. func (l _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -210,7 +210,7 @@ func (l _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetManyValues_Args. func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Range != nil { @@ -561,7 +561,7 @@ func (v *KeyValue_GetManyValues_Result) Equals(rhs *KeyValue_GetManyValues_Resul type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_ArbitraryValue_Zapper. func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -572,7 +572,7 @@ func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetManyValues_Result. func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/envelope/internal/tests/services/keyvalue_getvalue.go b/envelope/internal/tests/services/keyvalue_getvalue.go index 052bd64c..e460e5a1 100644 --- a/envelope/internal/tests/services/keyvalue_getvalue.go +++ b/envelope/internal/tests/services/keyvalue_getvalue.go @@ -142,7 +142,7 @@ func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetValue_Args. func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -421,7 +421,7 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetValue_Result. func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/envelope/internal/tests/services/keyvalue_setvalue.go b/envelope/internal/tests/services/keyvalue_setvalue.go index 4380491c..95e3e4bf 100644 --- a/envelope/internal/tests/services/keyvalue_setvalue.go +++ b/envelope/internal/tests/services/keyvalue_setvalue.go @@ -164,7 +164,7 @@ func (v *KeyValue_SetValue_Args) Equals(rhs *KeyValue_SetValue_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_SetValue_Args. func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -371,7 +371,7 @@ func (v *KeyValue_SetValue_Result) Equals(rhs *KeyValue_SetValue_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_SetValue_Result. func (v *KeyValue_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/envelope/internal/tests/services/keyvalue_setvaluev2.go b/envelope/internal/tests/services/keyvalue_setvaluev2.go index bae24940..1ffe9fd1 100644 --- a/envelope/internal/tests/services/keyvalue_setvaluev2.go +++ b/envelope/internal/tests/services/keyvalue_setvaluev2.go @@ -173,10 +173,11 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_SetValueV2_Args. func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", (string)(v.Key)) + if err := enc.AddObject("value", v.Value); err != nil { return err } @@ -364,7 +365,7 @@ func (v *KeyValue_SetValueV2_Result) Equals(rhs *KeyValue_SetValueV2_Result) boo return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_SetValueV2_Result. func (v *KeyValue_SetValueV2_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/envelope/internal/tests/services/keyvalue_size.go b/envelope/internal/tests/services/keyvalue_size.go index 7d788e29..5175d448 100644 --- a/envelope/internal/tests/services/keyvalue_size.go +++ b/envelope/internal/tests/services/keyvalue_size.go @@ -110,7 +110,7 @@ func (v *KeyValue_Size_Args) Equals(rhs *KeyValue_Size_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_Size_Args. func (v *KeyValue_Size_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { @@ -331,7 +331,7 @@ func (v *KeyValue_Size_Result) Equals(rhs *KeyValue_Size_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_Size_Result. func (v *KeyValue_Size_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go b/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go index 711bc3b3..1f7f715a 100644 --- a/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go +++ b/envelope/internal/tests/services/non_standard_service_name_non_standard_function_name.go @@ -109,7 +109,7 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Args) Equals(rhs *NonSta return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of NonStandardServiceName_NonStandardFunctionName_Args. func (v *NonStandardServiceName_NonStandardFunctionName_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { @@ -279,7 +279,7 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Result) Equals(rhs *NonS return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of NonStandardServiceName_NonStandardFunctionName_Result. func (v *NonStandardServiceName_NonStandardFunctionName_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/envelope/internal/tests/services/types.go b/envelope/internal/tests/services/types.go index d5e4ca6e..b77748c0 100644 --- a/envelope/internal/tests/services/types.go +++ b/envelope/internal/tests/services/types.go @@ -167,7 +167,7 @@ func (v *ConflictingNamesSetValueArgs) Equals(rhs *ConflictingNamesSetValueArgs) return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ConflictingNamesSetValueArgs. func (v *ConflictingNamesSetValueArgs) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", v.Key) @@ -300,7 +300,7 @@ func (v *InternalError) Equals(rhs *InternalError) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of InternalError. func (v *InternalError) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Message != nil { diff --git a/envelope/internal/tests/structs/types.go b/envelope/internal/tests/structs/types.go index 585012ec..df7c30d3 100644 --- a/envelope/internal/tests/structs/types.go +++ b/envelope/internal/tests/structs/types.go @@ -141,7 +141,7 @@ func (v *ContactInfo) Equals(rhs *ContactInfo) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ContactInfo. func (v *ContactInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("emailAddress", v.EmailAddress) @@ -701,7 +701,7 @@ func (v *DefaultsStruct) Equals(rhs *DefaultsStruct) bool { type _List_String_Zapper []string -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_String_Zapper. func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -712,7 +712,7 @@ func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_Double_Zapper []float64 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Double_Zapper. func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -721,7 +721,7 @@ func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of DefaultsStruct. func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.RequiredPrimitive != nil { @@ -1012,12 +1012,14 @@ func (v *Edge) Equals(rhs *Edge) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Edge. func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("startPoint", v.StartPoint); err != nil { return err } + if err := enc.AddObject("endPoint", v.EndPoint); err != nil { return err } @@ -1109,7 +1111,7 @@ func (v *EmptyStruct) Equals(rhs *EmptyStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EmptyStruct. func (v *EmptyStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { @@ -1259,12 +1261,14 @@ func (v *Frame) Equals(rhs *Frame) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Frame. func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("topLeft", v.TopLeft); err != nil { return err } + if err := enc.AddObject("size", v.Size); err != nil { return err } @@ -1528,7 +1532,7 @@ func (v *GoTags) Equals(rhs *GoTags) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of GoTags. func (v *GoTags) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("Foo", v.Foo) @@ -1758,7 +1762,7 @@ func (v *Graph) Equals(rhs *Graph) bool { type _List_Edge_Zapper []*Edge -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Edge_Zapper. func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1769,9 +1773,10 @@ func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Graph. func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { return err } @@ -1954,7 +1959,7 @@ func (v *Node) Equals(rhs *Node) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Node. func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", v.Value) @@ -2113,7 +2118,7 @@ func (v *Omit) Equals(rhs *Omit) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Omit. func (v *Omit) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("serialized", v.Serialized) @@ -2263,7 +2268,7 @@ func (v *Point) Equals(rhs *Point) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Point. func (v *Point) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddFloat64("x", v.X) @@ -2619,7 +2624,7 @@ func (v *PrimitiveOptionalStruct) Equals(rhs *PrimitiveOptionalStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of PrimitiveOptionalStruct. func (v *PrimitiveOptionalStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BoolField != nil { @@ -3023,7 +3028,7 @@ func (v *PrimitiveRequiredStruct) Equals(rhs *PrimitiveRequiredStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of PrimitiveRequiredStruct. func (v *PrimitiveRequiredStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddBool("boolField", v.BoolField) @@ -3202,7 +3207,7 @@ func (v *Rename) Equals(rhs *Rename) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Rename. func (v *Rename) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("Default", v.Default) @@ -3354,7 +3359,7 @@ func (v *Size) Equals(rhs *Size) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Size. func (v *Size) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddFloat64("width", v.Width) @@ -3507,7 +3512,7 @@ func (v *User) Equals(rhs *User) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of User. func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) diff --git a/envelope/internal/tests/typedefs/types.go b/envelope/internal/tests/typedefs/types.go index 56ca391f..1229a50f 100644 --- a/envelope/internal/tests/typedefs/types.go +++ b/envelope/internal/tests/typedefs/types.go @@ -106,7 +106,7 @@ func _Set_Binary_Equals(lhs, rhs [][]byte) bool { type _BinarySet_Zapper [][]byte -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _BinarySet_Zapper. func (s _BinarySet_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range s { @@ -283,7 +283,7 @@ func (v *DefaultPrimitiveTypedef) Equals(rhs *DefaultPrimitiveTypedef) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of DefaultPrimitiveTypedef. func (v *DefaultPrimitiveTypedef) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.State != nil { @@ -430,7 +430,7 @@ type _MapItem_Edge_Edge_Zapper struct { Value *structs.Edge } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_Edge_Edge_Zapper. func (v _MapItem_Edge_Edge_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", v.Key); err != nil { @@ -447,7 +447,7 @@ type _EdgeMap_Zapper []struct { Value *structs.Edge } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _EdgeMap_Zapper. func (m _EdgeMap_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range m { @@ -664,9 +664,10 @@ func (v *Event) Equals(rhs *Event) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Event. func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { return err } @@ -761,7 +762,7 @@ func _List_Event_Equals(lhs, rhs []*Event) bool { type _EventGroup_Zapper []*Event -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _EventGroup_Zapper. func (l _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -884,7 +885,7 @@ func _Set_Frame_Equals(lhs, rhs []*structs.Frame) bool { type _FrameGroup_Zapper []*structs.Frame -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _FrameGroup_Zapper. func (s _FrameGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range s { @@ -1129,7 +1130,7 @@ type _MapItem_Point_Point_Zapper struct { Value *structs.Point } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_Point_Point_Zapper. func (v _MapItem_Point_Point_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", v.Key); err != nil { @@ -1146,7 +1147,7 @@ type _PointMap_Zapper []struct { Value *structs.Point } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _PointMap_Zapper. func (m _PointMap_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range m { @@ -1433,7 +1434,7 @@ func (v *Transition) Equals(rhs *Transition) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Transition. func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("fromState", (string)(v.FromState)) @@ -1630,7 +1631,7 @@ func (v *I128) Equals(rhs *I128) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of I128. func (v *I128) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt64("high", v.High) diff --git a/envelope/internal/tests/unions/types.go b/envelope/internal/tests/unions/types.go index d9332e87..715ffdb3 100644 --- a/envelope/internal/tests/unions/types.go +++ b/envelope/internal/tests/unions/types.go @@ -454,7 +454,7 @@ func (v *ArbitraryValue) Equals(rhs *ArbitraryValue) bool { type _List_ArbitraryValue_Zapper []*ArbitraryValue -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_ArbitraryValue_Zapper. func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -467,7 +467,7 @@ func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_ArbitraryValue_Zapper. func (m _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -478,7 +478,7 @@ func (m _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEn return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ArbitraryValue. func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BoolValue != nil { @@ -705,7 +705,7 @@ func (v *Document) Equals(rhs *Document) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Document. func (v *Document) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Pdf != nil { @@ -814,7 +814,7 @@ func (v *EmptyUnion) Equals(rhs *EmptyUnion) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EmptyUnion. func (v *EmptyUnion) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/gen/internal/tests/collision/types.go b/gen/internal/tests/collision/types.go index e8a06e14..d5d440ac 100644 --- a/gen/internal/tests/collision/types.go +++ b/gen/internal/tests/collision/types.go @@ -157,7 +157,7 @@ func (v *AccessorConflict) Equals(rhs *AccessorConflict) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of AccessorConflict. func (v *AccessorConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Name != nil { @@ -322,7 +322,7 @@ func (v *AccessorNoConflict) Equals(rhs *AccessorNoConflict) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of AccessorNoConflict. func (v *AccessorNoConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Getname != nil { @@ -456,7 +456,7 @@ func (v MyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of MyEnum. func (v MyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -941,7 +941,7 @@ func (v *PrimitiveContainers) Equals(rhs *PrimitiveContainers) bool { type _List_String_Zapper []string -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_String_Zapper. func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -952,7 +952,7 @@ func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Set_String_Zapper map[string]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_String_Zapper. func (s _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range s { @@ -963,7 +963,7 @@ func (s _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Map_String_String_Zapper map[string]string -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_String_Zapper. func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -972,7 +972,7 @@ func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of PrimitiveContainers. func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.A != nil { @@ -1156,7 +1156,7 @@ func (v *StructCollision) Equals(rhs *StructCollision) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of StructCollision. func (v *StructCollision) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddBool("collisionField", v.CollisionField) @@ -1330,7 +1330,7 @@ func (v *UnionCollision) Equals(rhs *UnionCollision) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of UnionCollision. func (v *UnionCollision) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.CollisionField != nil { @@ -1486,7 +1486,7 @@ func (v *WithDefault) Equals(rhs *WithDefault) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of WithDefault. func (v *WithDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Pouet != nil { @@ -1598,7 +1598,7 @@ func (v MyEnum2) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of MyEnum2. func (v MyEnum2) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -1851,7 +1851,7 @@ func (v *StructCollision2) Equals(rhs *StructCollision2) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of StructCollision2. func (v *StructCollision2) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddBool("collisionField", v.CollisionField) @@ -2015,7 +2015,7 @@ func (v *UnionCollision2) Equals(rhs *UnionCollision2) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of UnionCollision2. func (v *UnionCollision2) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.CollisionField != nil { diff --git a/gen/internal/tests/containers/types.go b/gen/internal/tests/containers/types.go index f93714f8..df163454 100644 --- a/gen/internal/tests/containers/types.go +++ b/gen/internal/tests/containers/types.go @@ -1656,7 +1656,7 @@ func (v *ContainersOfContainers) Equals(rhs *ContainersOfContainers) bool { type _List_I32_Zapper []int32 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_I32_Zapper. func (l _List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1667,7 +1667,7 @@ func (l _List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_List_I32_Zapper [][]int32 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_List_I32_Zapper. func (l _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1680,7 +1680,7 @@ func (l _List_List_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Set_I32_Zapper map[int32]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_I32_Zapper. func (s _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range s { @@ -1691,7 +1691,7 @@ func (s _Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_Set_I32_Zapper []map[int32]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Set_I32_Zapper. func (l _List_Set_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1707,7 +1707,7 @@ type _MapItem_I32_I32_Zapper struct { Value int32 } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_I32_I32_Zapper. func (v _MapItem_I32_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", v.Key) @@ -1717,7 +1717,7 @@ func (v _MapItem_I32_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) err type _Map_I32_I32_Zapper map[int32]int32 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_I32_I32_Zapper. func (m _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range m { @@ -1730,7 +1730,7 @@ func (m _Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_Map_I32_I32_Zapper []map[int32]int32 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Map_I32_I32_Zapper. func (l _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1743,7 +1743,7 @@ func (l _List_Map_I32_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) erro type _Set_String_Zapper map[string]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_String_Zapper. func (s _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range s { @@ -1754,7 +1754,7 @@ func (s _Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Set_Set_String_Zapper []map[string]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_Set_String_Zapper. func (s _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range s { @@ -1767,7 +1767,7 @@ func (s _Set_Set_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _List_String_Zapper []string -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_String_Zapper. func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1778,7 +1778,7 @@ func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Set_List_String_Zapper [][]string -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_List_String_Zapper. func (s _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range s { @@ -1791,7 +1791,7 @@ func (s _Set_List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _Map_String_String_Zapper map[string]string -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_String_Zapper. func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -1802,7 +1802,7 @@ func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e type _Set_Map_String_String_Zapper []map[string]string -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_Map_String_String_Zapper. func (s _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range s { @@ -1815,7 +1815,7 @@ func (s _Set_Map_String_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) type _Map_String_I32_Zapper map[string]int32 -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_I32_Zapper. func (m _Map_String_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -1829,7 +1829,7 @@ type _MapItem_Map_String_I32_I64_Zapper struct { Value int64 } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_Map_String_I32_I64_Zapper. func (v _MapItem_Map_String_I32_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", (_Map_String_I32_Zapper)(v.Key)); err != nil { @@ -1844,7 +1844,7 @@ type _Map_Map_String_I32_I64_Zapper []struct { Value int64 } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_Map_String_I32_I64_Zapper. func (m _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range m { @@ -1859,7 +1859,7 @@ func (m _Map_Map_String_I32_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder type _Set_I64_Zapper map[int64]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_I64_Zapper. func (s _Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range s { @@ -1873,7 +1873,7 @@ type _MapItem_List_I32_Set_I64_Zapper struct { Value map[int64]struct{} } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_List_I32_Set_I64_Zapper. func (v _MapItem_List_I32_Set_I64_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("key", (_List_I32_Zapper)(v.Key)); err != nil { @@ -1890,7 +1890,7 @@ type _Map_List_I32_Set_I64_Zapper []struct { Value map[int64]struct{} } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_List_I32_Set_I64_Zapper. func (m _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range m { @@ -1905,7 +1905,7 @@ func (m _Map_List_I32_Set_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) type _List_Double_Zapper []float64 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Double_Zapper. func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1919,7 +1919,7 @@ type _MapItem_Set_I32_List_Double_Zapper struct { Value []float64 } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_Set_I32_List_Double_Zapper. func (v _MapItem_Set_I32_List_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddArray("key", (_Set_I32_Zapper)(v.Key)); err != nil { @@ -1936,7 +1936,7 @@ type _Map_Set_I32_List_Double_Zapper []struct { Value []float64 } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_Set_I32_List_Double_Zapper. func (m _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range m { @@ -1949,7 +1949,7 @@ func (m _Map_Set_I32_List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncode return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ContainersOfContainers. func (v *ContainersOfContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfLists != nil { @@ -2470,7 +2470,7 @@ func (v *EnumContainers) Equals(rhs *EnumContainers) bool { type _List_EnumDefault_Zapper []enums.EnumDefault -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_EnumDefault_Zapper. func (l _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -2483,7 +2483,7 @@ func (l _List_EnumDefault_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) erro type _Set_EnumWithValues_Zapper map[enums.EnumWithValues]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_EnumWithValues_Zapper. func (s _Set_EnumWithValues_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range s { @@ -2499,7 +2499,7 @@ type _MapItem_EnumWithDuplicateValues_I32_Zapper struct { Value int32 } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_EnumWithDuplicateValues_I32_Zapper. func (v _MapItem_EnumWithDuplicateValues_I32_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", v.Key); err != nil { @@ -2511,7 +2511,7 @@ func (v _MapItem_EnumWithDuplicateValues_I32_Zapper) MarshalLogObject(enc zapcor type _Map_EnumWithDuplicateValues_I32_Zapper map[enums.EnumWithDuplicateValues]int32 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_EnumWithDuplicateValues_I32_Zapper. func (m _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range m { @@ -2522,7 +2522,7 @@ func (m _Map_EnumWithDuplicateValues_I32_Zapper) MarshalLogArray(enc zapcore.Arr return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumContainers. func (v *EnumContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfEnums != nil { @@ -2843,7 +2843,7 @@ func (v *ListOfConflictingEnums) Equals(rhs *ListOfConflictingEnums) bool { type _List_RecordType_Zapper []enum_conflict.RecordType -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_RecordType_Zapper. func (l _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -2856,7 +2856,7 @@ func (l _List_RecordType_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _List_RecordType_1_Zapper []enums.RecordType -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_RecordType_1_Zapper. func (l _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -2867,12 +2867,14 @@ func (l _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) err return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ListOfConflictingEnums. func (v *ListOfConflictingEnums) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddArray("records", (_List_RecordType_Zapper)(v.Records)); err != nil { return err } + if err := enc.AddArray("otherRecords", (_List_RecordType_1_Zapper)(v.OtherRecords)); err != nil { return err } @@ -3160,7 +3162,7 @@ func (v *ListOfConflictingUUIDs) Equals(rhs *ListOfConflictingUUIDs) bool { type _List_UUID_Zapper []*typedefs.UUID -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_UUID_Zapper. func (l _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -3173,7 +3175,7 @@ func (l _List_UUID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_UUID_1_Zapper []uuid_conflict.UUID -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_UUID_1_Zapper. func (l _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -3182,12 +3184,14 @@ func (l _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ListOfConflictingUUIDs. func (v *ListOfConflictingUUIDs) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddArray("uuids", (_List_UUID_Zapper)(v.Uuids)); err != nil { return err } + if err := enc.AddArray("otherUUIDs", (_List_UUID_1_Zapper)(v.OtherUUIDs)); err != nil { return err } @@ -3535,7 +3539,7 @@ type _MapItem_Binary_String_Zapper struct { Value string } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_Binary_String_Zapper. func (v _MapItem_Binary_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", base64.StdEncoding.EncodeToString(v.Key)) @@ -3548,7 +3552,7 @@ type _Map_Binary_String_Zapper []struct { Value string } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_Binary_String_Zapper. func (m _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range m { @@ -3563,7 +3567,7 @@ func (m _Map_Binary_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) err type _Map_String_Binary_Zapper map[string][]byte -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_Binary_Zapper. func (m _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -3572,7 +3576,7 @@ func (m _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of MapOfBinaryAndString. func (v *MapOfBinaryAndString) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BinaryToString != nil { @@ -4178,7 +4182,7 @@ func (v *PrimitiveContainers) Equals(rhs *PrimitiveContainers) bool { type _List_Binary_Zapper [][]byte -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Binary_Zapper. func (l _List_Binary_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -4189,7 +4193,7 @@ func (l _List_Binary_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_I64_Zapper []int64 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_I64_Zapper. func (l _List_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -4200,7 +4204,7 @@ func (l _List_I64_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Set_Byte_Zapper map[int8]struct{} -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Set_Byte_Zapper. func (s _Set_Byte_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for v := range s { @@ -4214,7 +4218,7 @@ type _MapItem_I32_String_Zapper struct { Value string } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_I32_String_Zapper. func (v _MapItem_I32_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", v.Key) @@ -4224,7 +4228,7 @@ func (v _MapItem_I32_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) type _Map_I32_String_Zapper map[int32]string -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_I32_String_Zapper. func (m _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range m { @@ -4237,7 +4241,7 @@ func (m _Map_I32_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error type _Map_String_Bool_Zapper map[string]bool -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_Bool_Zapper. func (m _Map_String_Bool_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -4246,7 +4250,7 @@ func (m _Map_String_Bool_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) err return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of PrimitiveContainers. func (v *PrimitiveContainers) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ListOfBinary != nil { @@ -4593,7 +4597,7 @@ type _MapItem_I64_Double_Zapper struct { Value float64 } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_I64_Double_Zapper. func (v _MapItem_I64_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt64("key", v.Key) @@ -4603,7 +4607,7 @@ func (v _MapItem_I64_Double_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) type _Map_I64_Double_Zapper map[int64]float64 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_I64_Double_Zapper. func (m _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range m { @@ -4614,15 +4618,18 @@ func (m _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of PrimitiveContainersRequired. func (v *PrimitiveContainersRequired) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddArray("listOfStrings", (_List_String_Zapper)(v.ListOfStrings)); err != nil { return err } + if err := enc.AddArray("setOfInts", (_Set_I32_Zapper)(v.SetOfInts)); err != nil { return err } + if err := enc.AddArray("mapOfIntsToDoubles", (_Map_I64_Double_Zapper)(v.MapOfIntsToDoubles)); err != nil { return err } diff --git a/gen/internal/tests/enum_conflict/types.go b/gen/internal/tests/enum_conflict/types.go index 8f2cc36e..5e76e9e5 100644 --- a/gen/internal/tests/enum_conflict/types.go +++ b/gen/internal/tests/enum_conflict/types.go @@ -64,7 +64,7 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of RecordType. func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -365,7 +365,7 @@ func (v *Records) Equals(rhs *Records) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Records. func (v *Records) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.RecordType != nil { diff --git a/gen/internal/tests/enums/types.go b/gen/internal/tests/enums/types.go index 73a87759..3ef66a48 100644 --- a/gen/internal/tests/enums/types.go +++ b/gen/internal/tests/enums/types.go @@ -35,7 +35,7 @@ func (v EmptyEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EmptyEnum. func (v EmptyEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -188,7 +188,7 @@ func (v EnumDefault) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumDefault. func (v EnumDefault) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -407,7 +407,7 @@ func (v EnumWithDuplicateName) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumWithDuplicateName. func (v EnumWithDuplicateName) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -618,7 +618,7 @@ func (v EnumWithDuplicateValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumWithDuplicateValues. func (v EnumWithDuplicateValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -789,7 +789,7 @@ func (v EnumWithValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EnumWithValues. func (v EnumWithValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -974,7 +974,7 @@ func (v RecordType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of RecordType. func (v RecordType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -1144,7 +1144,7 @@ func (v RecordTypeValues) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of RecordTypeValues. func (v RecordTypeValues) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -1381,7 +1381,7 @@ func (v *StructWithOptionalEnum) Equals(rhs *StructWithOptionalEnum) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of StructWithOptionalEnum. func (v *StructWithOptionalEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.E != nil { @@ -1459,7 +1459,7 @@ func (v LowerCaseEnum) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of LowerCaseEnum. func (v LowerCaseEnum) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) diff --git a/gen/internal/tests/exceptions/types.go b/gen/internal/tests/exceptions/types.go index 4991ce6f..0e16a2f4 100644 --- a/gen/internal/tests/exceptions/types.go +++ b/gen/internal/tests/exceptions/types.go @@ -155,7 +155,7 @@ func (v *DoesNotExistException) Equals(rhs *DoesNotExistException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of DoesNotExistException. func (v *DoesNotExistException) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", v.Key) @@ -260,7 +260,7 @@ func (v *EmptyException) Equals(rhs *EmptyException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EmptyException. func (v *EmptyException) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/gen/internal/tests/services/cache_clear.go b/gen/internal/tests/services/cache_clear.go index dcb615b5..15470b9c 100644 --- a/gen/internal/tests/services/cache_clear.go +++ b/gen/internal/tests/services/cache_clear.go @@ -89,7 +89,7 @@ func (v *Cache_Clear_Args) Equals(rhs *Cache_Clear_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Cache_Clear_Args. func (v *Cache_Clear_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/gen/internal/tests/services/cache_clearafter.go b/gen/internal/tests/services/cache_clearafter.go index 01eae563..0a840c5a 100644 --- a/gen/internal/tests/services/cache_clearafter.go +++ b/gen/internal/tests/services/cache_clearafter.go @@ -129,7 +129,7 @@ func (v *Cache_ClearAfter_Args) Equals(rhs *Cache_ClearAfter_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Cache_ClearAfter_Args. func (v *Cache_ClearAfter_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DurationMS != nil { diff --git a/gen/internal/tests/services/conflictingnames_setvalue.go b/gen/internal/tests/services/conflictingnames_setvalue.go index e4ae7dd6..3aa348a2 100644 --- a/gen/internal/tests/services/conflictingnames_setvalue.go +++ b/gen/internal/tests/services/conflictingnames_setvalue.go @@ -123,7 +123,7 @@ func (v *ConflictingNames_SetValue_Args) Equals(rhs *ConflictingNames_SetValue_A return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ConflictingNames_SetValue_Args. func (v *ConflictingNames_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { @@ -314,7 +314,7 @@ func (v *ConflictingNames_SetValue_Result) Equals(rhs *ConflictingNames_SetValue return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ConflictingNames_SetValue_Result. func (v *ConflictingNames_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/gen/internal/tests/services/keyvalue_deletevalue.go b/gen/internal/tests/services/keyvalue_deletevalue.go index babd4c0d..d27f6293 100644 --- a/gen/internal/tests/services/keyvalue_deletevalue.go +++ b/gen/internal/tests/services/keyvalue_deletevalue.go @@ -137,7 +137,7 @@ func (v *KeyValue_DeleteValue_Args) Equals(rhs *KeyValue_DeleteValue_Args) bool return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_DeleteValue_Args. func (v *KeyValue_DeleteValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -431,7 +431,7 @@ func (v *KeyValue_DeleteValue_Result) Equals(rhs *KeyValue_DeleteValue_Result) b return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_DeleteValue_Result. func (v *KeyValue_DeleteValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.DoesNotExist != nil { diff --git a/gen/internal/tests/services/keyvalue_getmanyvalues.go b/gen/internal/tests/services/keyvalue_getmanyvalues.go index 18bed748..5408bc6d 100644 --- a/gen/internal/tests/services/keyvalue_getmanyvalues.go +++ b/gen/internal/tests/services/keyvalue_getmanyvalues.go @@ -181,7 +181,7 @@ func (v *KeyValue_GetManyValues_Args) Equals(rhs *KeyValue_GetManyValues_Args) b type _List_Key_Zapper []Key -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Key_Zapper. func (l _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -190,7 +190,7 @@ func (l _List_Key_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetManyValues_Args. func (v *KeyValue_GetManyValues_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Range != nil { @@ -541,7 +541,7 @@ func (v *KeyValue_GetManyValues_Result) Equals(rhs *KeyValue_GetManyValues_Resul type _List_ArbitraryValue_Zapper []*unions.ArbitraryValue -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_ArbitraryValue_Zapper. func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -552,7 +552,7 @@ func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetManyValues_Result. func (v *KeyValue_GetManyValues_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/gen/internal/tests/services/keyvalue_getvalue.go b/gen/internal/tests/services/keyvalue_getvalue.go index 83d70757..ae23f608 100644 --- a/gen/internal/tests/services/keyvalue_getvalue.go +++ b/gen/internal/tests/services/keyvalue_getvalue.go @@ -122,7 +122,7 @@ func (v *KeyValue_GetValue_Args) Equals(rhs *KeyValue_GetValue_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetValue_Args. func (v *KeyValue_GetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -401,7 +401,7 @@ func (v *KeyValue_GetValue_Result) Equals(rhs *KeyValue_GetValue_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_GetValue_Result. func (v *KeyValue_GetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/gen/internal/tests/services/keyvalue_setvalue.go b/gen/internal/tests/services/keyvalue_setvalue.go index 36923cc5..2b5b0a15 100644 --- a/gen/internal/tests/services/keyvalue_setvalue.go +++ b/gen/internal/tests/services/keyvalue_setvalue.go @@ -144,7 +144,7 @@ func (v *KeyValue_SetValue_Args) Equals(rhs *KeyValue_SetValue_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_SetValue_Args. func (v *KeyValue_SetValue_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Key != nil { @@ -351,7 +351,7 @@ func (v *KeyValue_SetValue_Result) Equals(rhs *KeyValue_SetValue_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_SetValue_Result. func (v *KeyValue_SetValue_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/gen/internal/tests/services/keyvalue_setvaluev2.go b/gen/internal/tests/services/keyvalue_setvaluev2.go index 4ab582b2..01815366 100644 --- a/gen/internal/tests/services/keyvalue_setvaluev2.go +++ b/gen/internal/tests/services/keyvalue_setvaluev2.go @@ -153,10 +153,11 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_SetValueV2_Args. func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", (string)(v.Key)) + if err := enc.AddObject("value", v.Value); err != nil { return err } @@ -344,7 +345,7 @@ func (v *KeyValue_SetValueV2_Result) Equals(rhs *KeyValue_SetValueV2_Result) boo return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_SetValueV2_Result. func (v *KeyValue_SetValueV2_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/gen/internal/tests/services/keyvalue_size.go b/gen/internal/tests/services/keyvalue_size.go index 318dc33b..fa5ccf3c 100644 --- a/gen/internal/tests/services/keyvalue_size.go +++ b/gen/internal/tests/services/keyvalue_size.go @@ -90,7 +90,7 @@ func (v *KeyValue_Size_Args) Equals(rhs *KeyValue_Size_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_Size_Args. func (v *KeyValue_Size_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { @@ -311,7 +311,7 @@ func (v *KeyValue_Size_Result) Equals(rhs *KeyValue_Size_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of KeyValue_Size_Result. func (v *KeyValue_Size_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go b/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go index 172dc17a..37c15fb3 100644 --- a/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go +++ b/gen/internal/tests/services/non_standard_service_name_non_standard_function_name.go @@ -89,7 +89,7 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Args) Equals(rhs *NonSta return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of NonStandardServiceName_NonStandardFunctionName_Args. func (v *NonStandardServiceName_NonStandardFunctionName_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { @@ -259,7 +259,7 @@ func (v *NonStandardServiceName_NonStandardFunctionName_Result) Equals(rhs *NonS return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of NonStandardServiceName_NonStandardFunctionName_Result. func (v *NonStandardServiceName_NonStandardFunctionName_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/gen/internal/tests/services/types.go b/gen/internal/tests/services/types.go index 0684e29a..b785dba5 100644 --- a/gen/internal/tests/services/types.go +++ b/gen/internal/tests/services/types.go @@ -147,7 +147,7 @@ func (v *ConflictingNamesSetValueArgs) Equals(rhs *ConflictingNamesSetValueArgs) return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ConflictingNamesSetValueArgs. func (v *ConflictingNamesSetValueArgs) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", v.Key) @@ -280,7 +280,7 @@ func (v *InternalError) Equals(rhs *InternalError) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of InternalError. func (v *InternalError) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Message != nil { diff --git a/gen/internal/tests/structs/types.go b/gen/internal/tests/structs/types.go index f2d9112a..c59a20ed 100644 --- a/gen/internal/tests/structs/types.go +++ b/gen/internal/tests/structs/types.go @@ -121,7 +121,7 @@ func (v *ContactInfo) Equals(rhs *ContactInfo) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ContactInfo. func (v *ContactInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("emailAddress", v.EmailAddress) @@ -681,7 +681,7 @@ func (v *DefaultsStruct) Equals(rhs *DefaultsStruct) bool { type _List_String_Zapper []string -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_String_Zapper. func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -692,7 +692,7 @@ func (l _List_String_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _List_Double_Zapper []float64 -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Double_Zapper. func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -701,7 +701,7 @@ func (l _List_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of DefaultsStruct. func (v *DefaultsStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.RequiredPrimitive != nil { @@ -992,12 +992,14 @@ func (v *Edge) Equals(rhs *Edge) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Edge. func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("startPoint", v.StartPoint); err != nil { return err } + if err := enc.AddObject("endPoint", v.EndPoint); err != nil { return err } @@ -1089,7 +1091,7 @@ func (v *EmptyStruct) Equals(rhs *EmptyStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EmptyStruct. func (v *EmptyStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { @@ -1239,12 +1241,14 @@ func (v *Frame) Equals(rhs *Frame) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Frame. func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("topLeft", v.TopLeft); err != nil { return err } + if err := enc.AddObject("size", v.Size); err != nil { return err } @@ -1508,7 +1512,7 @@ func (v *GoTags) Equals(rhs *GoTags) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of GoTags. func (v *GoTags) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("Foo", v.Foo) @@ -1738,7 +1742,7 @@ func (v *Graph) Equals(rhs *Graph) bool { type _List_Edge_Zapper []*Edge -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Edge_Zapper. func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1749,9 +1753,10 @@ func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Graph. func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { return err } @@ -1934,7 +1939,7 @@ func (v *Node) Equals(rhs *Node) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Node. func (v *Node) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", v.Value) @@ -2093,7 +2098,7 @@ func (v *Omit) Equals(rhs *Omit) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Omit. func (v *Omit) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("serialized", v.Serialized) @@ -2243,7 +2248,7 @@ func (v *Point) Equals(rhs *Point) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Point. func (v *Point) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddFloat64("x", v.X) @@ -2599,7 +2604,7 @@ func (v *PrimitiveOptionalStruct) Equals(rhs *PrimitiveOptionalStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of PrimitiveOptionalStruct. func (v *PrimitiveOptionalStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BoolField != nil { @@ -3003,7 +3008,7 @@ func (v *PrimitiveRequiredStruct) Equals(rhs *PrimitiveRequiredStruct) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of PrimitiveRequiredStruct. func (v *PrimitiveRequiredStruct) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddBool("boolField", v.BoolField) @@ -3182,7 +3187,7 @@ func (v *Rename) Equals(rhs *Rename) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Rename. func (v *Rename) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("Default", v.Default) @@ -3334,7 +3339,7 @@ func (v *Size) Equals(rhs *Size) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Size. func (v *Size) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddFloat64("width", v.Width) @@ -3487,7 +3492,7 @@ func (v *User) Equals(rhs *User) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of User. func (v *User) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) diff --git a/gen/internal/tests/typedefs/types.go b/gen/internal/tests/typedefs/types.go index 0538527e..848e1379 100644 --- a/gen/internal/tests/typedefs/types.go +++ b/gen/internal/tests/typedefs/types.go @@ -86,7 +86,7 @@ func _Set_Binary_Equals(lhs, rhs [][]byte) bool { type _BinarySet_Zapper [][]byte -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _BinarySet_Zapper. func (s _BinarySet_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range s { @@ -263,7 +263,7 @@ func (v *DefaultPrimitiveTypedef) Equals(rhs *DefaultPrimitiveTypedef) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of DefaultPrimitiveTypedef. func (v *DefaultPrimitiveTypedef) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.State != nil { @@ -410,7 +410,7 @@ type _MapItem_Edge_Edge_Zapper struct { Value *structs.Edge } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_Edge_Edge_Zapper. func (v _MapItem_Edge_Edge_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", v.Key); err != nil { @@ -427,7 +427,7 @@ type _EdgeMap_Zapper []struct { Value *structs.Edge } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _EdgeMap_Zapper. func (m _EdgeMap_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range m { @@ -644,9 +644,10 @@ func (v *Event) Equals(rhs *Event) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Event. func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { return err } @@ -741,7 +742,7 @@ func _List_Event_Equals(lhs, rhs []*Event) bool { type _EventGroup_Zapper []*Event -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _EventGroup_Zapper. func (l _EventGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -864,7 +865,7 @@ func _Set_Frame_Equals(lhs, rhs []*structs.Frame) bool { type _FrameGroup_Zapper []*structs.Frame -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _FrameGroup_Zapper. func (s _FrameGroup_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range s { @@ -1109,7 +1110,7 @@ type _MapItem_Point_Point_Zapper struct { Value *structs.Point } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_Point_Point_Zapper. func (v _MapItem_Point_Point_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { if err := enc.AddObject("key", v.Key); err != nil { @@ -1126,7 +1127,7 @@ type _PointMap_Zapper []struct { Value *structs.Point } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _PointMap_Zapper. func (m _PointMap_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, i := range m { @@ -1413,7 +1414,7 @@ func (v *Transition) Equals(rhs *Transition) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Transition. func (v *Transition) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("fromState", (string)(v.FromState)) @@ -1610,7 +1611,7 @@ func (v *I128) Equals(rhs *I128) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of I128. func (v *I128) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt64("high", v.High) diff --git a/gen/internal/tests/unions/types.go b/gen/internal/tests/unions/types.go index 0a56edbd..38485d67 100644 --- a/gen/internal/tests/unions/types.go +++ b/gen/internal/tests/unions/types.go @@ -434,7 +434,7 @@ func (v *ArbitraryValue) Equals(rhs *ArbitraryValue) bool { type _List_ArbitraryValue_Zapper []*ArbitraryValue -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_ArbitraryValue_Zapper. func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -447,7 +447,7 @@ func (l _List_ArbitraryValue_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e type _Map_String_ArbitraryValue_Zapper map[string]*ArbitraryValue -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_ArbitraryValue_Zapper. func (m _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -458,7 +458,7 @@ func (m _Map_String_ArbitraryValue_Zapper) MarshalLogObject(enc zapcore.ObjectEn return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ArbitraryValue. func (v *ArbitraryValue) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.BoolValue != nil { @@ -685,7 +685,7 @@ func (v *Document) Equals(rhs *Document) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Document. func (v *Document) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Pdf != nil { @@ -794,7 +794,7 @@ func (v *EmptyUnion) Equals(rhs *EmptyUnion) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of EmptyUnion. func (v *EmptyUnion) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/gen/internal/tests/uuid_conflict/types.go b/gen/internal/tests/uuid_conflict/types.go index 37d5067c..9b9cf296 100644 --- a/gen/internal/tests/uuid_conflict/types.go +++ b/gen/internal/tests/uuid_conflict/types.go @@ -189,10 +189,11 @@ func (v *UUIDConflict) Equals(rhs *UUIDConflict) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of UUIDConflict. func (v *UUIDConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("localUUID", (string)(v.LocalUUID)) + if err := enc.AddObject("importedUUID", (*typedefs.I128)(v.ImportedUUID)); err != nil { return err } diff --git a/internal/envelope/exception/types.go b/internal/envelope/exception/types.go index c407dc2a..ad79ac62 100644 --- a/internal/envelope/exception/types.go +++ b/internal/envelope/exception/types.go @@ -146,7 +146,7 @@ func (v ExceptionType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ExceptionType. func (v ExceptionType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -473,7 +473,7 @@ func (v *TApplicationException) Equals(rhs *TApplicationException) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of TApplicationException. func (v *TApplicationException) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Message != nil { diff --git a/plugin/api/plugin_goodbye.go b/plugin/api/plugin_goodbye.go index 180f0da5..b7d00418 100644 --- a/plugin/api/plugin_goodbye.go +++ b/plugin/api/plugin_goodbye.go @@ -109,7 +109,7 @@ func (v *Plugin_Goodbye_Args) Equals(rhs *Plugin_Goodbye_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Plugin_Goodbye_Args. func (v *Plugin_Goodbye_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { @@ -279,7 +279,7 @@ func (v *Plugin_Goodbye_Result) Equals(rhs *Plugin_Goodbye_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Plugin_Goodbye_Result. func (v *Plugin_Goodbye_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { diff --git a/plugin/api/plugin_handshake.go b/plugin/api/plugin_handshake.go index ac7b0966..36d971c3 100644 --- a/plugin/api/plugin_handshake.go +++ b/plugin/api/plugin_handshake.go @@ -144,7 +144,7 @@ func (v *Plugin_Handshake_Args) Equals(rhs *Plugin_Handshake_Args) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Plugin_Handshake_Args. func (v *Plugin_Handshake_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { @@ -390,7 +390,7 @@ func (v *Plugin_Handshake_Result) Equals(rhs *Plugin_Handshake_Result) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Plugin_Handshake_Result. func (v *Plugin_Handshake_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/plugin/api/servicegenerator_generate.go b/plugin/api/servicegenerator_generate.go index 4bb9bd1d..4bdeb5cf 100644 --- a/plugin/api/servicegenerator_generate.go +++ b/plugin/api/servicegenerator_generate.go @@ -144,7 +144,7 @@ func (v *ServiceGenerator_Generate_Args) Equals(rhs *ServiceGenerator_Generate_A return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ServiceGenerator_Generate_Args. func (v *ServiceGenerator_Generate_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Request != nil { @@ -390,7 +390,7 @@ func (v *ServiceGenerator_Generate_Result) Equals(rhs *ServiceGenerator_Generate return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ServiceGenerator_Generate_Result. func (v *ServiceGenerator_Generate_Result) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Success != nil { diff --git a/plugin/api/types.go b/plugin/api/types.go index 72d8428d..750ce6fa 100644 --- a/plugin/api/types.go +++ b/plugin/api/types.go @@ -189,10 +189,11 @@ func (v *Argument) Equals(rhs *Argument) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Argument. func (v *Argument) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) + if err := enc.AddObject("type", v.Type); err != nil { return err } @@ -256,7 +257,7 @@ func (v Feature) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Feature. func (v Feature) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -808,7 +809,7 @@ func (v *Function) Equals(rhs *Function) bool { type _List_Argument_Zapper []*Argument -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Argument_Zapper. func (l _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -821,7 +822,7 @@ func (l _List_Argument_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { type _Map_String_String_Zapper map[string]string -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_String_Zapper. func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -830,11 +831,12 @@ func (m _Map_String_String_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Function. func (v *Function) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) enc.AddString("thriftName", v.ThriftName) + if err := enc.AddArray("arguments", (_List_Argument_Zapper)(v.Arguments)); err != nil { return err } @@ -1344,7 +1346,7 @@ func (v *GenerateServiceRequest) Equals(rhs *GenerateServiceRequest) bool { type _List_ServiceID_Zapper []ServiceID -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_ServiceID_Zapper. func (l _List_ServiceID_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -1358,7 +1360,7 @@ type _MapItem_ServiceID_Service_Zapper struct { Value *Service } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_ServiceID_Service_Zapper. func (v _MapItem_ServiceID_Service_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", (int32)(v.Key)) @@ -1370,7 +1372,7 @@ func (v _MapItem_ServiceID_Service_Zapper) MarshalLogObject(enc zapcore.ObjectEn type _Map_ServiceID_Service_Zapper map[ServiceID]*Service -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_ServiceID_Service_Zapper. func (m _Map_ServiceID_Service_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range m { @@ -1386,7 +1388,7 @@ type _MapItem_ModuleID_Module_Zapper struct { Value *Module } -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _MapItem_ModuleID_Module_Zapper. func (v _MapItem_ModuleID_Module_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("key", (int32)(v.Key)) @@ -1398,7 +1400,7 @@ func (v _MapItem_ModuleID_Module_Zapper) MarshalLogObject(enc zapcore.ObjectEnco type _Map_ModuleID_Module_Zapper map[ModuleID]*Module -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _Map_ModuleID_Module_Zapper. func (m _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for k, v := range m { @@ -1409,15 +1411,18 @@ func (m _Map_ModuleID_Module_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) e return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of GenerateServiceRequest. func (v *GenerateServiceRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddArray("rootServices", (_List_ServiceID_Zapper)(v.RootServices)); err != nil { return err } + if err := enc.AddArray("services", (_Map_ServiceID_Service_Zapper)(v.Services)); err != nil { return err } + if err := enc.AddArray("modules", (_Map_ModuleID_Module_Zapper)(v.Modules)); err != nil { return err } @@ -1634,7 +1639,7 @@ func (v *GenerateServiceResponse) Equals(rhs *GenerateServiceResponse) bool { type _Map_String_Binary_Zapper map[string][]byte -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of _Map_String_Binary_Zapper. func (m _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) error { for k, v := range m { @@ -1643,7 +1648,7 @@ func (m _Map_String_Binary_Zapper) MarshalLogObject(enc zapcore.ObjectEncoder) e return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of GenerateServiceResponse. func (v *GenerateServiceResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.Files != nil { @@ -1743,7 +1748,7 @@ func (v *HandshakeRequest) Equals(rhs *HandshakeRequest) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of HandshakeRequest. func (v *HandshakeRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { @@ -2024,7 +2029,7 @@ func (v *HandshakeResponse) Equals(rhs *HandshakeResponse) bool { type _List_Feature_Zapper []Feature -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Feature_Zapper. func (l _List_Feature_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -2035,11 +2040,12 @@ func (l _List_Feature_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of HandshakeResponse. func (v *HandshakeResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) enc.AddInt32("apiVersion", v.APIVersion) + if err := enc.AddArray("features", (_List_Feature_Zapper)(v.Features)); err != nil { return err } @@ -2213,7 +2219,7 @@ func (v *Module) Equals(rhs *Module) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Module. func (v *Module) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("importPath", v.ImportPath) @@ -2598,7 +2604,7 @@ func (v *Service) Equals(rhs *Service) bool { type _List_Function_Zapper []*Function -// MarshalLogArray implements zapcore.ArrayMarshaler, allowing +// MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of _List_Function_Zapper. func (l _List_Function_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { for _, v := range l { @@ -2609,7 +2615,7 @@ func (l _List_Function_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { return nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Service. func (v *Service) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) @@ -2617,6 +2623,7 @@ func (v *Service) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.ParentID != nil { enc.AddInt32("parentID", (int32)(*v.ParentID)) } + if err := enc.AddArray("functions", (_List_Function_Zapper)(v.Functions)); err != nil { return err } @@ -2798,7 +2805,7 @@ func (v SimpleType) MarshalText() ([]byte, error) { return []byte(strconv.FormatInt(int64(v), 10)), nil } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of SimpleType. func (v SimpleType) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddInt32("value", int32(v)) @@ -3248,7 +3255,7 @@ func (v *Type) Equals(rhs *Type) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Type. func (v *Type) MarshalLogObject(enc zapcore.ObjectEncoder) error { if v.SimpleType != nil { @@ -3483,12 +3490,14 @@ func (v *TypePair) Equals(rhs *TypePair) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of TypePair. func (v *TypePair) MarshalLogObject(enc zapcore.ObjectEncoder) error { + if err := enc.AddObject("left", v.Left); err != nil { return err } + if err := enc.AddObject("right", v.Right); err != nil { return err } @@ -3680,7 +3689,7 @@ func (v *TypeReference) Equals(rhs *TypeReference) bool { return true } -// MarshalLogObject implements zapcore.ObjectMarshaler, allowing +// MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of TypeReference. func (v *TypeReference) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("name", v.Name) From 34c1a75bc102bc51945960e00b5fbff988c118e8 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Fri, 3 Aug 2018 15:49:13 -0700 Subject: [PATCH 20/25] wip --- gen/field.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gen/field.go b/gen/field.go index 92f7b23f..449a3889 100644 --- a/gen/field.go +++ b/gen/field.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018 Uber Technologies, Inc. +// Copyright (c) 2018 Uber Technologies, Inc // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -479,12 +479,13 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <- $fname := goName . -> <- $fval := printf "%s.%s" $v $fname -> <- if .Required -> + <$encAdd := printf "%s.Add%s(%q,%s)" $enc (zapEncoder .Type) .Name (zapMarshaler .Type $fval)> <- if (zapCanError .Type)> - if err := <$enc>.Add("<.Name>", ); err != nil { + if err := <$encAdd>; err != nil { return err } <- else -> - <$enc>.Add("<.Name>", ) + <$encAdd> <- end -> <- else -> if <$fval> != nil { From 7f0fe26dcee9d2cac0621b4b10c47c039002bc78 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Fri, 3 Aug 2018 17:16:09 -0700 Subject: [PATCH 21/25] wip --- gen/field.go | 7 ++++--- gen/list.go | 5 +++-- gen/map.go | 19 +++++++++++-------- gen/set.go | 5 +++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/gen/field.go b/gen/field.go index 449a3889..63d9f8b8 100644 --- a/gen/field.go +++ b/gen/field.go @@ -479,7 +479,7 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <- $fname := goName . -> <- $fval := printf "%s.%s" $v $fname -> <- if .Required -> - <$encAdd := printf "%s.Add%s(%q,%s)" $enc (zapEncoder .Type) .Name (zapMarshaler .Type $fval)> + <$encAdd := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .Type) .Name (zapMarshaler .Type $fval)> <- if (zapCanError .Type)> if err := <$encAdd>; err != nil { return err @@ -489,12 +489,13 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <- end -> <- else -> if <$fval> != nil { + <$encAdd := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .Type) .Name (zapMarshalerPtr .Type $fval)> <- if (zapCanError .Type)> - if err := <$enc>.Add("<.Name>", ); err != nil { + if err := <$encAdd>; err != nil { return err } <- else -> - <$enc>.Add("<.Name>", ) + <$encAdd> <- end -> } <- end> diff --git a/gen/list.go b/gen/list.go index 36e06dd4..e42301b1 100644 --- a/gen/list.go +++ b/gen/list.go @@ -200,12 +200,13 @@ func (l *listGenerator) zapMarshaler( // fast logging of <.Name>. func (<$l> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { for _, <$v> := range <$l> { + <$encAppend := printf "%s.Append%s(%s)" $enc (zapEncoder .Type.ValueSpec) (zapMarshaler .Type.ValueSpec $v)> - if err := <$enc>.Append(); err != nil { + if err := <$encAppend>; err != nil { return err } <- else -> - <$enc>.Append() + <$encAppend> <- end> } return nil diff --git a/gen/map.go b/gen/map.go index 48aa1174..6d283f1e 100644 --- a/gen/map.go +++ b/gen/map.go @@ -305,12 +305,13 @@ func (m *mapGenerator) zapMarshaler( // fast logging of <.Name>. func (<$m> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { for <$k>, <$v> := range <$m> { + <$encAdd := printf "%s.Add%s((string)(%v), %s)" $enc (zapEncoder .Type.ValueSpec) $k, (zapMarshaler .Type.ValueSpec $v)> - if err := <$enc>.Add((string)(<$k>), ); err != nil { - return err - } + if err := <$encAdd>; err != nil { + return err + } <- else -> - <$enc>.Add((string)(<$k>), ) + <$encAdd> <- end> } return nil @@ -389,19 +390,21 @@ func (m *mapGenerator) zapMapItemMarshaler( // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$v> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { + <$encAddKey := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .KeyType) "key" (zapMarshaler .KeyType $key)> - if err := <$enc>.Add("key", ); err != nil { + if err := <$encAddKey>; err != nil { return err } <- else -> - <$enc>.Add("key", ) + <$encAddKey> <- end> + <$encAddValue := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .ValueType) "value" (zapMarshaler .ValueType $val)> - if err := <$enc>.Add("value", ); err != nil { + if err := <$$encAddValue>; err != nil { return err } <- else -> - <$enc>.Add("value", ) + <$$encAddValue> <- end> return nil } diff --git a/gen/set.go b/gen/set.go index 1eed3970..086fca1e 100644 --- a/gen/set.go +++ b/gen/set.go @@ -224,12 +224,13 @@ func (s *setGenerator) zapMarshaler( for _, <$v> := range <$s> { + <$encAppend := printf "%s.Append%s(%s)" $enc (zapEncoder .Type.ValueSpec) (zapMarshaler .Type.ValueSpec $v)> - if err := <$enc>.Append(); err != nil { + if err := <$encAppend>; err != nil { return err } <- else -> - <$enc>.Append() + <$encAppend> <- end> } return nil From 329ee0cb574d7ce3ea93d352d4330913e4f4dfa5 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Sat, 4 Aug 2018 15:58:27 -0700 Subject: [PATCH 22/25] Refactor for readability --- gen/field.go | 2 +- gen/map.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gen/field.go b/gen/field.go index 63d9f8b8..08097f8f 100644 --- a/gen/field.go +++ b/gen/field.go @@ -488,8 +488,8 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <$encAdd> <- end -> <- else -> + <$encAdd := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .Type) .Name (zapMarshalerPtr .Type $fval)> if <$fval> != nil { - <$encAdd := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .Type) .Name (zapMarshalerPtr .Type $fval)> <- if (zapCanError .Type)> if err := <$encAdd>; err != nil { return err diff --git a/gen/map.go b/gen/map.go index 6d283f1e..eac77994 100644 --- a/gen/map.go +++ b/gen/map.go @@ -305,7 +305,7 @@ func (m *mapGenerator) zapMarshaler( // fast logging of <.Name>. func (<$m> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { for <$k>, <$v> := range <$m> { - <$encAdd := printf "%s.Add%s((string)(%v), %s)" $enc (zapEncoder .Type.ValueSpec) $k, (zapMarshaler .Type.ValueSpec $v)> + <$encAdd := printf "%s.Add%s((string)(%s), %s)" $enc (zapEncoder .Type.ValueSpec) $k (zapMarshaler .Type.ValueSpec $v)> if err := <$encAdd>; err != nil { return err @@ -400,11 +400,11 @@ func (m *mapGenerator) zapMapItemMarshaler( <- end> <$encAddValue := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .ValueType) "value" (zapMarshaler .ValueType $val)> - if err := <$$encAddValue>; err != nil { + if err := <$encAddValue>; err != nil { return err } <- else -> - <$$encAddValue> + <$encAddValue> <- end> return nil } From 2328cac4a13ee27df9e6ec9cc1a9a1bc50b9b998 Mon Sep 17 00:00:00 2001 From: Minho Park Date: Sat, 4 Aug 2018 16:10:00 -0700 Subject: [PATCH 23/25] Fix styling --- gen/field.go | 8 ++++---- gen/internal/tests/containers/types.go | 7 ------- gen/internal/tests/services/keyvalue_setvaluev2.go | 1 - gen/internal/tests/structs/types.go | 5 ----- gen/internal/tests/typedefs/types.go | 1 - gen/internal/tests/uuid_conflict/types.go | 1 - gen/list.go | 2 +- gen/map.go | 12 ++++++------ gen/set.go | 8 ++++---- 9 files changed, 15 insertions(+), 30 deletions(-) diff --git a/gen/field.go b/gen/field.go index 08097f8f..c51d07ee 100644 --- a/gen/field.go +++ b/gen/field.go @@ -479,8 +479,8 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <- $fname := goName . -> <- $fval := printf "%s.%s" $v $fname -> <- if .Required -> - <$encAdd := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .Type) .Name (zapMarshaler .Type $fval)> - <- if (zapCanError .Type)> + <- $encAdd := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .Type) .Name (zapMarshaler .Type $fval) -> + if err := <$encAdd>; err != nil { return err } @@ -488,9 +488,9 @@ func (f fieldGroupGenerator) Zap(g Generator) error { <$encAdd> <- end -> <- else -> - <$encAdd := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .Type) .Name (zapMarshalerPtr .Type $fval)> + <- $encAdd := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .Type) .Name (zapMarshalerPtr .Type $fval) -> if <$fval> != nil { - <- if (zapCanError .Type)> + if err := <$encAdd>; err != nil { return err } diff --git a/gen/internal/tests/containers/types.go b/gen/internal/tests/containers/types.go index df163454..53e2a135 100644 --- a/gen/internal/tests/containers/types.go +++ b/gen/internal/tests/containers/types.go @@ -2870,11 +2870,9 @@ func (l _List_RecordType_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) err // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ListOfConflictingEnums. func (v *ListOfConflictingEnums) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("records", (_List_RecordType_Zapper)(v.Records)); err != nil { return err } - if err := enc.AddArray("otherRecords", (_List_RecordType_1_Zapper)(v.OtherRecords)); err != nil { return err } @@ -3187,11 +3185,9 @@ func (l _List_UUID_1_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of ListOfConflictingUUIDs. func (v *ListOfConflictingUUIDs) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("uuids", (_List_UUID_Zapper)(v.Uuids)); err != nil { return err } - if err := enc.AddArray("otherUUIDs", (_List_UUID_1_Zapper)(v.OtherUUIDs)); err != nil { return err } @@ -4621,15 +4617,12 @@ func (m _Map_I64_Double_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of PrimitiveContainersRequired. func (v *PrimitiveContainersRequired) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("listOfStrings", (_List_String_Zapper)(v.ListOfStrings)); err != nil { return err } - if err := enc.AddArray("setOfInts", (_Set_I32_Zapper)(v.SetOfInts)); err != nil { return err } - if err := enc.AddArray("mapOfIntsToDoubles", (_Map_I64_Double_Zapper)(v.MapOfIntsToDoubles)); err != nil { return err } diff --git a/gen/internal/tests/services/keyvalue_setvaluev2.go b/gen/internal/tests/services/keyvalue_setvaluev2.go index 01815366..1cad6f78 100644 --- a/gen/internal/tests/services/keyvalue_setvaluev2.go +++ b/gen/internal/tests/services/keyvalue_setvaluev2.go @@ -157,7 +157,6 @@ func (v *KeyValue_SetValueV2_Args) Equals(rhs *KeyValue_SetValueV2_Args) bool { // fast logging of KeyValue_SetValueV2_Args. func (v *KeyValue_SetValueV2_Args) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("key", (string)(v.Key)) - if err := enc.AddObject("value", v.Value); err != nil { return err } diff --git a/gen/internal/tests/structs/types.go b/gen/internal/tests/structs/types.go index c59a20ed..c4a0ddc5 100644 --- a/gen/internal/tests/structs/types.go +++ b/gen/internal/tests/structs/types.go @@ -995,11 +995,9 @@ func (v *Edge) Equals(rhs *Edge) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Edge. func (v *Edge) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("startPoint", v.StartPoint); err != nil { return err } - if err := enc.AddObject("endPoint", v.EndPoint); err != nil { return err } @@ -1244,11 +1242,9 @@ func (v *Frame) Equals(rhs *Frame) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Frame. func (v *Frame) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("topLeft", v.TopLeft); err != nil { return err } - if err := enc.AddObject("size", v.Size); err != nil { return err } @@ -1756,7 +1752,6 @@ func (l _List_Edge_Zapper) MarshalLogArray(enc zapcore.ArrayEncoder) error { // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Graph. func (v *Graph) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddArray("edges", (_List_Edge_Zapper)(v.Edges)); err != nil { return err } diff --git a/gen/internal/tests/typedefs/types.go b/gen/internal/tests/typedefs/types.go index 848e1379..5ac5612e 100644 --- a/gen/internal/tests/typedefs/types.go +++ b/gen/internal/tests/typedefs/types.go @@ -647,7 +647,6 @@ func (v *Event) Equals(rhs *Event) bool { // MarshalLogObject implements zapcore.ObjectMarshaler, enabling // fast logging of Event. func (v *Event) MarshalLogObject(enc zapcore.ObjectEncoder) error { - if err := enc.AddObject("uuid", (*I128)(v.UUID)); err != nil { return err } diff --git a/gen/internal/tests/uuid_conflict/types.go b/gen/internal/tests/uuid_conflict/types.go index 9b9cf296..bb44bd3a 100644 --- a/gen/internal/tests/uuid_conflict/types.go +++ b/gen/internal/tests/uuid_conflict/types.go @@ -193,7 +193,6 @@ func (v *UUIDConflict) Equals(rhs *UUIDConflict) bool { // fast logging of UUIDConflict. func (v *UUIDConflict) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("localUUID", (string)(v.LocalUUID)) - if err := enc.AddObject("importedUUID", (*typedefs.I128)(v.ImportedUUID)); err != nil { return err } diff --git a/gen/list.go b/gen/list.go index e42301b1..715f44b4 100644 --- a/gen/list.go +++ b/gen/list.go @@ -200,7 +200,7 @@ func (l *listGenerator) zapMarshaler( // fast logging of <.Name>. func (<$l> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { for _, <$v> := range <$l> { - <$encAppend := printf "%s.Append%s(%s)" $enc (zapEncoder .Type.ValueSpec) (zapMarshaler .Type.ValueSpec $v)> + <- $encAppend := printf "%s.Append%s(%s)" $enc (zapEncoder .Type.ValueSpec) (zapMarshaler .Type.ValueSpec $v)> if err := <$encAppend>; err != nil { return err diff --git a/gen/map.go b/gen/map.go index eac77994..9dd57e78 100644 --- a/gen/map.go +++ b/gen/map.go @@ -305,7 +305,7 @@ func (m *mapGenerator) zapMarshaler( // fast logging of <.Name>. func (<$m> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { for <$k>, <$v> := range <$m> { - <$encAdd := printf "%s.Add%s((string)(%s), %s)" $enc (zapEncoder .Type.ValueSpec) $k (zapMarshaler .Type.ValueSpec $v)> + <- $encAdd := printf "%s.Add%s((string)(%s), %s)" $enc (zapEncoder .Type.ValueSpec) $k (zapMarshaler .Type.ValueSpec $v)> if err := <$encAdd>; err != nil { return err @@ -340,13 +340,13 @@ func (m *mapGenerator) zapMarshaler( // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$m> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { - <- if isHashable .Type.KeySpec -> + for <$k>, <$v> := range <$m> { - + <- else -> for _, <$i> := range <$m> { <$k> := <$i>.Key <$v> := <$i>.Value - + <- end> if err := <$enc>.AppendObject(); err != nil { return err } @@ -390,7 +390,7 @@ func (m *mapGenerator) zapMapItemMarshaler( // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$v> <.Name>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error { - <$encAddKey := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .KeyType) "key" (zapMarshaler .KeyType $key)> + <- $encAddKey := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .KeyType) "key" (zapMarshaler .KeyType $key)> if err := <$encAddKey>; err != nil { return err @@ -398,7 +398,7 @@ func (m *mapGenerator) zapMapItemMarshaler( <- else -> <$encAddKey> <- end> - <$encAddValue := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .ValueType) "value" (zapMarshaler .ValueType $val)> + <- $encAddValue := printf "%s.Add%s(%q, %s)" $enc (zapEncoder .ValueType) "value" (zapMarshaler .ValueType $val)> if err := <$encAddValue>; err != nil { return err diff --git a/gen/set.go b/gen/set.go index 086fca1e..d79fd511 100644 --- a/gen/set.go +++ b/gen/set.go @@ -219,12 +219,12 @@ func (s *setGenerator) zapMarshaler( // MarshalLogArray implements zapcore.ArrayMarshaler, enabling // fast logging of <.Name>. func (<$s> <.Name>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error { - <- if isHashable .Type.ValueSpec -> + for <$v> := range <$s> { - + <- else -> for _, <$v> := range <$s> { - - <$encAppend := printf "%s.Append%s(%s)" $enc (zapEncoder .Type.ValueSpec) (zapMarshaler .Type.ValueSpec $v)> + <- end> + <- $encAppend := printf "%s.Append%s(%s)" $enc (zapEncoder .Type.ValueSpec) (zapMarshaler .Type.ValueSpec $v)> if err := <$encAppend>; err != nil { return err From 8eb048f94720f609c4a0e0b707b2db1309185d3a Mon Sep 17 00:00:00 2001 From: Minho Park Date: Mon, 6 Aug 2018 11:17:06 -0700 Subject: [PATCH 24/25] glide: Pin to zap ^1 --- glide.lock | 14 +++++++------- glide.yaml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/glide.lock b/glide.lock index 881e3d1f..3763a1b4 100644 --- a/glide.lock +++ b/glide.lock @@ -1,16 +1,16 @@ -hash: 13611a214fe054d028621ae22f41fa294a2790cd6a0549bdbee33fada7c5bfab -updated: 2018-07-31T17:03:57.682127592-07:00 +hash: de4f56d34612433b7a80991786d4a9bf401fbd8d74bfd4b53e8a277e7f93bd6e +updated: 2018-08-06T11:16:47.428919733-07:00 imports: - name: github.com/anmitsu/go-shlex version: 648efa622239a2f6ff949fed78ee37b48d499ba4 - name: github.com/fatih/structtag version: da3d9ab5b78fdc25d3a7614853b085200bd10da9 - name: github.com/golang/mock - version: 22bbf0ddf08105dfa364d0a2fa619dfa71014af5 + version: c34cdb4725f4c3844d095133c6e40e448b86589b subpackages: - gomock - name: github.com/jessevdk/go-flags - version: 1c38ed7ad0cc3d9e66649ac398c30e45f395c4eb + version: c6ca198ec95c841fdb89fc0de7496fed11ab854e - name: github.com/kr/pretty version: 73f6ac0b30a98e433b289500d779f50c1a6f0712 - name: github.com/kr/text @@ -20,7 +20,7 @@ imports: - name: go.uber.org/multierr version: 3c4937480c32f4c13a875a1829af76c98ca3d40a - name: go.uber.org/zap - version: 1f8c4cad1e0417712b7d9f130a17b11eba6c8317 + version: ff33455a0e382e8a81d14dd7c922020b6b5e7982 subpackages: - buffer - internal/bufferpool @@ -28,11 +28,11 @@ imports: - internal/exit - zapcore - name: golang.org/x/net - version: 49c15d80dfbc983ea25246ee959d970efe09ec09 + version: f4c29de78a2a91c00474a2e689954305c350adf9 subpackages: - context - name: golang.org/x/tools - version: 33176b2029f9538e722efa4a005f7aa00cf60010 + version: 3c07937fe18c27668fd78bbaed3d6b8b39e202ea subpackages: - go/ast/astutil testImports: diff --git a/glide.yaml b/glide.yaml index 7c54be67..40ba5547 100644 --- a/glide.yaml +++ b/glide.yaml @@ -13,7 +13,7 @@ import: - package: github.com/fatih/structtag version: ^0.1.0 - package: go.uber.org/zap - version: master + version: ^1 testImport: - package: github.com/golang/mock subpackages: From 6b9f2b396779de60189471e7e3e251f36319c9af Mon Sep 17 00:00:00 2001 From: Minho Park Date: Mon, 6 Aug 2018 13:25:40 -0700 Subject: [PATCH 25/25] Modify changelog to reflect pr message --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5510e71d..0b13a6bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] -- All structs and its underlying components, enums, and typedefs of non-primitives - now implement `zapcore.ObjectMarshaler` or `zapcore.ArrayMarshaler`, depending - on its underlying type. For typedefs of primitives, the logging is up to the user, simply by casting it down to the root type and using the respective Add/Append... method of the Zap encoder. +- Added `zapcore.MarshalLogObject/Array` method to all generated structs + and its underlying components, enums, and non-primitive typedefs, implementing + Zap marshalers. ## [1.12.0] - 2018-06-25 ### Added