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
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
jrpc
Commits
076f0f2f
Verified
Commit
076f0f2f
authored
Jul 20, 2023
by
a
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
6bdf3a7c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
contrib/openrpc/out/example/main.go
+1
-1
1 addition, 1 deletion
contrib/openrpc/out/example/main.go
pkg/codec/json.go
+0
-53
0 additions, 53 deletions
pkg/codec/json.go
pkg/codec/reqresp.go
+0
-5
0 additions, 5 deletions
pkg/codec/reqresp.go
with
1 addition
and
59 deletions
contrib/openrpc/out/example/main.go
+
1
−
1
View file @
076f0f2f
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"gfx.cafe/open/jrpc"
"gfx.cafe/open/jrpc"
"gfx.cafe/open/jrpc/contrib/codecs"
"gfx.cafe/open/jrpc/contrib/codecs"
"gfx.cafe/open/jrpc/contrib/jmux"
"gfx.cafe/open/jrpc/contrib/jmux"
"gfx.cafe/open/jrpc/openrpc/out"
"gfx.cafe/open/jrpc/
contrib/
openrpc/out"
)
)
func
main
()
{
func
main
()
{
...
...
This diff is collapsed.
Click to expand it.
pkg/codec/json.go
+
0
−
53
View file @
076f0f2f
...
@@ -75,42 +75,11 @@ func (msg *Message) isNotification() bool {
...
@@ -75,42 +75,11 @@ func (msg *Message) isNotification() bool {
return
msg
.
ID
==
nil
&&
len
(
msg
.
Method
)
>
0
return
msg
.
ID
==
nil
&&
len
(
msg
.
Method
)
>
0
}
}
func
(
msg
*
Message
)
isCall
()
bool
{
return
msg
.
hasValidID
()
&&
len
(
msg
.
Method
)
>
0
}
func
(
msg
*
Message
)
isResponse
()
bool
{
return
msg
.
hasValidID
()
&&
len
(
msg
.
Method
)
==
0
&&
msg
.
Params
==
nil
&&
(
msg
.
Result
!=
nil
||
msg
.
Error
!=
nil
)
}
func
(
msg
*
Message
)
hasValidID
()
bool
{
return
msg
.
ID
!=
nil
&&
!
msg
.
ID
.
IsNull
()
}
func
(
msg
*
Message
)
String
()
string
{
func
(
msg
*
Message
)
String
()
string
{
b
,
_
:=
json
.
Marshal
(
msg
)
b
,
_
:=
json
.
Marshal
(
msg
)
return
string
(
b
)
return
string
(
b
)
}
}
func
(
msg
*
Message
)
ErrorResponse
(
err
error
)
*
Message
{
resp
:=
ErrorMessage
(
err
)
if
resp
.
ID
!=
nil
{
resp
.
ID
=
msg
.
ID
}
return
resp
}
func
(
msg
*
Message
)
response
(
result
any
)
*
Message
{
// do a funny marshaling
enc
,
err
:=
gojson
.
Marshal
(
result
)
if
err
!=
nil
{
return
msg
.
ErrorResponse
(
err
)
}
if
len
(
enc
)
==
0
{
enc
=
[]
byte
(
"null"
)
}
return
&
Message
{
ID
:
msg
.
ID
,
Result
:
enc
}
}
// encapsulate json rpc error into struct
// encapsulate json rpc error into struct
type
JsonError
struct
{
type
JsonError
struct
{
Code
int
`json:"code"`
Code
int
`json:"code"`
...
@@ -133,28 +102,6 @@ func (err *JsonError) ErrorData() any {
...
@@ -133,28 +102,6 @@ func (err *JsonError) ErrorData() any {
return
err
.
Data
return
err
.
Data
}
}
// error message produces json rpc message with error message
func
ErrorMessage
(
err
error
)
*
Message
{
if
err
==
nil
{
return
nil
}
msg
:=
&
Message
{
ID
:
NewNullIDPtr
(),
Error
:
&
JsonError
{
Code
:
ErrorCodeDefault
,
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
}
// isBatch returns true when the first non-whitespace characters is '['
// isBatch returns true when the first non-whitespace characters is '['
func
IsBatchMessage
(
raw
json
.
RawMessage
)
bool
{
func
IsBatchMessage
(
raw
json
.
RawMessage
)
bool
{
for
_
,
c
:=
range
raw
{
for
_
,
c
:=
range
raw
{
...
...
This diff is collapsed.
Click to expand it.
pkg/codec/reqresp.go
+
0
−
5
View file @
076f0f2f
...
@@ -113,11 +113,6 @@ func NewNotification(ctx context.Context, method string, params any) *Request {
...
@@ -113,11 +113,6 @@ func NewNotification(ctx context.Context, method string, params any) *Request {
return
r
return
r
}
}
func
(
r
*
Request
)
makeError
(
err
error
)
*
Message
{
m
:=
r
.
Msg
()
return
m
.
ErrorResponse
(
err
)
}
func
(
r
*
Request
)
isNotification
()
bool
{
func
(
r
*
Request
)
isNotification
()
bool
{
return
r
.
ID
==
nil
&&
len
(
r
.
Method
)
>
0
return
r
.
ID
==
nil
&&
len
(
r
.
Method
)
>
0
}
}
...
...
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