oxidecomputer / oxidecomputer/oxide.go

Support units for `ByteCount` type

Open
#270 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement Go SDK
Dominant language
Go
Stars
26
Forks
6
Avg merge
5h 33m
Merged PRs (30d)
9

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.

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in types.go at the ByteCount definition, then review the linked Kubernetes Quantity and go-humanize references for unit-parsing behavior. Define how ParseByteCount and MustParseByteCount should handle values such as "16GiB", including invalid input, and verify that callers can use the resulting ByteCount in InstanceCreateParams.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.