Support units for `ByteCount` type

オープン
#270 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
go
領域
api

調査の方向性

types.go の ByteCount の定義から始め、リンクされた Kubernetes Quantity と go-humanize の参照を確認して、単位のパース動作を調べます。ParseByteCount と MustParseByteCount が "16GiB" のような値を、無効な入力を含めてどのように扱うべきかを定義し、呼び出し元が結果の ByteCount を InstanceCreateParams で使用できることを検証します。

索引モデルが issue の本文から書いたものです。

説明

Enhancement Go SDK
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

主要言語
Go
スター
26
フォーク
6
平均マージ
17時間 27分
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

oxidecomputer/oxide.go のほかの issue

oxidecomputer/oxide.go の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。