-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 重构了图书馆相关接口, 封装了request, 实现了请求日志
- Loading branch information
Showing
10 changed files
with
107 additions
and
86 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package request | ||
|
||
import ( | ||
"funnel/app/service/libraryService/request/midware" | ||
"github.com/go-resty/resty/v2" | ||
) | ||
|
||
type Client struct { | ||
*resty.Client | ||
} | ||
|
||
func New() Client { | ||
s := Client{ | ||
Client: resty.New(), | ||
} | ||
// 利用中间件实现请求日志 | ||
s.OnAfterResponse(midware.LogMiddleware) | ||
return s | ||
} | ||
|
||
func (s Client) Request() *resty.Request { | ||
return s.R(). | ||
EnableTrace(). | ||
SetHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36") | ||
} |
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,19 @@ | ||
package midware | ||
|
||
import ( | ||
"fmt" | ||
"github.com/go-resty/resty/v2" | ||
) | ||
|
||
// LogMiddleware 日志中间件 | ||
func LogMiddleware(client *resty.Client, resp *resty.Response) error { | ||
fmt.Println("==================================================================") | ||
method := resp.Request.Method | ||
url := resp.Request.URL | ||
fmt.Printf("%s %s \n", method, url) | ||
//fmt.Println(resp.Request.Header) | ||
//fmt.Println(resp) | ||
fmt.Printf("Time Spent: %v\n", resp.Time()) | ||
|
||
return 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
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
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