Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
96c699aa
Commit
96c699aa
authored
4 years ago
by
xuxiaoliang
Browse files
Options
Downloads
Patches
Plain Diff
add public method 、struc comment
parent
65e2b21e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
protocol/grpc/client.go
+1
-1
1 addition, 1 deletion
protocol/grpc/client.go
protocol/grpc/codec.go
+7
-9
7 additions, 9 deletions
protocol/grpc/codec.go
protocol/grpc/config.go
+9
-9
9 additions, 9 deletions
protocol/grpc/config.go
with
17 additions
and
19 deletions
protocol/grpc/client.go
+
1
−
1
View file @
96c699aa
...
...
@@ -77,7 +77,7 @@ func init() {
}
}
// Client
...
// Client
return grpc connection and warp service stub
type
Client
struct
{
*
grpc
.
ClientConn
invoker
reflect
.
Value
...
...
This diff is collapsed.
Click to expand it.
protocol/grpc/codec.go
+
7
−
9
View file @
96c699aa
...
...
@@ -29,10 +29,8 @@ import (
)
const
(
// json
CODEC_JSON
=
"json"
// proto
CODEC_PROTO
=
"proto"
codecJson
=
"json"
codecProto
=
"proto"
)
func
init
()
{
...
...
@@ -44,18 +42,18 @@ func init() {
})
}
// grpcJson ...
type
grpcJson
struct
{
jsonpb
.
Marshaler
jsonpb
.
Unmarshaler
}
// implements grpc encoding package Codec interface method
// Name implements grpc encoding package Codec interface method,
// returns the name of the Codec implementation.
func
(
_
grpcJson
)
Name
()
string
{
return
CODEC_JSON
return
codecJson
}
// implements grpc encoding package Codec interface method
//
Marshal
implements grpc encoding package Codec interface method
,returns the wire format of v.
func
(
j
grpcJson
)
Marshal
(
v
interface
{})
(
out
[]
byte
,
err
error
)
{
if
pm
,
ok
:=
v
.
(
proto
.
Message
);
ok
{
b
:=
new
(
bytes
.
Buffer
)
...
...
@@ -68,7 +66,7 @@ func (j grpcJson) Marshal(v interface{}) (out []byte, err error) {
return
json
.
Marshal
(
v
)
}
// implements grpc encoding package Codec interface method
//
Unmarshal
implements grpc encoding package Codec interface method
,Unmarshal parses the wire format into v.
func
(
j
grpcJson
)
Unmarshal
(
data
[]
byte
,
v
interface
{})
(
err
error
)
{
if
pm
,
ok
:=
v
.
(
proto
.
Message
);
ok
{
b
:=
bytes
.
NewBuffer
(
data
)
...
...
This diff is collapsed.
Click to expand it.
protocol/grpc/config.go
+
9
−
9
View file @
96c699aa
...
...
@@ -22,44 +22,44 @@ import (
)
type
(
// ServerConfig
// ServerConfig
currently is empty struct,for future expansion
ServerConfig
struct
{
}
// ClientConfig
// ClientConfig
wrap client call parameters
ClientConfig
struct
{
// content type, more information refer by https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests
ContentSubType
string
`default:"proto" yaml:"content_sub_type" json:"content_sub_type,omitempty"`
}
)
// GetDefaultClientConfig
...
// GetDefaultClientConfig
return grpc client default call options
func
GetDefaultClientConfig
()
ClientConfig
{
return
ClientConfig
{
ContentSubType
:
CODEC_PROTO
,
ContentSubType
:
codecProto
,
}
}
// GetDefaultServerConfig
...
// GetDefaultServerConfig
currently return empty struct,for future expansion
func
GetDefaultServerConfig
()
ServerConfig
{
return
ServerConfig
{}
}
// GetClientConfig
...
// GetClientConfig
return grpc client custom call options
func
GetClientConfig
()
ClientConfig
{
return
ClientConfig
{}
}
//
clientConfig Validate ...
//
Validate check if custom config encoding is supported in dubbo grpc
func
(
c
*
ClientConfig
)
Validate
()
error
{
if
c
.
ContentSubType
!=
CODEC_JSON
&&
c
.
ContentSubType
!=
CODEC_PROTO
{
if
c
.
ContentSubType
!=
codecJson
&&
c
.
ContentSubType
!=
codecProto
{
return
perrors
.
Errorf
(
" dubbo-go grpc codec currently only support proto、json, %s isn't supported,"
+
" please check protocol content_sub_type config"
,
c
.
ContentSubType
)
}
return
nil
}
//
severConfig Validate ...
//
Validate currently return empty struct,for future expansion
func
(
c
*
ServerConfig
)
Validate
()
error
{
return
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment