diff --git a/vela/worker.go b/vela/worker.go index fca6d1e..9985ba1 100644 --- a/vela/worker.go +++ b/vela/worker.go @@ -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 @@ -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) diff --git a/vela/worker_test.go b/vela/worker_test.go index bdf8a09..82b8624 100644 --- a/vela/worker_test.go +++ b/vela/worker_test.go @@ -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) @@ -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) }