package config import ( "google.golang.org/protobuf/encoding/prototext" protoreflect "google.golang.org/protobuf/reflect/protoreflect" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) // --- Mock of a generated user.pb.go file --- type PatchError struct { // Note: The `XXX_` fields are part of the older struct tags, // but the reflection logic comes from the modern API. // In a real generated file, you wouldn't see these tags. UserName string `protobuf:"bytes,1,opt,name=user_name,json=userName,proto3" json:"user_name,omitempty"` UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"` LastLogin *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=last_login,json=lastLogin,proto3" json:"last_login,omitempty"` } func (x *PatchError) Reset() { *x = PatchError{} } func (x *PatchError) String() string { return prototext.Format(x) } // Modern way to implement String() func (*PatchError) ProtoMessage() {} // In a real generated file, ProtoReflect() would be fully implemented. // For this example, we don't need it as the marshallers will use reflection. func (x *PatchError) ProtoReflect() protoreflect.Message { return nil } // --- End of mock --- /* user := &User{ UserName:"jdoe", UserId: 12345, Email: "jdoe@example.com", LastLogin: timestamppb.Now(), } fmt.Println"==========================================================") fmt.Println"1. The Best Method: prototext.Format (like spew.Dump)") fmt.Println"==========================================================") // The prototext.Format function is the most direct equivalent. outText := prototext.Format(user) fmt.Println(outText) */