Skip to content

Support units for ByteCount type #270

@sudomateo

Description

@sudomateo

Overview

The Go SDK uses the ByteCount type to represent the number of bytes for instance memory, disks, and other Oxide resources. Instead of using values with units (e.g., 16GiB), users must convert these values to bytes (e.g., 17179869184). This can lead to issues if users leave off numbers or typo numbers. Some users opt to use a helper like the following to calculate the correct number of bytes.

> python3 -c 'print(16 * 1024**3)'
17179869184

This Go SDK should be updated to allow users to specify a value with a unit (e.g., 16GiB).

Implementation details

The implementation can take inspiration from the following.

Here are function signatures that an implementation can use.

func MustParseByteCount(str string) ByteCount
func ParseByteCount(str string) (ByteCount, error)

Given those function signatures, here's how a user can use them in code.

params := oxide.InstanceCreateParams{
  Memory: MustParseByteCount("16GiB"),
}
memory, err := ParseByteCount("16GiB")
if err != nil {
  // Handle error.
}

params := oxide.InstanceCreateParams{
  Memory: memory,
}

Anything else you would like to add?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions