Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
koko
Commits
3ed7a99f
Unverified
Commit
3ed7a99f
authored
Oct 31, 2019
by
Eric_Lee
Committed by
GitHub
Oct 31, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #132 from jumpserver/dev_bugfix
[Bugfix] fix unclosed fd issues
parents
4a509ca4
47105d55
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
3 deletions
+15
-3
client.go
pkg/common/client.go
+15
-3
No files found.
pkg/common/client.go
View file @
3ed7a99f
...
...
@@ -144,6 +144,9 @@ func (c *Client) NewRequest(method, url string, body interface{}, params []map[s
return
}
req
,
err
=
http
.
NewRequest
(
method
,
url
,
reader
)
if
err
!=
nil
{
return
req
,
err
}
c
.
SetReqHeaders
(
req
,
params
)
return
req
,
err
}
...
...
@@ -219,7 +222,7 @@ func (c *Client) PostForm(url string, data interface{}, res interface{}) (err er
default
:
attr
,
err
:=
json
.
Marshal
(
val
.
Field
(
i
)
.
Interface
())
if
err
!=
nil
{
return
nil
return
err
}
v
=
string
(
attr
)
}
...
...
@@ -229,6 +232,9 @@ func (c *Client) PostForm(url string, data interface{}, res interface{}) (err er
reader
:=
strings
.
NewReader
(
values
.
Encode
())
req
,
err
:=
http
.
NewRequest
(
"POST"
,
url
,
reader
)
if
err
!=
nil
{
return
err
}
req
.
Header
.
Set
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
return
nil
}
...
...
@@ -238,6 +244,7 @@ func (c *Client) UploadFile(url string, gFile string, res interface{}, params ..
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
buf
:=
new
(
bytes
.
Buffer
)
bodyWriter
:=
multipart
.
NewWriter
(
buf
)
gName
:=
filepath
.
Base
(
gFile
)
...
...
@@ -245,18 +252,23 @@ func (c *Client) UploadFile(url string, gFile string, res interface{}, params ..
if
err
!=
nil
{
return
err
}
_
,
err
=
io
.
Copy
(
part
,
f
)
if
_
,
err
=
io
.
Copy
(
part
,
f
);
err
!=
nil
{
return
err
}
err
=
bodyWriter
.
Close
()
if
err
!=
nil
{
return
err
}
url
=
c
.
parseUrl
(
url
,
params
)
req
,
err
:=
http
.
NewRequest
(
"POST"
,
url
,
buf
)
if
err
!=
nil
{
return
err
}
req
.
Header
.
Set
(
"Content-Type"
,
bodyWriter
.
FormDataContentType
())
c
.
SetReqHeaders
(
req
,
params
)
resp
,
err
:=
c
.
http
.
Do
(
req
)
if
err
!=
nil
{
return
return
err
}
defer
resp
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment