core

package
v0.0.0-...-cef9ff9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2019 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

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

func RegisterMedia(media, collection string, factory func() Resource)

RegisterMedia sets the Resource factory for the media collection

func Resolve

func Resolve(href string, query url.Values) string

Resolve resolves a rawurl location iwithin the api endpoint

Types

type Authenticator

type Authenticator interface {
	// contains filtered or unexported methods
}

Authenticator ...

type Basic

type Basic struct {
	Username string
	Password string
}

Basic contains the information for an Abiquo API basic auth client

type Call

type Call struct {
	// contains filtered or unexported fields
}

Call represents a generic API call

func Delete

func Delete(href Href) *Call

Delete returns a new DELETE call

func Get

func Get(href Href, media Type) *Call

Get returns a new GET call

func Post

func Post(href Href, accept, content Type, payload interface{}) *Call

Post returns a new POST call

func Put

func Put(href Href, accept, content Type, payload interface{}) *Call

Put returns a new PUT call

func (*Call) Query

func (c *Call) Query(query url.Values) *Call

Query sets an Abiquo API call query values

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

func (*Collection) Size

func (c *Collection) Size() int

Size returns the collection totalSize

type DTO

type DTO struct {
	Links `json:"links,omitempty"`
}

DTO represents a list of links

func NewDTO

func NewDTO(links ...*Link) (d DTO)

NewDTO returns a DTO Links

func (*DTO) Add

func (d *DTO) Add(l *Link)

Add adds the Link l as rel to the *DTO Links If the link is nil, the *DTO Links do not change

func (*DTO) Create

func (d *DTO) Create(result interface{}) (err error)

Create ...

func (*DTO) Exists

func (d *DTO) Exists() (bool, error)

Exists ...

func (*DTO) Read

func (d *DTO) Read(result interface{}) (err error)

Read ...

func (*DTO) Remove

func (d *DTO) Remove() (err error)

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

func (*DTO) Update

func (d *DTO) Update(result interface{}) (err error)

Update ...

type Endpoint

type Endpoint interface {
	Href
	Type
}

Endpoint represents and Abiquo APIcore.Resource (urls, links, objects or responses)

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

func (Error) Error

func (e Error) Error() (str string)

type Href

type Href interface {
	URL() string
}

Href is an string representing an Abiquo resource

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 NewLink(href string) *Link

NewLink returns a new link to the href URL

func (*Link) Collection

func (l *Link) Collection(query url.Values) *Collection

Collection returns a collection from the link

func (*Link) Create

func (l *Link) Create(result interface{}) (err error)

Create ...

func (*Link) Exists

func (l *Link) Exists() (bool, error)

Exists ...

func (*Link) IsMedia

func (l *Link) IsMedia(media string) bool

IsMedia returns whether the link is of media Type

func (*Link) Media

func (l *Link) Media() (media string)

Media returns a link type value

func (*Link) Read

func (l *Link) Read(result interface{}) (err error)

Read ...

func (*Link) Remove

func (l *Link) Remove() (err error)

Remove ...

func (*Link) SetRel

func (l *Link) SetRel(rel string) (link *Link)

SetRel retuns a link clone with the specified rel value

func (*Link) SetTitle

func (l *Link) SetTitle(title string) (link *Link)

SetTitle retuns a link clone with the specified tytle value

func (*Link) SetType

func (l *Link) SetType(media string) (link *Link)

SetType retuns a link clone with the specified type value

func (*Link) URL

func (l *Link) URL() (href string)

URL returns a link href

func (*Link) Update

func (l *Link) Update(result interface{}) (err error)

Update ...

func (*Link) Walk

func (l *Link) Walk() (resource Resource, err error)

Walk returns the resource the link is pointing to

type Links []*Link

Links represents a list of links

func (Links) Filter

func (l Links) Filter(t func(l *Link) bool) (links Links)

Filter returns the links that meet the condition

func (Links) Find

func (l Links) Find(t func(l *Link) bool) (link *Link)

Find returns the links that meet the condition

func (l Links) Link() (link *Link)

Link retuns the self/edit link to thecore.Resource

func (Links) Map

func (l Links) Map(f func(*Link))

Map executes function f(*Link) on all the Links elements

func (Links) Media

func (l Links) Media() (m string)

Media returns a links collection media

func (Links) Rel

func (l Links) Rel(rel string) (link *Link)

Rel returns the rel object link

func (Links) URL

func (l Links) URL() (u string)

URL returns a links collection href

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

func (Media) Media

func (m Media) Media() string

Media resolves m Media string

func (Media) String

func (m Media) String() string

String ...

type Oauth

type Oauth struct {
	Token       string
	TokenSecret string
	APIKey      string
	APISecret   string
}

Oauth contains the information for an Abiquo API oauth client

type Reply

type Reply struct {
	*http.Response
	// contains filtered or unexported fields
}

Reply represents a generic Abiquo API response

func Rest

func Rest(result interface{}, c *Call) (r *Reply, err error)

Rest provides a facility to perform a rest Call

func Upload

func Upload(templates, path, info string) (r *Reply, err error)

Upload provides a method to upload templates to the AM repository

func (*Reply) Error

func (r *Reply) Error() (e Error)

Error returns a failed reply error

func (*Reply) Media

func (r *Reply) Media() string

Media ...

func (*Reply) Ok

func (r *Reply) Ok() (ok bool)

Ok returns if the reply was successful or not

func (*Reply) URL

func (r *Reply) URL() (location string)

URL returns an http.Response location values

type Resource

type Resource interface {
	Endpoint
	Link() *Link
	Rel(string) *Link
	Add(*Link)
}

Resource is an abstract interface for DTO objects

func Factory

func Factory(media string) Resource

Factory returns a resource of the specified media type

type Resources

type Resources []Resource

Resources represents an Abiquo API collection elements

func (Resources) Filter

func (r Resources) Filter(t func(r Resource) bool) (resources Resources)

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) Find

func (r Resources) Find(t func(r Resource) bool) Resource

Find a resource in a collection

func (Resources) Map

func (r Resources) Map(f func(Resource))

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

type Type

type Type interface {
	Media() string
}

Type ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL