2015-02-02 01:51:01 +02:00
|
|
|
package authboss
|
|
|
|
|
2015-02-20 00:34:29 +02:00
|
|
|
// HTMLData is used to render templates with.
|
|
|
|
type HTMLData map[string]interface{}
|
|
|
|
|
|
|
|
// NewHTMLData creates HTMLData from key-value pairs. The input is a key-value
|
|
|
|
// slice, where odd elements are keys, and the following even element is their value.
|
|
|
|
func NewHTMLData(data ...interface{}) HTMLData {
|
|
|
|
if len(data)%2 != 0 {
|
|
|
|
panic("It should be a key value list of arguments.")
|
|
|
|
}
|
|
|
|
|
|
|
|
h := make(HTMLData)
|
|
|
|
|
|
|
|
for i := 0; i < len(data)-1; i += 2 {
|
|
|
|
k, ok := data[i].(string)
|
|
|
|
if !ok {
|
|
|
|
panic("Keys must be strings.")
|
|
|
|
}
|
|
|
|
|
|
|
|
h[k] = data[i+1]
|
|
|
|
}
|
|
|
|
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge adds extra key-values to the HTMLData. The input is a key-value
|
|
|
|
// slice, where odd elements are keys, and the following even element is their value.
|
|
|
|
func (h HTMLData) Merge(data ...interface{}) HTMLData {
|
|
|
|
if len(data)%2 != 0 {
|
|
|
|
panic("It should be a key value list of arguments.")
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(data)-1; i += 2 {
|
|
|
|
k, ok := data[i].(string)
|
|
|
|
if !ok {
|
|
|
|
panic("Keys must be strings.")
|
|
|
|
}
|
2015-02-20 00:50:14 +02:00
|
|
|
|
|
|
|
h[k] = data[i+1]
|
2015-02-20 00:34:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return h
|
2015-02-02 01:51:01 +02:00
|
|
|
}
|