From ff4fba7a438c26b74d4f17126085fc747030be99 Mon Sep 17 00:00:00 2001 From: Rogee Date: Mon, 15 Dec 2025 11:17:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=BB=A5=E6=94=AF=E6=8C=81=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=8C=96=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/providers/job/provider.go.tpl | 2 +- templates/providers/req/client.go.tpl | 202 +++++++++--------- 2 files changed, 102 insertions(+), 102 deletions(-) diff --git a/templates/project/providers/job/provider.go.tpl b/templates/project/providers/job/provider.go.tpl index a35d3cb..76acfce 100644 --- a/templates/project/providers/job/provider.go.tpl +++ b/templates/project/providers/job/provider.go.tpl @@ -6,7 +6,7 @@ import ( "sync" "time" - "test/providers/postgres" + "{{.ModuleName}}/providers/postgres" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgxpool" diff --git a/templates/providers/req/client.go.tpl b/templates/providers/req/client.go.tpl index dec20e8..521bb7c 100644 --- a/templates/providers/req/client.go.tpl +++ b/templates/providers/req/client.go.tpl @@ -1,21 +1,21 @@ package req import ( - "context" - "io" - "net/http" - "net/url" - "os" - "path/filepath" - "strconv" - "strings" - "time" + "context" + "io" + "net/http" + "net/url" + "os" + "path/filepath" + "strconv" + "strings" + "time" - "test/providers/req/cookiejar" + "{{.ModuleName}}/providers/req/cookiejar" - "github.com/imroc/req/v3" - "go.ipao.vip/atom/container" - "go.ipao.vip/atom/opt" + "github.com/imroc/req/v3" + "go.ipao.vip/atom/container" + "go.ipao.vip/atom/opt" ) type Client struct { @@ -64,25 +64,25 @@ func Provide(opts ...opt.Option) error { client.EnableInsecureSkipVerify() } - if config.UserAgent != "" { - client.SetUserAgent(config.UserAgent) - } - if config.BaseURL != "" { - client.SetBaseURL(config.BaseURL) - } - if config.Timeout > 0 { - client.SetTimeout(time.Duration(config.Timeout) * time.Second) - } + if config.UserAgent != "" { + client.SetUserAgent(config.UserAgent) + } + if config.BaseURL != "" { + client.SetBaseURL(config.BaseURL) + } + if config.Timeout > 0 { + client.SetTimeout(time.Duration(config.Timeout) * time.Second) + } - if config.CommonHeaders != nil { - client.SetCommonHeaders(config.CommonHeaders) - } - if config.CommonQuery != nil { - client.SetCommonQueryParams(config.CommonQuery) - } - if config.ContentType != "" { - client.SetCommonContentType(config.ContentType) - } + if config.CommonHeaders != nil { + client.SetCommonHeaders(config.CommonHeaders) + } + if config.CommonQuery != nil { + client.SetCommonQueryParams(config.CommonQuery) + } + if config.ContentType != "" { + client.SetCommonContentType(config.ContentType) + } if config.AuthBasic.Username != "" && config.AuthBasic.Password != "" { client.SetCommonBasicAuth(config.AuthBasic.Username, config.AuthBasic.Password) @@ -100,12 +100,12 @@ func Provide(opts ...opt.Option) error { client.SetRedirectPolicy(parsePolicies(config.RedirectPolicy)...) } - c.client = client - if c.jar != nil { - container.AddCloseAble(func() { _ = c.jar.Save() }) - } - return c, nil - }, o.DiOptions()...) + c.client = client + if c.jar != nil { + container.AddCloseAble(func() { _ = c.jar.Save() }) + } + return c, nil + }, o.DiOptions()...) } func parsePolicies(policies []string) []req.RedirectPolicy { @@ -140,11 +140,11 @@ func parsePolicies(policies []string) []req.RedirectPolicy { } func (c *Client) R() *req.Request { - return c.client.R() + return c.client.R() } func (c *Client) RWithCtx(ctx context.Context) *req.Request { - return c.client.R().SetContext(ctx) + return c.client.R().SetContext(ctx) } func (c *Client) SaveCookJar() error { @@ -166,78 +166,78 @@ func (c *Client) AllCookiesKV() map[string]string { } func (c *Client) SetCookie(u *url.URL, cookies []*http.Cookie) { - c.jar.SetCookies(u, cookies) + c.jar.SetCookies(u, cookies) } func (c *Client) DoJSON(ctx context.Context, method, url string, in any, out any) error { - r := c.RWithCtx(ctx) - if in != nil { - r.SetBody(in) - } - if out != nil { - r.SetSuccessResult(out) - } - var resp *req.Response - var err error - switch strings.ToUpper(method) { - case http.MethodGet: - resp, err = r.Get(url) - case http.MethodPost: - resp, err = r.Post(url) - case http.MethodPut: - resp, err = r.Put(url) - case http.MethodPatch: - resp, err = r.Patch(url) - case http.MethodDelete: - resp, err = r.Delete(url) - default: - resp, err = r.Send(method, url) - } - if err != nil { - return err - } - return resp.Err + r := c.RWithCtx(ctx) + if in != nil { + r.SetBody(in) + } + if out != nil { + r.SetSuccessResult(out) + } + var resp *req.Response + var err error + switch strings.ToUpper(method) { + case http.MethodGet: + resp, err = r.Get(url) + case http.MethodPost: + resp, err = r.Post(url) + case http.MethodPut: + resp, err = r.Put(url) + case http.MethodPatch: + resp, err = r.Patch(url) + case http.MethodDelete: + resp, err = r.Delete(url) + default: + resp, err = r.Send(method, url) + } + if err != nil { + return err + } + return resp.Err } func (c *Client) GetJSON(ctx context.Context, url string, out any, query map[string]string) error { - r := c.RWithCtx(ctx) - if query != nil { - r.SetQueryParams(query) - } - r.SetSuccessResult(out) - resp, err := r.Get(url) - if err != nil { - return err - } - return resp.Err + r := c.RWithCtx(ctx) + if query != nil { + r.SetQueryParams(query) + } + r.SetSuccessResult(out) + resp, err := r.Get(url) + if err != nil { + return err + } + return resp.Err } func (c *Client) PostJSON(ctx context.Context, url string, in any, out any) error { - r := c.RWithCtx(ctx) - if in != nil { - r.SetBody(in) - } - if out != nil { - r.SetSuccessResult(out) - } - resp, err := r.Post(url) - if err != nil { - return err - } - return resp.Err + r := c.RWithCtx(ctx) + if in != nil { + r.SetBody(in) + } + if out != nil { + r.SetSuccessResult(out) + } + resp, err := r.Post(url) + if err != nil { + return err + } + return resp.Err } func (c *Client) Download(ctx context.Context, url, filepath string) error { - r := c.RWithCtx(ctx) - resp, err := r.Get(url) - if err != nil { - return err - } - f, err := os.Create(filepath) - if err != nil { - return err - } - defer f.Close() - _, err = io.Copy(f, resp.Body) - return err + r := c.RWithCtx(ctx) + resp, err := r.Get(url) + if err != nil { + return err + } + f, err := os.Create(filepath) + if err != nil { + return err + } + defer f.Close() + _, err = io.Copy(f, resp.Body) + return err }