Documentation
¶
Overview ¶
Package arukas is library for Arukas API clients
ref: https://arukas.io/en/documents-en/arukas-api-reference-en/
Example ¶
package main
import (
"context"
"time"
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// Create container(app and service)
app, err := client.CreateApp(&arukas.RequestParam{
Name: "<your-app-name>",
Image: "nginx:latest", // supports only DockerHub public repositories
Plan: arukas.PlanFree, // allows [PlanFree / PlanHobby / PlanStandard1 / PlanStandard2]
Instances: 1, // number of instance count
SubDomain: "", // subdomain(EndPoint will be <subdomain>.arukascloud.io). if empty, using random domain.
Ports: []*arukas.Port{
{
Protocol: "tcp",
Number: 80,
},
},
Environment: []*arukas.Env{
{
Key: "FOO",
Value: "BAR",
},
},
Command: "nginx -g daemon off;",
})
if err != nil {
panic(err)
}
// Get IDs
appID := app.AppID()
serviceID := app.ServiceID()
// Power on
err = client.PowerOn(serviceID)
if err != nil {
panic(err)
}
// Wait until container is running...
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
errChan := make(chan error)
go func() {
errChan <- client.WaitForState(ctx, serviceID, arukas.StatusRunning)
}()
select {
case e := <-errChan:
if e != nil {
panic(e)
}
case <-ctx.Done():
panic(ctx.Err())
}
// Update container(service)
_, err = client.UpdateService(serviceID, &arukas.RequestParam{
Image: "httpd:latest",
})
if err != nil {
panic(err)
}
// Delete container(app)
err = client.DeleteApp(appID)
if err != nil {
panic(err)
}
}
Output:
Example (CreateContainer) ¶
package main
import (
"fmt"
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// Create container(app and service)
app, err := client.CreateApp(&arukas.RequestParam{
Name: "<your-app-name>",
Image: "nginx:latest", // supports only DockerHub public repositories
Plan: arukas.PlanFree, // allows [PlanFree / PlanHobby / PlanStandard1 / PlanStandard2]
Instances: 1, // number of instance count
SubDomain: "", // subdomain(EndPoint will be <subdomain>.arukascloud.io). if empty, using random domain.
Ports: []*arukas.Port{
{
Protocol: "tcp",
Number: 80,
},
},
Environment: []*arukas.Env{
{
Key: "FOO",
Value: "BAR",
},
},
Command: "nginx -g daemon off;",
})
if err != nil {
panic(err)
}
fmt.Printf("AppName: %s", app.Name())
}
Output:
Example (DeleteApp) ¶
package main
import (
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
appID := "<your-app-id>" // UUID format is required for appID
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// Delete app
err = client.DeleteApp(appID)
if err != nil {
panic(err)
}
}
Output:
Example (ListApps) ¶
package main
import (
"fmt"
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// List all apps
apps, err := client.ListApps()
if err != nil {
panic(err)
}
for _, app := range apps.Data {
fmt.Printf("AppName: %s", app.Name())
}
}
Output:
Example (ListServices) ¶
package main
import (
"fmt"
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// List all services
services, err := client.ListServices()
if err != nil {
panic(err)
}
for _, service := range services.Data {
fmt.Printf("ServiceID: %s\nEndPoint URL: %s", service.ID, service.EndPoint())
}
}
Output:
Example (PowerOff) ¶
package main
import (
"context"
"time"
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
serviceID := "<your-service-id>" // UUID format is required for serviceID
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// PowerOff
if err := client.PowerOff(serviceID); err != nil {
panic(err)
}
// Wait until container is stopped...
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
errChan := make(chan error)
go func() {
errChan <- client.WaitForState(ctx, serviceID, arukas.StatusStopped)
}()
select {
case e := <-errChan:
if e != nil {
panic(e)
}
case <-ctx.Done():
panic(ctx.Err())
}
}
Output:
Example (PowerOn) ¶
package main
import (
"context"
"time"
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
serviceID := "<your-service-id>" // UUID format is required for serviceID
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// PowerOn
if err := client.PowerOn(serviceID); err != nil {
panic(err)
}
// Wait until container is running...
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
errChan := make(chan error)
go func() {
errChan <- client.WaitForState(ctx, serviceID, arukas.StatusRunning)
}()
select {
case e := <-errChan:
if e != nil {
panic(e)
}
case <-ctx.Done():
panic(ctx.Err())
}
}
Output:
Example (ReadApp) ¶
package main
import (
"fmt"
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
appID := "<your-app-id>" // UUID format is required for appID
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// Read app
app, err := client.ReadApp(appID)
if err != nil {
panic(err)
}
fmt.Printf("AppName: %s", app.Name())
}
Output:
Example (UpdateService) ¶
package main
import (
"fmt"
"github.com/yamamoto-febc/go-arukas"
)
func main() {
// Initialize API Client
token := "<your-api-token>"
secret := "<your-api-secret>"
serviceID := "<your-service-id>" // UUID format is required for serviceID
client, err := arukas.NewClient(&arukas.ClientParam{
Token: token,
Secret: secret,
})
if err != nil {
panic(err)
}
// Update service
updatedService, err := client.UpdateService(serviceID, &arukas.RequestParam{
Instances: 2,
Image: "nginx:latst",
Ports: []*arukas.Port{
{
Protocol: "tcp",
Number: 80,
},
{
Protocol: "tcp",
Number: 443,
},
},
Environment: []*arukas.Env{
{
Key: "MY_ENV",
Value: "my_value",
},
},
})
if err != nil {
panic(err)
}
fmt.Printf("Services: %#v", updatedService)
}
Output:
Index ¶
- Constants
- Variables
- func PlanID(region, plan string) string
- type App
- type AppAttr
- type AppData
- type AppListData
- type AppRelationship
- type Client
- type ClientParam
- type CustomDomain
- type Env
- type ErrorNotFound
- type Port
- type PortMapping
- type Ports
- type Relationship
- type RelationshipData
- type RelationshipDataList
- type RequestParam
- type Service
- func (s *Service) AppID() string
- func (s *Service) CPUs() float32
- func (s *Service) Command() string
- func (s *Service) CreatedAt() *time.Time
- func (s *Service) EndPoint() string
- func (s *Service) Environment() []*Env
- func (s *Service) Image() string
- func (s *Service) Instances() int32
- func (s *Service) Memory() int32
- func (s *Service) PlanID() string
- func (s *Service) PortMapping() []*PortMapping
- func (s *Service) PortMappings() [][]*PortMapping
- func (s *Service) Ports() Ports
- func (s *Service) Status() string
- func (s *Service) SubDomain() string
- func (s *Service) UpdatedAt() *time.Time
- type ServiceAttr
- type ServiceData
- func (s *ServiceData) AppID() string
- func (s *ServiceData) CPUs() float32
- func (s *ServiceData) Command() string
- func (s *ServiceData) CreatedAt() *time.Time
- func (s *ServiceData) EndPoint() string
- func (s *ServiceData) Environment() []*Env
- func (s *ServiceData) Image() string
- func (s *ServiceData) Instances() int32
- func (s *ServiceData) Memory() int32
- func (s *ServiceData) PlanID() string
- func (s *ServiceData) PortMapping() []*PortMapping
- func (s *ServiceData) PortMappings() [][]*PortMapping
- func (s *ServiceData) Ports() Ports
- func (s *ServiceData) ServiceID() string
- func (s *ServiceData) Status() string
- func (s *ServiceData) SubDomain() string
- func (s *ServiceData) Type() string
- func (s *ServiceData) UpdatedAt() *time.Time
- type ServiceListData
- type ServiceRelationship
Examples ¶
Constants ¶
const ( // PlanFree represents the "free" plan PlanFree = "free" // PlanHobby represents the "hobby" plan PlanHobby = "hobby" // PlanStandard1 represents the "standard-1" plan PlanStandard1 = "standard-1" // PlanStandard2 represents the "standard-2" plan PlanStandard2 = "standard-2" )
const ( // TypeApps represents the "apps" type TypeApps = "apps" // TypeServices represents the "services" type TypeServices = "services" // TypeServicePlans represents the "service_plans" type TypeServicePlans = "service-plans" // TypeUsers represents the "users" type TypeUsers = "users" // TypeRegions represents the "regions" type TypeRegions = "regions" )
const ( // StatusBooting represents the "booting" status StatusBooting = "booting" // StatusTerminated represents the "terminated" status StatusTerminated = "terminated" // StatusRunning represents the "running" status StatusRunning = "running" // StatusStopping represents the "stopping" status StatusStopping = "stopping" // StatusStopped represents the "stopped" status StatusStopped = "stopped" // StatusRebooting represents the "rebooting" status StatusRebooting = "rebooting" )
const LinkID = 1
LinkID used when creating new app/service
const (
// RegionJPTokyo represents the "jp-tokyo" region
RegionJPTokyo = "jp-tokyo"
)
Variables ¶
var ( // ValidRegions is a list of valid regions ValidRegions = []string{RegionJPTokyo} // ValidPlans is a list of valid ValidPlans = []string{PlanFree, PlanHobby, PlanStandard1, PlanStandard2} )
var ValidProtocols = []string{"tcp", "udp"}
ValidProtocols is a list of valid protocol
var Version = "0.1.0"
Version returns current version
Functions ¶
Types ¶
type App ¶
type App struct {
ID string `json:"id"`
Type string `json:"type,omitempty"`
Attributes *AppAttr `json:"attributes,omitempty"`
Relationships *AppRelationship `json:"relationships,omitempty"`
}
App represents a app object
type AppAttr ¶
type AppAttr struct {
Name string `json:"name,omitempty"`
CreatedAt *time.Time `json:"created-at,omitempty"`
UpdatedAt *time.Time `json:"updated-at,omitempty"`
}
AppAttr represents app.attributes object
type AppData ¶
type AppData struct {
Data *App `json:"data"`
Included []interface{} `json:"included,omitempty"`
}
AppData represents data object(included app and child service)
type AppListData ¶
type AppListData struct {
Data []*App `json:"data"`
Included []interface{} `json:"included,omitempty"`
}
AppListData represents data object(included []app and child services)
type AppRelationship ¶
type AppRelationship struct {
User *RelationshipData `json:"user,omitempty"`
Services *RelationshipDataList `json:"services,omitempty"`
}
AppRelationship represents App relationship data
func NewAppRelationship ¶
func NewAppRelationship() *AppRelationship
NewAppRelationship creates new AppRelationship with default values
type Client ¶
type Client interface {
ListApps() (*AppListData, error)
ReadApp(id string) (*AppData, error)
CreateApp(param *RequestParam) (*AppData, error)
DeleteApp(id string) error
ListServices() (*ServiceListData, error)
ReadService(id string) (*ServiceData, error)
UpdateService(id string, param *RequestParam) (*ServiceData, error)
PowerOn(id string) error
PowerOff(id string) error
WaitForState(ctx context.Context, serviceID string, status string) error
Version() string
}
Client is Arukas API Client interface
func NewClient ¶
func NewClient(p *ClientParam) (Client, error)
NewClient returns a new arukas API Client, requires an authorization key. You can generate a API key by visiting the Keys section of the Arukas control panel for your account.
type ClientParam ¶
type ClientParam struct {
APIBaseURL string
Token string
Secret string
UserAgent string
Trace bool
TraceOut io.Writer
Timeout time.Duration
}
ClientParam represents parameters to use arukas.API
type CustomDomain ¶
type CustomDomain struct {
Name string `json:"name"`
}
CustomDomain represents custom_domain object
func CustomDomains ¶
func CustomDomains(domains ...string) []*CustomDomain
CustomDomains returns array of *CustomDomain created from domain name list
type ErrorNotFound ¶ added in v0.0.2
type ErrorNotFound error
ErrorNotFound represents 404 not found error
type Port ¶
type Port struct {
// Protocol is either tcp/udp
Protocol string `json:"protocol"`
// Number is port number that container exposes.
// Valid value range is [1 - 65535]
Number int32 `json:"number"`
}
Port represents the port information you want expose in container
func (*Port) MarshalJSON ¶ added in v0.1.0
MarshalJSON implements json.Marshaler
type PortMapping ¶
type PortMapping struct {
Host string `json:"host"`
Protocol string `json:"protocol"`
ContainerPort int32 `json:"container-port"`
ServicePort int32 `json:"service-port"`
}
PortMapping represents actual port mapping information on running container
type Ports ¶ added in v0.0.8
type Ports []*Port
Ports is a slice of Ports. A service can have multiple ports.
func (*Ports) UnmarshalJSON ¶ added in v0.0.8
UnmarshalJSON parses ports in both old and new port format and convert them to Port.
type Relationship ¶
type Relationship struct {
ID string `json:"id,omitempty"`
LinkID int32 `json:"lid,omitempty"`
Type string `json:"type,omitempty"`
}
Relationship represents relationship body
type RelationshipData ¶
type RelationshipData struct {
Data *Relationship `json:"data,omitempty"`
}
RelationshipData represents relationship data
type RelationshipDataList ¶ added in v0.0.7
type RelationshipDataList struct {
Data []*Relationship `json:"data,omitempty"`
}
RelationshipDataList represents relationship data(list)
type RequestParam ¶
type RequestParam struct {
// Name needs only when create app
Name string
Command string
CustomDomains []string
Image string
Instances int32
Ports Ports
Environment []*Env
SubDomain string
Region string
Plan string
}
RequestParam represents request parameter of Arukas.API
func (*RequestParam) ToAppData ¶
func (p *RequestParam) ToAppData() *AppData
ToAppData returns *AppData built from RequestParam
func (*RequestParam) ToServiceData ¶
func (p *RequestParam) ToServiceData() *ServiceData
ToServiceData returns *ServiceData built from RequestParam
func (*RequestParam) ValidateForCreate ¶
func (p *RequestParam) ValidateForCreate() error
ValidateForCreate returns error if parameter is invalid
func (*RequestParam) ValidateForUpdate ¶
func (p *RequestParam) ValidateForUpdate() error
ValidateForUpdate returns error if parameter is invalid
type Service ¶
type Service struct {
ID string `json:"id,omitempty"`
LinkID int32 `json:"lid,omitempty"`
Type string `json:"type,omitempty"`
Attributes *ServiceAttr `json:"attributes,omitempty"`
Relationships *ServiceRelationship `json:"relationships,omitempty"`
}
Service represents service object
func (*Service) Environment ¶
Environment returns data.attributes.environment
func (*Service) PortMapping ¶
func (s *Service) PortMapping() []*PortMapping
PortMapping returns data.attributes.port_mappings[0]
func (*Service) PortMappings ¶
func (s *Service) PortMappings() [][]*PortMapping
PortMappings returns data.attributes.port_mappings
type ServiceAttr ¶
type ServiceAttr struct {
AppID string `json:"app-id,omitempty"`
Image string `json:"image"`
Command string `json:"command"`
Instances int32 `json:"instances"`
CPUs float32 `json:"cups,omitempty"`
Memory int32 `json:"memory,omitempty"`
Environment []*Env `json:"environment"`
Ports Ports `json:"ports,omitempty"`
PortMappings [][]*PortMapping `json:"port-mappings,omitempty"`
CreatedAt *time.Time `json:"created-at,omitempty"`
UpdatedAt *time.Time `json:"updated-at,omitempty"`
Status string `json:"status,omitempty"`
SubDomain string `json:"subdomain,omitempty"`
EndPoint string `json:"endpoint,omitempty"`
CustomDomains []*CustomDomain `json:"custom-domains,omitempty"`
LastInstanceFailedAt *time.Time `json:"last-instance-failed-at,omitempty"`
LastInstanceFailedStatus interface{} `json:"last-instance-failed-status,omitempty"`
}
ServiceAttr represents service.attributes object
type ServiceData ¶
type ServiceData struct {
Data *Service `json:"data"`
}
ServiceData represents service data
func (*ServiceData) AppID ¶ added in v0.0.2
func (s *ServiceData) AppID() string
AppID returns data.attributes.app_id
func (*ServiceData) Command ¶
func (s *ServiceData) Command() string
Command returns data.attributes.command
func (*ServiceData) CreatedAt ¶
func (s *ServiceData) CreatedAt() *time.Time
CreatedAt returns data.attributes.created_at
func (*ServiceData) EndPoint ¶
func (s *ServiceData) EndPoint() string
EndPoint returns data.attributes.endpoint
func (*ServiceData) Environment ¶
func (s *ServiceData) Environment() []*Env
Environment returns data.attributes.environment
func (*ServiceData) Image ¶
func (s *ServiceData) Image() string
Image returns data.attributes.image
func (*ServiceData) Instances ¶
func (s *ServiceData) Instances() int32
Instances returns data.attributes.instances
func (*ServiceData) Memory ¶
func (s *ServiceData) Memory() int32
Memory returns data.attributes.memory
func (*ServiceData) PlanID ¶
func (s *ServiceData) PlanID() string
PlanID returns data.relationship.service_plan.data.id
func (*ServiceData) PortMapping ¶
func (s *ServiceData) PortMapping() []*PortMapping
PortMapping returns data.attributes.port_mappings[0]
func (*ServiceData) PortMappings ¶
func (s *ServiceData) PortMappings() [][]*PortMapping
PortMappings returns data.attributes.port_mappings
func (*ServiceData) Status ¶
func (s *ServiceData) Status() string
Status returns data.attributes.status
func (*ServiceData) SubDomain ¶
func (s *ServiceData) SubDomain() string
SubDomain returns data.attributes.subdomain
func (*ServiceData) UpdatedAt ¶
func (s *ServiceData) UpdatedAt() *time.Time
UpdatedAt returns data.attributes.updated_at
type ServiceListData ¶
type ServiceListData struct {
Data []*Service `json:"data"`
}
ServiceListData represents services data
type ServiceRelationship ¶
type ServiceRelationship struct {
App *RelationshipData `json:"app,omitempty"`
ServicePlan *RelationshipData `json:"service-plan,omitempty"`
}
ServiceRelationship represents Services relationship data
func NewServiceRelationship ¶
func NewServiceRelationship(region, plan string) *ServiceRelationship
NewServiceRelationship creates new ServiceRelationship with PlanID