Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina-Sakai committed May 30, 2024
1 parent 9c3cb83 commit 2512412
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions client/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (kc *kClient) Stream(ctx context.Context, method string, request, response
panic("ctx is nil")
}
var ri rpcinfo.RPCInfo
// TODO: generic & streamingMode
ctx, ri, _ = kc.initRPCInfo(ctx, method, 0, nil)

rpcinfo.AsMutableRPCConfig(ri.Config()).SetInteractionMode(rpcinfo.Streaming)
Expand Down Expand Up @@ -98,6 +99,7 @@ func (kc *kClient) invokeStreamingEndpoint() (endpoint.Endpoint, error) {
}

func (kc *kClient) getStreamingMode(ri rpcinfo.RPCInfo) serviceinfo.StreamingMode {
// TODO: ここでキーがわかれば良い
methodInfo := kc.svcInfo.MethodInfo(ri.Invocation().MethodName())
if methodInfo == nil {
return serviceinfo.StreamingNone
Expand Down
3 changes: 3 additions & 0 deletions pkg/generic/descriptor/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"os"

dthrift "github.com/cloudwego/dynamicgo/thrift"

"github.com/cloudwego/kitex/pkg/serviceinfo"
)

var isGoTagAliasDisabled = os.Getenv("KITEX_GENERIC_GOTAG_ALIAS_DISABLED") == "True"
Expand Down Expand Up @@ -91,6 +93,7 @@ type FunctionDescriptor struct {
Request *TypeDescriptor
Response *TypeDescriptor
HasRequestBase bool
StreamingMode serviceinfo.StreamingMode
}

// ServiceDescriptor idl service descriptor
Expand Down
1 change: 0 additions & 1 deletion pkg/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ func (g *jsonThriftGeneric) PayloadCodecType() serviceinfo.PayloadCodec {

func (g *jsonThriftGeneric) PayloadCodec() remote.PayloadCodec {
return nil
//return g.codec
}

func (g *jsonThriftGeneric) GetMethod(req interface{}, method string) (*Method, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/generic/httpthrift_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestHttpThriftCodec(t *testing.T) {
test.Assert(t, htc.GetIDLServiceName() == "ExampleService")

rw := htc.GetMessageReaderWriter()
err, ok := rw.(error)
_, ok := rw.(error)
test.Assert(t, !ok)

htc.SetMethod(method.Name)
Expand Down
4 changes: 2 additions & 2 deletions pkg/generic/mapthrift_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package generic

import (
"github.com/pkg/errors"

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.19.12, X64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / benchmark-test

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.17, X64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.18, X64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / unit-scenario-test

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.19.12, ARM64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.21, X64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.18, ARM64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.17, ARM64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.22, X64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.20.7, ARM64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.20.7, X64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.21, ARM64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / compatibility-test (1.22, ARM64)

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:

Check failure on line 20 in pkg/generic/mapthrift_codec.go

View workflow job for this annotation

GitHub Actions / windows-test

missing go.sum entry for module providing package github.com/pkg/errors (imported by github.com/cloudwego/kitex/pkg/generic); to add:
"sync/atomic"

"github.com/cloudwego/kitex/pkg/generic/descriptor"
Expand Down Expand Up @@ -74,8 +75,7 @@ func (c *mapThriftCodec) update() {
func (c *mapThriftCodec) GetMessageReaderWriter() interface{} {
svcDsc, ok := c.svcDsc.Load().(*descriptor.ServiceDescriptor)
if !ok {
return nil
//return nil, fmt.Errorf("get parser ServiceDescriptor failed")
return errors.New("get parser ServiceDescriptor failed")
}
var rw *thrift.StructReaderWriter
var err error
Expand Down
22 changes: 22 additions & 0 deletions pkg/generic/thrift/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import (
"fmt"
"runtime/debug"

"github.com/cloudwego/thriftgo/generator/golang/streaming"
"github.com/cloudwego/thriftgo/parser"
"github.com/cloudwego/thriftgo/semantic"

"github.com/cloudwego/kitex/pkg/generic/descriptor"
"github.com/cloudwego/kitex/pkg/gofunc"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/serviceinfo"
)

const (
Expand Down Expand Up @@ -140,6 +142,11 @@ func addFunction(fn *parser.Function, tree *parser.Thrift, sDsc *descriptor.Serv
if len(fn.Arguments) == 0 {
return fmt.Errorf("empty arguments in function: %s", fn.Name)
}
st, err := streaming.ParseStreaming(fn)
if err != nil {
return err
}
mode := streamingMode(st)
// only support single argument
field := fn.Arguments[0]
req := &descriptor.TypeDescriptor{
Expand Down Expand Up @@ -213,6 +220,7 @@ func addFunction(fn *parser.Function, tree *parser.Thrift, sDsc *descriptor.Serv
Request: req,
Response: resp,
HasRequestBase: hasRequestBase,
StreamingMode: mode,
}
defer func() {
if ret := recover(); ret != nil {
Expand All @@ -234,6 +242,20 @@ func addFunction(fn *parser.Function, tree *parser.Thrift, sDsc *descriptor.Serv
return nil
}

func streamingMode(st *streaming.Streaming) serviceinfo.StreamingMode {
if st.BidirectionalStreaming {
return serviceinfo.StreamingBidirectional
}
if st.ClientStreaming {
return serviceinfo.StreamingClient
}
if st.ServerStreaming {
return serviceinfo.StreamingServer
}
return serviceinfo.StreamingNone
// TODO: unary
}

// reuse builtin types
var builtinTypes = map[string]*descriptor.TypeDescriptor{
"void": {Name: "void", Type: descriptor.VOID, Struct: new(descriptor.StructDescriptor)},
Expand Down

0 comments on commit 2512412

Please sign in to comment.