Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor curl job structure #60

Merged
merged 1 commit into from
Aug 8, 2023
Merged

Refactor curl job structure #60

merged 1 commit into from
Aug 8, 2023

Conversation

reugn
Copy link
Owner

@reugn reugn commented Aug 6, 2023

This PR revises the CurlJob struct as an alternative to the proposal in #59.

@codecov-commenter
Copy link

Codecov Report

Merging #60 (ab9d7b2) into master (cf2d2db) will increase coverage by 2.86%.
Report is 1 commits behind head on master.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   87.26%   90.13%   +2.86%     
==========================================
  Files           8        8              
  Lines         534      527       -7     
==========================================
+ Hits          466      475       +9     
+ Misses         45       33      -12     
+ Partials       23       19       -4     
Files Changed Coverage Δ
quartz/function_job.go 100.00% <ø> (+32.14%) ⬆️
quartz/job.go 100.00% <100.00%> (+10.93%) ⬆️

@oreillysean
Copy link
Contributor

Here are my 2 cents on this.

Firstly I think the code is good and of high quality. Developers get access to better response struct and they get to customise their request more but the trade off it they have to pass in a request. And NewCurlJobWithHTTPClient is very handy.

I think the issue is the BC break for NewCurlJob. That is really up to you to decide. It is often a pain breaking backwards compatibility however sometimes it has to be done. As the maintainer it is your decision.

If you want to maintain BC then you could try

func NewCurlJob(args ...interface{}) (*CurlJob, error) {
	if len(args) == 1 {
		req, ok := args[0].(*http.Request)
		if !ok {
			return nil, fmt.Errorf("expected *http.Request as single argument")
		}
		// Handle the request processing here
		_ = req
	} else if len(args) == 4 {
		method, ok1 := args[0].(string)
		url, ok2 := args[1].(string)
		body, ok3 := args[2].(string)
		headers, ok4 := args[3].(map[string]string)
		if !(ok1 && ok2 && ok3 && ok4) {
			return nil, fmt.Errorf("expected string, string, string, map[string]string arguments")
		}
		// Handle the original processing here using method, url, body, headers
		_ = method
		_ = url
		_ = body
		_ = headers
	} else {
		return nil, fmt.Errorf("invalid argument count or types")
	}

I know it is ugly but it's all I've got @reugn

@reugn reugn merged commit 485d76b into master Aug 8, 2023
@reugn reugn deleted the refactor-curl-job branch August 8, 2023 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants