1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-986 User-definable DigitalOcean columns (#1001)

* WTF-986 Wrap the DigitalOcean droplet in our own droplet

This gives us something to build off while still providing the
underlying functionality of the original droplet instance.

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-986 Dynamically display droplet attributes based on defined column names

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-986 Read DigitalOcean column configuration from settings

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-986 Extract the reflection bits into a Reflective package

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer
2020-10-14 09:29:58 -07:00
committed by GitHub
parent b2e0c520e8
commit f84142553c
7 changed files with 175 additions and 28 deletions

25
utils/reflective.go Normal file
View File

@@ -0,0 +1,25 @@
package utils
import (
"fmt"
"reflect"
)
// Reflective is a convenience wrapper for objects that makes it possible to
// extract property values from the object by property name
type Reflective struct{}
// StringValueForProperty returns a string value for the given property
// If the property doesn't exist, it returns an error
func (ref *Reflective) StringValueForProperty(propName string) (string, error) {
v := reflect.ValueOf(ref)
refVal := reflect.Indirect(v).FieldByName(propName)
if !refVal.IsValid() {
return "", fmt.Errorf("invalid property name: %s", propName)
}
strVal := fmt.Sprintf("%v", refVal)
return strVal, nil
}

View File

@@ -77,12 +77,13 @@ func Truncate(src string, maxLen int, withEllipse bool) string {
return src
}
// Formats number as string with 1000 delimiters and, if necessary, rounds it to 2 decimals
// PrettyNumber formats number as string with 1000 delimiters and, if necessary, rounds it to 2 decimals
func PrettyNumber(number float64) string {
p := message.NewPrinter(language.English)
if number == math.Trunc(number) {
return p.Sprintf("%.0f", number)
} else {
return p.Sprintf("%.2f", number)
}
return p.Sprintf("%.2f", number)
}