mirror of
https://github.com/miniflux/v2.git
synced 2025-08-21 18:11:09 +00:00
Move template functions outside engine (refactoring)
This commit is contained in:
parent
b5b1930599
commit
3884a33b36
9 changed files with 254 additions and 214 deletions
22
template/dict.go
Normal file
22
template/dict.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package template
|
||||
|
||||
import "fmt"
|
||||
|
||||
func dict(values ...interface{}) (map[string]interface{}, error) {
|
||||
if len(values)%2 != 0 {
|
||||
return nil, fmt.Errorf("Dict expects an even number of arguments")
|
||||
}
|
||||
dict := make(map[string]interface{}, len(values)/2)
|
||||
for i := 0; i < len(values); i += 2 {
|
||||
key, ok := values[i].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Dict keys must be strings")
|
||||
}
|
||||
dict[key] = values[i+1]
|
||||
}
|
||||
return dict, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue