Support units for `ByteCount` type

Aperta
#270 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
go
Ambito
api

Direzione di ricerca

Inizia in types.go, dalla definizione di ByteCount, quindi esamina i riferimenti collegati a Kubernetes Quantity e go-humanize per il comportamento del parsing delle unità. Definisci come ParseByteCount e MustParseByteCount devono gestire valori come "16GiB", incluso l'input non valido, e verifica che i chiamanti possano usare il ByteCount risultante in InstanceCreateParams.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Go
Stelle
26
Fork
6
Merge medio
17h 27m
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di oxidecomputer/oxide.go

Tutte le issue di oxidecomputer/oxide.go

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.