Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): api update #44

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -202,7 +202,7 @@ _, err := client.VMs.New(context.TODO(), vms.VMNewParams{
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -248,7 +248,7 @@ client.VMs.New(
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -303,7 +303,7 @@ client.VMs.New(
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down
6 changes: 3 additions & 3 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Params Types:
Response Types:

- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#CPU">CPU</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OsImage">OsImage</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OSImage">OSImage</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#Ram">Ram</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#VM">VM</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#VMList">VMList</a>
Expand All @@ -31,11 +31,11 @@ Methods:
- <code title="delete /vms/{vm_id}">client.VMs.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#VMService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, vmID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/operations">operations</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/operations#Operation">Operation</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /vms/{vm_id}">client.VMs.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#VMService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, vmID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#VM">VM</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

## OsImages
## OSImages

Methods:

- <code title="get /vms/os_images">client.VMs.OsImages.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OsImageService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) ([]<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OsImage">OsImage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /vms/os_images">client.VMs.OSImages.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OSImageService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) ([]<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OSImage">OSImage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# VPCs

Expand Down
16 changes: 8 additions & 8 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestUserAgentHeader(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestRetryAfter(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestDeleteRetryCountHeader(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestOverwriteRetryCountHeader(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestRetryAfterMs(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestContextCancel(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestContextCancelDelay(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestContextDeadline(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down
2 changes: 1 addition & 1 deletion usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestUsage(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down
14 changes: 7 additions & 7 deletions vms/osimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ import (
"github.com/nirvana-labs/nirvana-go/option"
)

// OsImageService contains methods and other services that help with interacting
// OSImageService contains methods and other services that help with interacting
// with the Nirvana Labs API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewOsImageService] method instead.
type OsImageService struct {
// the [NewOSImageService] method instead.
type OSImageService struct {
Options []option.RequestOption
}

// NewOsImageService generates a new service that applies the given options to each
// NewOSImageService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewOsImageService(opts ...option.RequestOption) (r *OsImageService) {
r = &OsImageService{}
func NewOSImageService(opts ...option.RequestOption) (r *OSImageService) {
r = &OSImageService{}
r.Options = opts
return
}

// List all OS Images
func (r *OsImageService) List(ctx context.Context, opts ...option.RequestOption) (res *[]OsImage, err error) {
func (r *OSImageService) List(ctx context.Context, opts ...option.RequestOption) (res *[]OSImage, err error) {
opts = append(r.Options[:], opts...)
path := "vms/os_images"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
Expand Down
4 changes: 2 additions & 2 deletions vms/osimage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/nirvana-labs/nirvana-go/option"
)

func TestOsImageList(t *testing.T) {
func TestOSImageList(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
Expand All @@ -25,7 +25,7 @@ func TestOsImageList(t *testing.T) {
option.WithBaseURL(baseURL),
option.WithAuthToken("My Auth Token"),
)
_, err := client.VMs.OsImages.List(context.TODO())
_, err := client.VMs.OSImages.List(context.TODO())
if err != nil {
var apierr *nirvana.Error
if errors.As(err, &apierr) {
Expand Down
12 changes: 6 additions & 6 deletions vms/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// the [NewVMService] method instead.
type VMService struct {
Options []option.RequestOption
OsImages *OsImageService
OSImages *OSImageService
}

// NewVMService generates a new service that applies the given options to each
Expand All @@ -34,7 +34,7 @@ type VMService struct {
func NewVMService(opts ...option.RequestOption) (r *VMService) {
r = &VMService{}
r.Options = opts
r.OsImages = NewOsImageService(opts...)
r.OSImages = NewOSImageService(opts...)
return
}

Expand Down Expand Up @@ -120,14 +120,14 @@ func (r CPUParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type OsImage struct {
type OSImage struct {
CreatedAt string `json:"created_at,required"`
DisplayName string `json:"display_name,required"`
Name string `json:"name,required"`
JSON osImageJSON `json:"-"`
}

// osImageJSON contains the JSON metadata for the struct [OsImage]
// osImageJSON contains the JSON metadata for the struct [OSImage]
type osImageJSON struct {
CreatedAt apijson.Field
DisplayName apijson.Field
Expand All @@ -136,7 +136,7 @@ type osImageJSON struct {
ExtraFields map[string]apijson.Field
}

func (r *OsImage) UnmarshalJSON(data []byte) (err error) {
func (r *OSImage) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

Expand Down Expand Up @@ -258,7 +258,7 @@ type VMNewParams struct {
CPU param.Field[CPUParam] `json:"cpu,required"`
Name param.Field[string] `json:"name,required"`
NeedPublicIP param.Field[bool] `json:"need_public_ip,required"`
OsImageID param.Field[int64] `json:"os_image_id,required"`
OSImageID param.Field[int64] `json:"os_image_id,required"`
Ports param.Field[[]string] `json:"ports,required"`
// RAM details.
Ram param.Field[RamParam] `json:"ram,required"`
Expand Down
2 changes: 1 addition & 1 deletion vms/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestVMNewWithOptionalParams(t *testing.T) {
}),
Name: nirvana.F("my-vm"),
NeedPublicIP: nirvana.F(true),
OsImageID: nirvana.F(int64(1)),
OSImageID: nirvana.F(int64(1)),
Ports: nirvana.F([]string{"22", "80", "443"}),
Ram: nirvana.F(vms.RamParam{
Size: nirvana.F(int64(2)),
Expand Down