Skip to content
Permalink
Browse files
Allow setting default options (#85)
Using it looks like this:

```
// Create a new API client
cs := cloudstack.NewAsyncClient("https://cloudstack.company.com", "your-api-key", "your-api-secret", false)

// Set an option
cs.DefaultOptions(WithProject(“project”))

// Or set multiple options
cs.DefautlOptions(WithProject(“project”), WithVPCID(“xxxx”))
```
  • Loading branch information
Sander van Harmelen committed Jan 13, 2018
1 parent c815114 commit 1ab415ce0306dadd2f38c6934696c455c2d8183c
Showing 46 changed files with 146 additions and 124 deletions.
@@ -1146,7 +1146,7 @@ func (s *AccountService) GetAccountID(name string, opts ...OptionFunc) (string,

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -1196,7 +1196,7 @@ func (s *AccountService) GetAccountByID(id string, opts ...OptionFunc) (*Account

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1749,7 +1749,7 @@ func (s *AccountService) GetProjectAccountID(keyword string, projectid string, o
p.p["keyword"] = keyword
p.p["projectid"] = projectid

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -589,7 +589,7 @@ func (s *AddressService) GetPublicIpAddressByID(id string, opts ...OptionFunc) (

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -435,7 +435,7 @@ func (s *AffinityGroupService) GetAffinityGroupID(name string, opts ...OptionFun

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -489,7 +489,7 @@ func (s *AffinityGroupService) GetAffinityGroupByID(id string, opts ...OptionFun

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -119,7 +119,7 @@ func (s *AlertService) GetAlertID(name string, opts ...OptionFunc) (string, int,

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -169,7 +169,7 @@ func (s *AlertService) GetAlertByID(id string, opts ...OptionFunc) (*Alert, int,

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1150,7 +1150,7 @@ func (s *AutoScaleService) GetCounterID(name string, opts ...OptionFunc) (string

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -1200,7 +1200,7 @@ func (s *AutoScaleService) GetCounterByID(id string, opts ...OptionFunc) (*Count

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1395,7 +1395,7 @@ func (s *AutoScaleService) GetConditionByID(id string, opts ...OptionFunc) (*Con

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1606,7 +1606,7 @@ func (s *AutoScaleService) GetAutoScalePolicyByID(id string, opts ...OptionFunc)

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1851,7 +1851,7 @@ func (s *AutoScaleService) GetAutoScaleVmProfileByID(id string, opts ...OptionFu

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -2099,7 +2099,7 @@ func (s *AutoScaleService) GetAutoScaleVmGroupByID(id string, opts ...OptionFunc

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -645,7 +645,7 @@ func (s *ClusterService) GetClusterID(name string, opts ...OptionFunc) (string,

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -695,7 +695,7 @@ func (s *ClusterService) GetClusterByID(id string, opts ...OptionFunc) (*Cluster

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -571,7 +571,7 @@ func (s *DiskOfferingService) GetDiskOfferingID(name string, opts ...OptionFunc)

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -621,7 +621,7 @@ func (s *DiskOfferingService) GetDiskOfferingByID(id string, opts ...OptionFunc)

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -457,7 +457,7 @@ func (s *DomainService) GetDomainID(name string, opts ...OptionFunc) (string, in

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -507,7 +507,7 @@ func (s *DomainService) GetDomainByID(id string, opts ...OptionFunc) (*Domain, i

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -709,7 +709,7 @@ func (s *DomainService) GetDomainChildrenID(name string, opts ...OptionFunc) (st

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -759,7 +759,7 @@ func (s *DomainService) GetDomainChildrenByID(id string, opts ...OptionFunc) (*D

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -222,7 +222,7 @@ func (s *EventService) GetEventByID(id string, opts ...OptionFunc) (*Event, int,

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -254,7 +254,7 @@ func (s *FirewallService) GetPortForwardingRuleByID(id string, opts ...OptionFun

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1254,7 +1254,7 @@ func (s *FirewallService) GetFirewallRuleByID(id string, opts ...OptionFunc) (*F

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1903,7 +1903,7 @@ func (s *FirewallService) GetEgressFirewallRuleByID(id string, opts ...OptionFun

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -119,7 +119,7 @@ func (s *GuestOSService) GetOsTypeByID(id string, opts ...OptionFunc) (*OsType,

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -256,7 +256,7 @@ func (s *GuestOSService) GetOsCategoryID(name string, opts ...OptionFunc) (strin

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -306,7 +306,7 @@ func (s *GuestOSService) GetOsCategoryByID(id string, opts ...OptionFunc) (*OsCa

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -716,7 +716,7 @@ func (s *GuestOSService) GetGuestOsMappingByID(id string, opts ...OptionFunc) (*

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1049,7 +1049,7 @@ func (s *HostService) GetHostID(name string, opts ...OptionFunc) (string, int, e

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -1099,7 +1099,7 @@ func (s *HostService) GetHostByID(id string, opts ...OptionFunc) (*Host, int, er

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1268,7 +1268,7 @@ func (s *HostService) GetHostTagID(keyword string, opts ...OptionFunc) (string,

p.p["keyword"] = keyword

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -244,7 +244,7 @@ func (s *HypervisorService) GetHypervisorCapabilityByID(id string, opts ...Optio

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -764,7 +764,7 @@ func (s *ISOService) GetIsoID(name string, isofilter string, zoneid string, opts
p.p["isofilter"] = isofilter
p.p["zoneid"] = zoneid

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -814,7 +814,7 @@ func (s *ISOService) GetIsoByID(id string, opts ...OptionFunc) (*Iso, int, error

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -1780,7 +1780,7 @@ func (s *ISOService) GetIsoPermissionByID(id string, opts ...OptionFunc) (*IsoPe

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -427,7 +427,7 @@ func (s *ImageStoreService) GetImageStoreID(name string, opts ...OptionFunc) (st

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -477,7 +477,7 @@ func (s *ImageStoreService) GetImageStoreByID(id string, opts ...OptionFunc) (*I

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -812,7 +812,7 @@ func (s *ImageStoreService) GetSecondaryStagingStoreID(name string, opts ...Opti

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -862,7 +862,7 @@ func (s *ImageStoreService) GetSecondaryStagingStoreByID(id string, opts ...Opti

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -281,7 +281,7 @@ func (s *InternalLBService) GetInternalLoadBalancerElementByID(id string, opts .

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}
@@ -842,7 +842,7 @@ func (s *InternalLBService) GetInternalLoadBalancerVMID(name string, opts ...Opt

p.p["name"] = name

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return "", -1, err
}
@@ -892,7 +892,7 @@ func (s *InternalLBService) GetInternalLoadBalancerVMByID(id string, opts ...Opt

p.p["id"] = id

for _, fn := range opts {
for _, fn := range append(s.cs.options, opts...) {
if err := fn(s.cs, p); err != nil {
return nil, -1, err
}

0 comments on commit 1ab415c

Please sign in to comment.