good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jrpc
Manage
Activity
Members
Labels
Plan
Issues
6
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
4
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
jrpc
Commits
013f2541
Commit
013f2541
authored
2 years ago
by
a
Browse files
Options
Downloads
Patches
Plain Diff
remove extra interfaces
parent
c5bc6bc5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
json.go
+23
-33
23 additions, 33 deletions
json.go
with
23 additions
and
33 deletions
json.go
+
23
−
33
View file @
013f2541
...
...
@@ -99,24 +99,7 @@ func (msg *jsonrpcMessage) response(result any) *jsonrpcMessage {
return
&
jsonrpcMessage
{
ID
:
msg
.
ID
,
Result
:
enc
}
}
func
errorMessage
(
err
error
)
*
jsonrpcMessage
{
msg
:=
&
jsonrpcMessage
{
ID
:
NewNullIDPtr
(),
Error
:
&
jsonError
{
Code
:
defaultErrorCode
,
Message
:
err
.
Error
(),
}}
ec
,
ok
:=
err
.
(
Error
)
if
ok
{
msg
.
Error
.
Code
=
ec
.
ErrorCode
()
}
de
,
ok
:=
err
.
(
DataError
)
if
ok
{
msg
.
Error
.
Data
=
de
.
ErrorData
()
}
return
msg
}
// encapsulate json rpc error into struct
type
jsonError
struct
{
Code
int
`json:"code"`
Message
string
`json:"message"`
...
...
@@ -140,24 +123,31 @@ func (err *jsonError) ErrorData() any {
return
err
.
Data
}
// error message produces json rpc message with error message
func
errorMessage
(
err
error
)
*
jsonrpcMessage
{
msg
:=
&
jsonrpcMessage
{
ID
:
NewNullIDPtr
(),
Error
:
&
jsonError
{
Code
:
defaultErrorCode
,
Message
:
err
.
Error
(),
}}
ec
,
ok
:=
err
.
(
Error
)
if
ok
{
msg
.
Error
.
Code
=
ec
.
ErrorCode
()
}
de
,
ok
:=
err
.
(
DataError
)
if
ok
{
msg
.
Error
.
Data
=
de
.
ErrorData
()
}
return
msg
}
// Conn is a subset of the methods of net.Conn which are sufficient for ServerCodec.
type
Conn
interface
{
io
.
ReadWriteCloser
SetWriteDeadline
(
time
.
Time
)
error
}
type
deadlineCloser
interface
{
io
.
Closer
SetWriteDeadline
(
time
.
Time
)
error
}
// ConnRemoteAddr wraps the RemoteAddr operation, which returns a description
// of the peer address of a connection. If a Conn also implements ConnRemoteAddr, this
// description is used in log messages.
type
ConnRemoteAddr
interface
{
RemoteAddr
()
string
}
// jsonCodec reads and writes JSON-RPC messages to the underlying connection. It also has
// support for parsing arguments and serializing (result) objects.
type
jsonCodec
struct
{
...
...
@@ -168,14 +158,14 @@ type jsonCodec struct {
decode
func
(
v
any
)
error
// decoder to allow multiple transports
encMu
sync
.
Mutex
// guards the encoder
encode
func
(
v
any
)
error
// encoder to allow multiple transports
conn
deadlineCloser
conn
Conn
}
// NewFuncCodec creates a codec which uses the given functions to read and write. If conn
// implements ConnRemoteAddr, log messages will use it to include the remote address of
// the connection.
func
NewFuncCodec
(
conn
deadlineCloser
,
conn
Conn
,
encode
,
decode
func
(
v
any
)
error
,
closeFunc
func
()
error
,
)
ServerCodec
{
...
...
@@ -186,7 +176,7 @@ func NewFuncCodec(
decode
:
decode
,
conn
:
conn
,
}
if
ra
,
ok
:=
conn
.
(
ConnRemoteAddr
);
ok
{
if
ra
,
ok
:=
conn
.
(
interface
{
RemoteAddr
()
string
}
);
ok
{
codec
.
remote
=
ra
.
RemoteAddr
()
}
return
codec
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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