-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
featureNew featureNew feature
Description
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.
- https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity
- https://pkg.go.dev/github.com/dustin/go-humanize
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
karencfv
Metadata
Metadata
Assignees
Labels
featureNew featureNew feature