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
2027c978
Commit
2027c978
authored
Dec 13, 2023
by
Faizal Aziz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding get with proxy to resty client
parent
4da79a81
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
client.go
pkg/http-client/client.go
+37
-0
No files found.
pkg/http-client/client.go
View file @
2027c978
...
...
@@ -3,6 +3,8 @@ package http_client
import
(
"bytes"
"crypto/tls"
"encoding/base64"
"fmt"
"github.com/go-resty/resty/v2"
"gitlab.ursabyte.com/faizal.aziz/ulfssar-go/pkg/context"
"gitlab.ursabyte.com/faizal.aziz/ulfssar-go/pkg/logger"
...
...
@@ -46,6 +48,7 @@ type (
PostMultipartFormFilesAndData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
formData
[]
*
MultipartField
,
formFiles
[]
MultipartFileRequest
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
Put
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
Get
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
GetWithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
GetWithQueryParam
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
queryParam
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
Delete
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
Patch
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
...
...
@@ -57,6 +60,40 @@ type (
}
)
func
(
c
*
client
)
GetWithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
startTime
:=
time
.
Now
()
request
:=
c
.
httpClient
.
SetProxy
(
fmt
.
Sprintf
(
"%s:%s"
,
ip
,
port
))
.
R
()
for
h
,
val
:=
range
headers
{
request
.
Header
[
h
]
=
val
}
request
.
Header
.
Set
(
UserAgent
,
UserAgentValue
)
request
.
Header
.
Set
(
"Proxy-Authorization"
,
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
fmt
.
Sprintf
(
"%s:%s"
,
username
,
password
))))
httpResp
,
httpErr
:=
request
.
Get
(
url
)
if
httpResp
!=
nil
{
body
=
httpResp
.
Body
()
respHeader
=
httpResp
.
Header
()
statusCode
=
httpResp
.
StatusCode
()
}
ctx
.
Info
(
"Get"
,
logger
.
ToField
(
urlKey
,
url
),
logger
.
ToField
(
requestKey
,
toRequest
(
request
.
Header
,
nil
)),
logger
.
ToField
(
responseKey
,
toResponse
(
statusCode
,
respHeader
,
body
)),
logger
.
ToField
(
startProcessingTimeKey
,
startProcessingTime
(
startTime
)),
logger
.
ToField
(
processingTimeKey
,
processingTime
(
startTime
)),
)
if
statusCode
==
http
.
StatusOK
{
return
respHeader
,
statusCode
,
body
,
nil
}
return
respHeader
,
statusCode
,
body
,
httpErr
}
func
(
c
*
client
)
SetTimeout
(
timeout
time
.
Duration
)
{
c
.
httpClient
.
SetTimeout
(
timeout
)
return
...
...
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