-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* set http client * set http protocol by default * set default host & protocol * add request handler * add req handler mocks * add `TestGetProfileStatus` * add some tests * add `TestSetProfileStatus` * add `TestGetOwnContact` * add `TestSetProfileStatusUnsuccess` * add `TestCheckClientConnection` * add `TestUseVoucher` * add tests * add `TestGetBalance` * Update client_test.go * add `TestSetWebSocket` * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * do not check connection in method * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * check amount and address is set * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Update client_test.go * Create request_test.go * Create log_test.go * add new conn error variants
- Loading branch information
Showing
16 changed files
with
921 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.PHONY: generate-mocks | ||
generate-mocks: | ||
mockgen -package=bots -source=./v2/internal/reqhandler/reqhandler.go > ./v2/internal/mocks/mock_reqhandler.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package reqhandler | ||
|
||
import "net/http" | ||
|
||
func closeRequest(resp *http.Response) { | ||
if resp != nil { | ||
resp.Body.Close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package reqhandler | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type RequestHandler interface { | ||
Send(reqType, URL string, data []byte) ([]byte, error) | ||
} | ||
|
||
type defaultHandler struct { | ||
client *http.Client | ||
} | ||
|
||
func NewDefaultHandler(timeout time.Duration) RequestHandler { | ||
return &defaultHandler{ | ||
client: &http.Client{Timeout: timeout}, | ||
} | ||
} | ||
|
||
func (h *defaultHandler) Send(reqType, URL string, data []byte) ([]byte, error) { | ||
|
||
req, err := http.NewRequest(reqType, URL, bytes.NewBuffer(data)) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create request: %w", err) | ||
} | ||
req.Header.Set("Content-Type", "application/json") | ||
|
||
resp, err := h.client.Do(req) | ||
defer closeRequest(resp) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to send request: %w", err) | ||
} | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read response body: %w", err) | ||
} | ||
|
||
return body, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.