using reflect to set values in the config
This commit is contained in:
parent
bbe7c76ae0
commit
0de632d29c
@ -1,9 +1,11 @@
|
|||||||
package rendering
|
package rendering
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
type RenderingConfig struct {
|
type RenderingConfig struct {
|
||||||
HeaderPhrases []string
|
HeaderPhrases []string
|
||||||
BackgroundScrollX float32
|
BackgroundScrollX string
|
||||||
BackgroundScrollY float32
|
BackgroundScrollY string
|
||||||
PageTitle string
|
PageTitle string
|
||||||
SearchPlaceholder string
|
SearchPlaceholder string
|
||||||
SearchFormAction string
|
SearchFormAction string
|
||||||
@ -21,11 +23,20 @@ func DefaultRenderingConfig() RenderingConfig {
|
|||||||
"Nazi.Punch()",
|
"Nazi.Punch()",
|
||||||
"Dolls.GiveGuns()",
|
"Dolls.GiveGuns()",
|
||||||
},
|
},
|
||||||
BackgroundScrollX: 1,
|
BackgroundScrollX: "1",
|
||||||
BackgroundScrollY: 0,
|
BackgroundScrollY: "0",
|
||||||
PageTitle: "TransRights",
|
PageTitle: "TransRights",
|
||||||
SearchPlaceholder: "Search on DuckDuckGo",
|
SearchPlaceholder: "Search on DuckDuckGo",
|
||||||
SearchFormAction: "https://duckduckgo.com/",
|
SearchFormAction: "https://duckduckgo.com/",
|
||||||
SearchInputName: "q",
|
SearchInputName: "q",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *RenderingConfig) Set(key string, value string) {
|
||||||
|
// https://gist.github.com/kilfu0701/77c614386483782f68bc5538b6100730
|
||||||
|
r := reflect.ValueOf(rc)
|
||||||
|
f := reflect.Indirect(r).FieldByName(key)
|
||||||
|
if f.Kind() != reflect.Invalid {
|
||||||
|
f.SetString(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user