normalize thumbnails

This commit is contained in:
A.Unger
2021-11-08 12:25:15 +01:00
parent 23cfb909eb
commit f76dfc9af1
5 changed files with 22 additions and 104 deletions

View File

@@ -2,23 +2,12 @@ package config
import (
"context"
"fmt"
"path"
"reflect"
gofig "github.com/gookit/config/v2"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
"github.com/owncloud/ocis/ocis-pkg/shared"
)
// Log defines the available logging configuration.
type Log struct {
Level string `mapstructure:"level"`
Pretty bool `mapstructure:"pretty"`
Color bool `mapstructure:"color"`
File string `mapstructure:"file"`
}
// Debug defines the available debug configuration.
type Debug struct {
Addr string `mapstructure:"addr"`
@@ -46,12 +35,12 @@ type Tracing struct {
// Config combines all available configuration parts.
type Config struct {
File string `mapstructure:"file"`
Log Log `mapstructure:"log"`
Debug Debug `mapstructure:"debug"`
Server Server `mapstructure:"server"`
Tracing Tracing `mapstructure:"tracing"`
Thumbnail Thumbnail `mapstructure:"thumbnail"`
File string `mapstructure:"file"`
Log shared.Log `mapstructure:"log"`
Debug Debug `mapstructure:"debug"`
Server Server `mapstructure:"server"`
Tracing Tracing `mapstructure:"tracing"`
Thumbnail Thumbnail `mapstructure:"thumbnail"`
Context context.Context
Supervised bool
@@ -83,7 +72,7 @@ func New() *Config {
func DefaultConfig() *Config {
return &Config{
Log: Log{},
Log: shared.Log{},
Debug: Debug{
Addr: "127.0.0.1:9189",
Token: "",
@@ -124,38 +113,3 @@ func GetEnv() []string {
return r
}
// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination.
func (c *Config) UnmapEnv(gooconf *gofig.Config) error {
vals := structMappings(c)
for i := range vals {
for j := range vals[i].EnvVars {
// we need to guard against v != "" because this is the condition that checks that the value is set from the environment.
// the `ok` guard is not enough, apparently.
if v, ok := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" {
// get the destination type from destination
switch reflect.ValueOf(vals[i].Destination).Type().String() {
case "*bool":
r := gooconf.Bool(vals[i].EnvVars[j])
*vals[i].Destination.(*bool) = r
case "*string":
r := gooconf.String(vals[i].EnvVars[j])
*vals[i].Destination.(*string) = r
case "*int":
r := gooconf.Int(vals[i].EnvVars[j])
*vals[i].Destination.(*int) = r
case "*float64":
// defaults to float64
r := gooconf.Float(vals[i].EnvVars[j])
*vals[i].Destination.(*float64) = r
default:
// it is unlikely we will ever get here. Let this serve more as a runtime check for when debugging.
return fmt.Errorf("invalid type for env var: `%v`", vals[i].EnvVars[j])
}
}
}
}
return nil
}

View File

@@ -1,13 +1,17 @@
package config
type mapping struct {
EnvVars []string // name of the EnvVars var.
Destination interface{} // memory address of the original config value to modify.
import "github.com/owncloud/ocis/ocis-pkg/shared"
// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the
// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets
// us propagate changes easier.
func StructMappings(cfg *Config) []shared.EnvBinding {
return structMappings(cfg)
}
// structMappings binds a set of environment variables to a destination on cfg.
func structMappings(cfg *Config) []mapping {
return []mapping{
func structMappings(cfg *Config) []shared.EnvBinding {
return []shared.EnvBinding{
{
EnvVars: []string{"THUMBNAILS_LOG_FILE", "OCIS_LOG_FILE"},
Destination: &cfg.Log.File,