many small improvements

This commit is contained in:
Christoph Haas
2020-11-10 22:23:05 +01:00
parent e09ef939c0
commit eb51c2dd74
20 changed files with 252 additions and 115 deletions

View File

@@ -62,6 +62,7 @@ type Config struct {
AdminUser string `yaml:"adminUser" envconfig:"ADMIN_USER"` // optional, non LDAP admin user
AdminPassword string `yaml:"adminPass" envconfig:"ADMIN_PASS"`
DatabasePath string `yaml:"database" envconfig:"DATABASE_PATH"`
EditableKeys bool `yaml:"editableKeys" envconfig:"EDITABLE_KEYS"`
} `yaml:"core"`
Email MailConfig `yaml:"email"`
LDAP ldap.Config `yaml:"ldap"`

View File

@@ -1,6 +1,7 @@
package common
import (
"fmt"
"net"
"strings"
)
@@ -55,3 +56,18 @@ func ParseStringList(lst string) []string {
func ListToString(lst []string) string {
return strings.Join(lst, ", ")
}
// https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format/
func ByteCountSI(b int64) string {
const unit = 1000
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %cB",
float64(b)/float64(div), "kMGTPE"[exp])
}