github.com/tobgu/qframe@v0.4.0/config/newqf/config.go (about) 1 package newqf 2 3 // Config holds configuration for creating new QFrames using the New constructor. 4 // It should be considered a private implementation detail and should never be 5 // referenced or used directly outside of the QFrame code. To manipulate it 6 // use the functions returning ConfigFunc below. 7 type Config struct { 8 ColumnOrder []string 9 EnumColumns map[string][]string 10 } 11 12 // ConfigFunc is a function that operates on a Config object. 13 type ConfigFunc func(c *Config) 14 15 // NewConfig creates a new Config object. 16 // This function should never be called from outside QFrame. 17 func NewConfig(fns []ConfigFunc) *Config { 18 // TODO: This function returns a pointer while most of the other returns values. Decide which way to do it. 19 config := &Config{} 20 for _, fn := range fns { 21 fn(config) 22 } 23 return config 24 } 25 26 // ColumnOrder provides the order in which columns are displayed, etc. 27 func ColumnOrder(columns ...string) ConfigFunc { 28 return func(c *Config) { 29 c.ColumnOrder = make([]string, len(columns)) 30 copy(c.ColumnOrder, columns) 31 } 32 } 33 34 // Enums lists columns that should be considered enums. 35 // The map key specifies the columns name, the value if there is a fixed set of 36 // values and their internal ordering. If value is nil or empty list the values 37 // will be derived from the columns content and the ordering unspecified. 38 func Enums(columns map[string][]string) ConfigFunc { 39 return func(c *Config) { 40 c.EnumColumns = make(map[string][]string) 41 for k, v := range columns { 42 c.EnumColumns[k] = v 43 } 44 } 45 }