Skip to content

Commit

Permalink
fix: golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sudorandom committed Nov 6, 2024
1 parent 5da261f commit c820304
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
12 changes: 9 additions & 3 deletions example/set-data-on-message/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
func main() {
{
msg := &elizav1.SayResponse{}
fauxrpc.SetDataOnMessage(msg)
if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil {
log.Fatalf("err: %s", err)
}
b, err := protojson.MarshalOptions{Indent: " "}.Marshal(msg)
if err != nil {
log.Fatalf("err: %s", err)
Expand All @@ -24,7 +26,9 @@ func main() {

{
msg := &ownerv1.Owner{}
fauxrpc.SetDataOnMessage(msg)
if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil {
log.Fatalf("err: %s", err)
}
b, err := protojson.MarshalOptions{Indent: " "}.Marshal(msg)
if err != nil {
log.Fatalf("err: %s", err)
Expand All @@ -34,7 +38,9 @@ func main() {

{
msg := &runtimeapi.ListMetricDescriptorsResponse{}
fauxrpc.SetDataOnMessage(msg)
if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil {
log.Fatalf("err: %s", err)
}
b, err := protojson.MarshalOptions{Indent: " "}.Marshal(msg)
if err != nil {
log.Fatalf("err: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions fauxplugin/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func UnaryHandler[T *proto.Message](ctx context.Context, opts fauxrpc.GenOptions, msg *T) (*connect.Response[T], error) {
fauxrpc.SetDataOnMessage(**msg, opts)
_ = fauxrpc.SetDataOnMessage(**msg, opts)
return connect.NewResponse(msg), nil
}

Expand All @@ -26,7 +26,7 @@ func BidiStreamHandler[I proto.Message, O proto.Message](ctx context.Context, st
})
eg.Go(func() error {
var msg O
fauxrpc.SetDataOnMessage(msg, opts)
_ = fauxrpc.SetDataOnMessage(msg, opts)
return stream.Send(&msg)
})
return eg.Wait()
Expand Down
4 changes: 2 additions & 2 deletions gen_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ func getFieldValue(fd protoreflect.FieldDescriptor, opts GenOptions) *protorefle
}

nested := newMessage(fd.Message())
setDataOnMessage(nested.Interface(), opts.nested())
_ = setDataOnMessage(nested.Interface(), opts.nested())
v := protoreflect.ValueOf(nested)
return &v
case protoreflect.GroupKind:
nested := newMessage(fd.Message())
setDataOnMessage(nested.Interface(), opts.nested())
_ = setDataOnMessage(nested.Interface(), opts.nested())
v := protoreflect.ValueOf(nested)
return &v
}
Expand Down
13 changes: 8 additions & 5 deletions gen_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fauxrpc_test

import (
"fmt"
"log"
"testing"

elizav1 "buf.build/gen/go/connectrpc/eliza/protocolbuffers/go/connectrpc/eliza/v1"
Expand All @@ -19,7 +20,9 @@ var AllTypes = testv1.File_test_v1_test_proto.Messages().ByName("AllTypes")

func ExampleSetDataOnMessage() {
msg := &elizav1.SayResponse{}
fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})
if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil {
log.Fatalf("error: %s", err) // handle error
}
b, _ := protojson.MarshalOptions{Indent: " "}.Marshal(msg)
fmt.Println(string(b))
}
Expand All @@ -46,7 +49,7 @@ func TestNewMessage(t *testing.T) {
t.Run("AllTypes - dynamicpb", func(t *testing.T) {
md := testv1.File_test_v1_test_proto.Messages().ByName("AllTypes")
msg := dynamicpb.NewMessage(md)
fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})
require.NoError(t, fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}))
assertFieldIsSet(t, md, msg, "doubleValue")
assertFieldIsSet(t, md, msg, "doubleValue")
assertFieldIsSet(t, md, msg, "floatValue")
Expand Down Expand Up @@ -83,7 +86,7 @@ func TestNewMessage(t *testing.T) {

t.Run("AllTypes - concrete", func(t *testing.T) {
msg := &testv1.AllTypes{}
fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})
require.NoError(t, fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}))
md := msg.ProtoReflect().Descriptor()
pmsg := msg.ProtoReflect()
assertFieldIsSet(t, md, pmsg, "doubleValue")
Expand Down Expand Up @@ -123,7 +126,7 @@ func TestNewMessage(t *testing.T) {
t.Run("ParameterValues - dynamicpb", func(t *testing.T) {
md := testv1.File_test_v1_test_proto.Messages().ByName("ParameterValues")
msg := dynamicpb.NewMessage(md)
fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})
require.NoError(t, fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}))
assertFieldIsSet(t, md, msg, "doubleValue")
assertFieldIsSet(t, md, msg, "floatValue")
assertFieldIsSet(t, md, msg, "int32Value")
Expand Down Expand Up @@ -156,7 +159,7 @@ func TestNewMessage(t *testing.T) {

t.Run("ParameterValues - concrete", func(t *testing.T) {
msg := &testv1.ParameterValues{}
fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})
require.NoError(t, fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}))
md := msg.ProtoReflect().Descriptor()
pmsg := msg.ProtoReflect()
assertFieldIsSet(t, md, pmsg, "doubleValue")
Expand Down

0 comments on commit c820304

Please sign in to comment.