diff --git a/coder-sdk/env.go b/coder-sdk/env.go index c8f346be..5113dee2 100644 --- a/coder-sdk/env.go +++ b/coder-sdk/env.go @@ -11,18 +11,19 @@ import ( // Environment describes a Coder environment type Environment struct { - ID string `json:"id" tab:"-"` - Name string `json:"name"` - ImageID string `json:"image_id" tab:"-"` - ImageTag string `json:"image_tag"` - OrganizationID string `json:"organization_id" tab:"-"` - UserID string `json:"user_id" tab:"-"` - LastBuiltAt time.Time `json:"last_built_at" tab:"-"` - CPUCores float32 `json:"cpu_cores"` - MemoryGB int `json:"memory_gb"` - DiskGB int `json:"disk_gb"` - GPUs int `json:"gpus"` - Updating bool `json:"updating"` + ID string `json:"id" tab:"-"` + Name string `json:"name"` + ImageID string `json:"image_id" tab:"-"` + ImageTag string `json:"image_tag"` + OrganizationID string `json:"organization_id" tab:"-"` + UserID string `json:"user_id" tab:"-"` + LastBuiltAt time.Time `json:"last_built_at" tab:"-"` + CPUCores float32 `json:"cpu_cores"` + MemoryGB int `json:"memory_gb"` + DiskGB int `json:"disk_gb"` + GPUs int `json:"gpus"` + Updating bool `json:"updating"` + LatestStat EnvironmentStat `json:"latest_stat" tab:"Status"` RebuildMessages []struct { Text string `json:"text"` Required bool `json:"required"` @@ -34,6 +35,35 @@ type Environment struct { AutoOffThreshold xjson.Duration `json:"auto_off_threshold" tab:"-"` } +// EnvironmentStat represents the state of an environment +type EnvironmentStat struct { + Time time.Time `json:"time"` + LastOnline time.Time `json:"last_online"` + ContainerStatus EnvironmentStatus `json:"container_status"` + StatError string `json:"stat_error"` + CPUUsage float32 `json:"cpu_usage"` + MemoryTotal int64 `json:"memory_total"` + MemoryUsage float32 `json:"memory_usage"` + DiskTotal int64 `json:"disk_total"` + DiskUsed int64 `json:"disk_used"` +} + +func (e EnvironmentStat) String() string { + return string(e.ContainerStatus) +} + +// EnvironmentStatus refers to the states of an environment. +type EnvironmentStatus string + +// The following represent the possible environment container states +const ( + EnvironmentCreating EnvironmentStatus = "CREATING" + EnvironmentOff EnvironmentStatus = "OFF" + EnvironmentOn EnvironmentStatus = "ON" + EnvironmentFailed EnvironmentStatus = "FAILED" + EnvironmentUnknown EnvironmentStatus = "UNKNOWN" +) + // CreateEnvironmentRequest is used to configure a new environment type CreateEnvironmentRequest struct { Name string `json:"name"` diff --git a/internal/x/xtabwriter/tabwriter.go b/internal/x/xtabwriter/tabwriter.go index 1345cca7..4d3a91be 100644 --- a/internal/x/xtabwriter/tabwriter.go +++ b/internal/x/xtabwriter/tabwriter.go @@ -25,7 +25,7 @@ func StructValues(data interface{}) string { if shouldHideField(v.Type().Field(i)) { continue } - s.WriteString(fmt.Sprintf("%v\t", v.Field(i).Interface())) + fmt.Fprintf(s, "%v\t", v.Field(i).Interface()) } return s.String() } @@ -41,7 +41,7 @@ func StructFieldNames(data interface{}) string { if shouldHideField(field) { continue } - s.WriteString(fmt.Sprintf("%s\t", field.Name)) + fmt.Fprintf(s, "%s\t", fieldName(field)) } return s.String() } @@ -72,6 +72,14 @@ func WriteTable(length int, each func(i int) interface{}) error { return nil } +func fieldName(f reflect.StructField) string { + custom, ok := f.Tag.Lookup(structFieldTagKey) + if ok { + return custom + } + return f.Name +} + func shouldHideField(f reflect.StructField) bool { return f.Tag.Get(structFieldTagKey) == "-" } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy