Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
ulfssar-go
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Faizal Aziz
ulfssar-go
Commits
3f8fd14e
Commit
3f8fd14e
authored
Jun 20, 2024
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update client.go
parent
8c00a559
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
41 deletions
+41
-41
client.go
pkg/http-client/client.go
+41
-41
No files found.
pkg/http-client/client.go
View file @
3f8fd14e
...
@@ -63,8 +63,8 @@ type (
...
@@ -63,8 +63,8 @@ type (
}
}
)
)
func
(
c
*
client
)
GetWithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
GetWithProxy
(
ctx
*
context
.
UlfsaarContext
,
urls
,
ip
,
port
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
urls
:=
c
.
options
.
Address
+
path
//
urls := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
var
stringProxUrl
string
var
stringProxUrl
string
proxUrl
,
err
:=
url
.
Parse
(
fmt
.
Sprintf
(
"http://%s:%s"
,
ip
,
port
))
proxUrl
,
err
:=
url
.
Parse
(
fmt
.
Sprintf
(
"http://%s:%s"
,
ip
,
port
))
...
@@ -102,8 +102,8 @@ func (c *client) GetWithProxy(ctx *context.UlfsaarContext, path, ip, port string
...
@@ -102,8 +102,8 @@ func (c *client) GetWithProxy(ctx *context.UlfsaarContext, path, ip, port string
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
GetWithProxyAuth
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
GetWithProxyAuth
(
ctx
*
context
.
UlfsaarContext
,
urls
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
urls
:=
c
.
options
.
Address
+
path
//
urls := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
var
stringProxUrl
string
var
stringProxUrl
string
proxUrl
,
err
:=
url
.
Parse
(
fmt
.
Sprintf
(
"http://%s:%s@%s:%s"
,
username
,
password
,
ip
,
port
))
proxUrl
,
err
:=
url
.
Parse
(
fmt
.
Sprintf
(
"http://%s:%s@%s:%s"
,
username
,
password
,
ip
,
port
))
...
@@ -150,8 +150,8 @@ func (c *client) SetTimeout(timeout time.Duration) {
...
@@ -150,8 +150,8 @@ func (c *client) SetTimeout(timeout time.Duration) {
return
return
}
}
func
(
c
*
client
)
PostWithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
PostWithProxy
(
ctx
*
context
.
UlfsaarContext
,
uri
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
uri
:=
c
.
options
.
Address
+
path
//
uri := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
var
stringProxUrl
string
var
stringProxUrl
string
...
@@ -196,8 +196,8 @@ func (c *client) PostWithProxy(ctx *context.UlfsaarContext, path, ip, port, user
...
@@ -196,8 +196,8 @@ func (c *client) PostWithProxy(ctx *context.UlfsaarContext, path, ip, port, user
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
Post
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
Post
(
ctx
*
context
.
UlfsaarContext
,
url
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
//
url := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
request
:=
c
.
httpClient
.
R
()
request
:=
c
.
httpClient
.
R
()
...
@@ -234,22 +234,29 @@ func (c *client) Post(ctx *context.UlfsaarContext, path string, headers http.Hea
...
@@ -234,22 +234,29 @@ func (c *client) Post(ctx *context.UlfsaarContext, path string, headers http.Hea
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
PostFormData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
PostFormData
WithProxy
(
ctx
*
context
.
UlfsaarContext
,
Url
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
,
payload
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
u
rl
:=
c
.
options
.
Address
+
path
//U
rl := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
var
stringProxUrl
string
proxUrl
,
err
:=
url
.
Parse
(
fmt
.
Sprintf
(
"https://%s:%s@%s:%s"
,
username
,
password
,
ip
,
port
))
if
err
!=
nil
{
stringProxUrl
=
fmt
.
Sprintf
(
"https://%s:%s@%s:%s"
,
username
,
password
,
ip
,
port
)
}
else
{
stringProxUrl
=
proxUrl
.
String
()
}
request
:=
c
.
httpClient
.
R
()
request
:=
c
.
httpClient
.
SetProxy
(
stringProxUrl
)
.
R
()
request
.
SetFormData
(
payload
)
for
h
,
val
:=
range
headers
{
for
h
,
val
:=
range
headers
{
request
.
Header
[
h
]
=
val
request
.
Header
[
h
]
=
val
}
}
request
.
SetFormData
(
payload
)
if
headers
[
ContentType
]
==
nil
{
if
headers
[
ContentType
]
==
nil
{
request
.
Header
.
Set
(
ContentType
,
ApplicationJSON
)
request
.
Header
.
Set
(
ContentType
,
ApplicationJSON
)
}
}
request
.
Header
.
Set
(
UserAgent
,
UserAgentValue
)
httpResp
,
httpErr
:=
request
.
Post
(
u
rl
)
httpResp
,
httpErr
:=
request
.
Post
(
U
rl
)
if
httpResp
!=
nil
{
if
httpResp
!=
nil
{
body
=
httpResp
.
Body
()
body
=
httpResp
.
Body
()
...
@@ -258,7 +265,7 @@ func (c *client) PostFormData(ctx *context.UlfsaarContext, path string, headers
...
@@ -258,7 +265,7 @@ func (c *client) PostFormData(ctx *context.UlfsaarContext, path string, headers
}
}
ctx
.
Info
(
"PostFormData"
,
ctx
.
Info
(
"PostFormData"
,
logger
.
ToField
(
urlKey
,
u
rl
),
logger
.
ToField
(
urlKey
,
U
rl
),
logger
.
ToField
(
requestKey
,
toRequest
(
request
.
Header
,
payload
)),
logger
.
ToField
(
requestKey
,
toRequest
(
request
.
Header
,
payload
)),
logger
.
ToField
(
responseKey
,
toResponse
(
statusCode
,
respHeader
,
body
)),
logger
.
ToField
(
responseKey
,
toResponse
(
statusCode
,
respHeader
,
body
)),
logger
.
ToField
(
startProcessingTimeKey
,
startProcessingTime
(
startTime
)),
logger
.
ToField
(
startProcessingTimeKey
,
startProcessingTime
(
startTime
)),
...
@@ -272,29 +279,22 @@ func (c *client) PostFormData(ctx *context.UlfsaarContext, path string, headers
...
@@ -272,29 +279,22 @@ func (c *client) PostFormData(ctx *context.UlfsaarContext, path string, headers
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
PostFormData
WithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
,
payload
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
PostFormData
(
ctx
*
context
.
UlfsaarContext
,
url
string
,
headers
http
.
Header
,
payload
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
searchU
rl
:=
c
.
options
.
Address
+
path
//u
rl := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
var
stringProxUrl
string
proxUrl
,
err
:=
url
.
Parse
(
fmt
.
Sprintf
(
"https://%s:%s@%s:%s"
,
username
,
password
,
ip
,
port
))
if
err
!=
nil
{
stringProxUrl
=
fmt
.
Sprintf
(
"https://%s:%s@%s:%s"
,
username
,
password
,
ip
,
port
)
}
else
{
stringProxUrl
=
proxUrl
.
String
()
}
request
:=
c
.
httpClient
.
SetProxy
(
stringProxUrl
)
.
R
()
request
:=
c
.
httpClient
.
R
()
request
.
SetFormData
(
payload
)
for
h
,
val
:=
range
headers
{
for
h
,
val
:=
range
headers
{
request
.
Header
[
h
]
=
val
request
.
Header
[
h
]
=
val
}
}
request
.
SetFormData
(
payload
)
if
headers
[
ContentType
]
==
nil
{
if
headers
[
ContentType
]
==
nil
{
request
.
Header
.
Set
(
ContentType
,
ApplicationJSON
)
request
.
Header
.
Set
(
ContentType
,
ApplicationJSON
)
}
}
request
.
Header
.
Set
(
UserAgent
,
UserAgentValue
)
httpResp
,
httpErr
:=
request
.
Post
(
searchU
rl
)
httpResp
,
httpErr
:=
request
.
Post
(
u
rl
)
if
httpResp
!=
nil
{
if
httpResp
!=
nil
{
body
=
httpResp
.
Body
()
body
=
httpResp
.
Body
()
...
@@ -303,7 +303,7 @@ func (c *client) PostFormDataWithProxy(ctx *context.UlfsaarContext, path, ip, po
...
@@ -303,7 +303,7 @@ func (c *client) PostFormDataWithProxy(ctx *context.UlfsaarContext, path, ip, po
}
}
ctx
.
Info
(
"PostFormData"
,
ctx
.
Info
(
"PostFormData"
,
logger
.
ToField
(
urlKey
,
searchU
rl
),
logger
.
ToField
(
urlKey
,
u
rl
),
logger
.
ToField
(
requestKey
,
toRequest
(
request
.
Header
,
payload
)),
logger
.
ToField
(
requestKey
,
toRequest
(
request
.
Header
,
payload
)),
logger
.
ToField
(
responseKey
,
toResponse
(
statusCode
,
respHeader
,
body
)),
logger
.
ToField
(
responseKey
,
toResponse
(
statusCode
,
respHeader
,
body
)),
logger
.
ToField
(
startProcessingTimeKey
,
startProcessingTime
(
startTime
)),
logger
.
ToField
(
startProcessingTimeKey
,
startProcessingTime
(
startTime
)),
...
@@ -317,8 +317,8 @@ func (c *client) PostFormDataWithProxy(ctx *context.UlfsaarContext, path, ip, po
...
@@ -317,8 +317,8 @@ func (c *client) PostFormDataWithProxy(ctx *context.UlfsaarContext, path, ip, po
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
PostMultipartFormFilesAndData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
formData
[]
*
MultipartField
,
formFiles
[]
MultipartFileRequest
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
PostMultipartFormFilesAndData
(
ctx
*
context
.
UlfsaarContext
,
url
string
,
headers
http
.
Header
,
formData
[]
*
MultipartField
,
formFiles
[]
MultipartFileRequest
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
//
url := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
request
:=
c
.
httpClient
.
R
()
request
:=
c
.
httpClient
.
R
()
...
@@ -358,8 +358,8 @@ func (c *client) PostMultipartFormFilesAndData(ctx *context.UlfsaarContext, path
...
@@ -358,8 +358,8 @@ func (c *client) PostMultipartFormFilesAndData(ctx *context.UlfsaarContext, path
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
Put
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
Put
(
ctx
*
context
.
UlfsaarContext
,
url
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
//
url := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
request
:=
c
.
httpClient
.
R
()
request
:=
c
.
httpClient
.
R
()
...
@@ -397,8 +397,8 @@ func (c *client) Put(ctx *context.UlfsaarContext, path string, headers http.Head
...
@@ -397,8 +397,8 @@ func (c *client) Put(ctx *context.UlfsaarContext, path string, headers http.Head
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
Get
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
Get
(
ctx
*
context
.
UlfsaarContext
,
url
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
//
url := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
request
:=
c
.
httpClient
.
R
()
request
:=
c
.
httpClient
.
R
()
...
@@ -431,8 +431,8 @@ func (c *client) Get(ctx *context.UlfsaarContext, path string, headers http.Head
...
@@ -431,8 +431,8 @@ func (c *client) Get(ctx *context.UlfsaarContext, path string, headers http.Head
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
GetWithQueryParam
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
queryParam
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
GetWithQueryParam
(
ctx
*
context
.
UlfsaarContext
,
url
string
,
headers
http
.
Header
,
queryParam
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
//
url := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
request
:=
c
.
httpClient
.
R
()
request
:=
c
.
httpClient
.
R
()
...
@@ -466,8 +466,8 @@ func (c *client) GetWithQueryParam(ctx *context.UlfsaarContext, path string, hea
...
@@ -466,8 +466,8 @@ func (c *client) GetWithQueryParam(ctx *context.UlfsaarContext, path string, hea
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
Delete
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
Delete
(
ctx
*
context
.
UlfsaarContext
,
url
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
//
url := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
request
:=
c
.
httpClient
.
R
()
request
:=
c
.
httpClient
.
R
()
...
@@ -502,8 +502,8 @@ func (c *client) Delete(ctx *context.UlfsaarContext, path string, headers http.H
...
@@ -502,8 +502,8 @@ func (c *client) Delete(ctx *context.UlfsaarContext, path string, headers http.H
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
Patch
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
Patch
(
ctx
*
context
.
UlfsaarContext
,
url
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
//
url := c.options.Address + path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
request
:=
c
.
httpClient
.
R
()
request
:=
c
.
httpClient
.
R
()
...
...
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