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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
jrpc
Commits
f86836ec
Verified
Commit
f86836ec
authored
1 year ago
by
a
Browse files
Options
Downloads
Patches
Plain Diff
remove race
parent
180c42ba
No related branches found
Branches containing commit
Tags
v0.1.10
Tags containing commit
No related merge requests found
Pipeline
#25787
failed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/codecs/http/client.go
+40
-28
40 additions, 28 deletions
contrib/codecs/http/client.go
with
40 additions
and
28 deletions
contrib/codecs/http/client.go
+
40
−
28
View file @
f86836ec
...
...
@@ -63,13 +63,11 @@ func Dial(ctx context.Context, client *http.Client, target string) (*Client, err
}
func
(
c
*
Client
)
SetHeader
(
key
string
,
value
string
)
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
c
.
headers
.
Set
(
key
,
value
)
}
func
(
c
*
Client
)
Closed
()
<-
chan
struct
{}
{
return
make
(
chan
struct
{})
}
func
(
c
*
Client
)
Do
(
ctx
context
.
Context
,
result
any
,
method
string
,
params
any
)
error
{
req
,
err
:=
codec
.
NewRequest
(
ctx
,
codec
.
NewId
(
c
.
id
.
Add
(
1
)),
method
,
params
)
if
err
!=
nil
{
...
...
@@ -88,7 +86,6 @@ func (c *Client) Do(ctx context.Context, result any, method string, params any)
Body
:
b
,
}
}
// TODO: this can be reused
msg
:=
clientutil
.
GetMessage
()
defer
clientutil
.
PutMessage
(
msg
)
err
=
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
msg
)
...
...
@@ -107,28 +104,6 @@ func (c *Client) Do(ctx context.Context, result any, method string, params any)
return
nil
}
func
(
c
*
Client
)
post
(
req
*
codec
.
Request
)
(
*
http
.
Response
,
error
)
{
// TODO: use buffer for this
buf
:=
bufpool
.
GetStd
()
defer
bufpool
.
PutStd
(
buf
)
buf
.
Reset
()
err
:=
json
.
NewEncoder
(
buf
)
.
Encode
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
hreq
,
err
:=
http
.
NewRequestWithContext
(
req
.
Context
(),
http
.
MethodPost
,
c
.
remote
,
buf
)
if
err
!=
nil
{
return
nil
,
err
}
for
k
,
v
:=
range
c
.
headers
{
for
_
,
vv
:=
range
v
{
hreq
.
Header
.
Add
(
k
,
vv
)
}
}
c
.
headers
.
Add
(
"Content-Type"
,
"application/json"
)
return
c
.
c
.
Do
(
hreq
)
}
func
(
c
*
Client
)
Notify
(
ctx
context
.
Context
,
method
string
,
params
any
)
error
{
req
,
err
:=
codec
.
NewRequest
(
ctx
,
nil
,
method
,
params
)
if
err
!=
nil
{
...
...
@@ -163,7 +138,7 @@ func (c *Client) BatchCall(ctx context.Context, b ...*codec.BatchElem) error {
if
err
!=
nil
{
return
err
}
resp
,
err
:=
c
.
c
.
Post
(
c
.
remote
,
"application/json"
,
bytes
.
NewBuffer
(
dat
))
resp
,
err
:=
c
.
postBuf
(
ctx
,
bytes
.
NewBuffer
(
dat
))
if
err
!=
nil
{
return
err
}
...
...
@@ -186,3 +161,40 @@ func (c *Client) BatchCall(ctx context.Context, b ...*codec.BatchElem) error {
func
(
c
*
Client
)
Close
()
error
{
return
nil
}
func
(
c
*
Client
)
Closed
()
<-
chan
struct
{}
{
return
make
(
chan
struct
{})
}
func
(
c
*
Client
)
post
(
req
*
codec
.
Request
)
(
*
http
.
Response
,
error
)
{
// TODO: use buffer for this
buf
:=
bufpool
.
GetStd
()
defer
bufpool
.
PutStd
(
buf
)
buf
.
Reset
()
err
:=
json
.
NewEncoder
(
buf
)
.
Encode
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
return
c
.
postBuf
(
req
.
Context
(),
buf
)
}
func
(
c
*
Client
)
postBuf
(
ctx
context
.
Context
,
rd
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
if
ctx
==
nil
{
ctx
=
context
.
Background
()
}
hreq
,
err
:=
http
.
NewRequestWithContext
(
ctx
,
http
.
MethodPost
,
c
.
remote
,
rd
)
if
err
!=
nil
{
return
nil
,
err
}
func
()
{
c
.
mu
.
RLock
()
defer
c
.
mu
.
RUnlock
()
for
k
,
v
:=
range
c
.
headers
{
for
_
,
vv
:=
range
v
{
hreq
.
Header
.
Add
(
k
,
vv
)
}
}
}()
hreq
.
Header
.
Add
(
"Content-Type"
,
"application/json"
)
return
c
.
c
.
Do
(
hreq
)
}
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