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

support units for ByteCount #270

Open
sudomateo opened this issue Mar 3, 2025 · 1 comment
Open

support units for ByteCount #270

sudomateo opened this issue Mar 3, 2025 · 1 comment
Labels
feature New feature

Comments

@sudomateo
Copy link
Contributor

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

@sudomateo sudomateo added the feature New feature label Mar 3, 2025
@karencfv
Copy link
Collaborator

karencfv commented Mar 3, 2025

Nice!! I like this idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

No branches or pull requests

2 participants