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

enhance(workers): add list filters for GetAll #279

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion vela/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import (
// the server methods of the Vela API.
type WorkerService service

// WorkerListOptions specifies the optional parameters to the
// Worker.GetAll method.
type WorkerListOptions struct {
Active string `url:"active,omitempty"`
CheckedInBefore int64 `url:"checked_in_before,omitempty"`
CheckedInAfter int64 `url:"checked_in_after,omitempty"`
}

// Get returns the provided worker.
func (svc *WorkerService) Get(hostname string) (*library.Worker, *Response, error) {
// set the API endpoint path we send the request to
Expand All @@ -27,10 +35,16 @@ func (svc *WorkerService) Get(hostname string) (*library.Worker, *Response, erro
}

// GetAll returns a list of all workers.
func (svc *WorkerService) GetAll() (*[]library.Worker, *Response, error) {
func (svc *WorkerService) GetAll(opt *WorkerListOptions) (*[]library.Worker, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/workers"

// add optional arguments if supplied
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}

// slice library Worker type we want to return
v := new([]library.Worker)

Expand Down
4 changes: 2 additions & 2 deletions vela/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestWorker_GetAll_200(t *testing.T) {
_ = json.Unmarshal(data, &want)

// run test
got, resp, err := c.Worker.GetAll()
got, resp, err := c.Worker.GetAll(nil)

if err != nil {
t.Errorf("Worker get all returned err: %v", err)
Expand Down Expand Up @@ -312,7 +312,7 @@ func ExampleWorkerService_GetAll() {
c.Authentication.SetPersonalAccessTokenAuth("token")

// Get all the workers from the server
workers, resp, err := c.Worker.GetAll()
workers, resp, err := c.Worker.GetAll(nil)
if err != nil {
fmt.Println(err)
}
Expand Down