Documentation
¶
Index ¶
- func Init(api string, auth Authenticator) (err error)
- func RegisterMedia(media, collection string, factory func() Resource)
- func Resolve(href string, query url.Values) string
- type Authenticator
- type Basic
- type Call
- type Collection
- type DTO
- type Endpoint
- type Error
- type Href
- type Link
- func (l *Link) Collection(query url.Values) *Collection
- func (l *Link) Create(result interface{}) (err error)
- func (l *Link) Exists() (bool, error)
- func (l *Link) IsMedia(media string) bool
- func (l *Link) Media() (media string)
- func (l *Link) Read(result interface{}) (err error)
- func (l *Link) Remove() (err error)
- func (l *Link) SetRel(rel string) (link *Link)
- func (l *Link) SetTitle(title string) (link *Link)
- func (l *Link) SetType(media string) (link *Link)
- func (l *Link) URL() (href string)
- func (l *Link) Update(result interface{}) (err error)
- func (l *Link) Walk() (resource Resource, err error)
- type Links
- type Media
- type Oauth
- type Reply
- type Resource
- type Resources
- type Type
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(api string, auth Authenticator) (err error)
Init initializes Abiquo API client
func RegisterMedia ¶
RegisterMedia sets the Resource factory for the media collection
Types ¶
type Authenticator ¶
type Authenticator interface {
// contains filtered or unexported methods
}
Authenticator ...
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
Call represents a generic API call
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection represents an Abiquo API collection.
func (*Collection) Find ¶
func (c *Collection) Find(t func(r Resource) bool) Resource
Find a resource in a collection
Example ¶
package main import ( "fmt" "github.com/abiquo/ojal/abiquo" "github.com/abiquo/ojal/core" ) func main() { for _, name := range []string{"Abiquo", "abq"} { result := abiquo.Enterprises().Collection(nil).Find(func(r core.Resource) bool { return r.Link().Title == name }) fmt.Println(result == nil) } }
Output: false true
func (*Collection) First ¶
func (c *Collection) First() Resource
First returns a collection first element
Example ¶
package main import ( "fmt" "github.com/abiquo/ojal/abiquo" ) func main() { e := abiquo.Enterprises().Collection(nil).First() fmt.Println(e.(*abiquo.Enterprise).Name) }
Output: Abiquo
func (*Collection) Item ¶
func (c *Collection) Item() Resource
Item returns the first item and removes it from the collection
func (*Collection) List ¶
func (c *Collection) List() (resources Resources)
List returns an slice with all the collection elements
Example ¶
package main import ( "fmt" "github.com/abiquo/ojal/abiquo" ) func main() { for _, e := range abiquo.Enterprises().Collection(nil).List() { fmt.Println(e.Link().Title) break } }
Output: Abiquo
func (*Collection) Next ¶
func (c *Collection) Next() bool
Next returns true it there are still elements on the collection
type DTO ¶
type DTO struct {
Links `json:"links,omitempty"`
}
DTO represents a list of links
func (*DTO) Add ¶
Add adds the Link l as rel to the *DTO Links If the link is nil, the *DTO Links do not change
func (*DTO) Remove ¶
Remove ...
Example ¶
package main import ( "fmt" "time" "github.com/abiquo/ojal/abiquo" "github.com/abiquo/ojal/core" ) var ( ts = time.Now().Unix() enterprise0 = &abiquo.Enterprise{Name: fmt.Sprint("ztest A ", ts)} ) func main() { var ( endpoint = abiquo.Enterprises().SetType("enterprise") create1 = endpoint.Create(enterprise0) create2 = endpoint.Create(enterprise0) read = enterprise0.Read(enterprise0) update = enterprise0.Update(enterprise0) remove1 = enterprise0.Remove() remove2 = enterprise0.Remove() ) fmt.Println(create1) fmt.Println(create2) fmt.Println(read) fmt.Println(update) fmt.Println(remove1) fmt.Println(remove2) }
Output: <nil> 409 ENTERPRISE-4 Duplicate name for an enterprise <nil> <nil> <nil> 404 EN-0 The requested enterprise does not exist
type Error ¶
type Error struct { Status int Collection []struct { Code string `json:"code"` Message string `json:"message"` } `json:"collection"` }
Error represents an Abiquo API error collection
type Link ¶
type Link struct { Href string `json:"href,omitempty"` Rel string `json:"rel,omitempty"` Title string `json:"title,omitempty"` Type string `json:"type,omitempty"` // Disk specific attributes Length int `json:"length,omitempty"` DiskControllerType string `json:"diskControllerType,omitempty"` DiskController string `json:"diskController,omitempty"` DiskLabel string `json:"diskLabel,omitempty"` }
Link represents an Abiquo link
func (*Link) Collection ¶
func (l *Link) Collection(query url.Values) *Collection
Collection returns a collection from the link
type Links ¶
type Links []*Link
Links represents a list of links
type Media ¶
type Media string
Media ...
Example ¶
package main import ( "fmt" "github.com/abiquo/ojal/core" ) func main() { fmt.Println(core.Media("")) fmt.Println(core.Media("text/plain")) fmt.Println(core.Media("enterprise")) }
Output: text/plain application/vnd.abiquo.enterprise+json
type Reply ¶
Reply represents a generic Abiquo API response
type Resources ¶
type Resources []Resource
Resources represents an Abiquo API collection elements
func (Resources) Filter ¶
Filter returns the elements which fullfill the Test
Example ¶
package main import ( "fmt" "github.com/abiquo/ojal/abiquo" "github.com/abiquo/ojal/core" ) func main() { collection := abiquo.Enterprises().Collection(nil) filtered := collection.List().Filter(func(r core.Resource) bool { return r.(*abiquo.Enterprise).Name == "Abiquo" }) fmt.Println(filtered[0].(*abiquo.Enterprise).Name) fmt.Println(len(filtered)) }
Output: Abiquo 1
func (Resources) Map ¶
Map applies a function to all elements of r
Example ¶
package main import ( "fmt" "github.com/abiquo/ojal/abiquo" "github.com/abiquo/ojal/core" ) func main() { var count int counter := func(r core.Resource) { count++ } collection := abiquo.Enterprises().Collection(nil) collection.List().Map(counter) fmt.Println(collection.Size() == count) }
Output: true