func NewTestConfig(client *godo.Client) *TestConfig { return &TestConfig{ Client: client, SSHFn: func(u, h, kp string, p int) doit.Runner { logrus.WithFields(logrus.Fields{ "user": u, "host": h, }).Info("ssh") return &doit.MockRunner{} }, v: viper.New(), } }
// PaginateResp paginates a Response. func PaginateResp(gen Generator) ([]interface{}, error) { opt := &godo.ListOptions{Page: 1, PerPage: 200} list := []interface{}{} for { items, resp, err := gen(opt) if err != nil { return nil, err } for _, i := range items { list = append(list, i) } if resp == nil || resp.Links.Pages == nil { break } if uStr := resp.Links.Pages.Next; len(uStr) > 0 { u, err := url.Parse(uStr) if err != nil { return nil, err } if viper.GetBool("debug") { log.WithFields(log.Fields{ "page.current": opt.Page, "page.per": opt.PerPage, }).Info("retrieving page") } pageStr := u.Query().Get("page") page, err := strconv.Atoi(pageStr) if err != nil { return nil, err } opt.Page = page continue } break } return list, nil }