github.com/zhongdalu/gf@v1.0.0/g/os/gview/gview_config.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 7 package gview 8 9 // Assign binds multiple template variables to current view object. 10 // Each goroutine will take effect after the call, so it is concurrent-safe. 11 func (view *View) Assigns(data Params) { 12 view.mu.Lock() 13 for k, v := range data { 14 view.data[k] = v 15 } 16 view.mu.Unlock() 17 } 18 19 // Assign binds a template variable to current view object. 20 // Each goroutine will take effect after the call, so it is concurrent-safe. 21 func (view *View) Assign(key string, value interface{}) { 22 view.mu.Lock() 23 view.data[key] = value 24 view.mu.Unlock() 25 } 26 27 // SetDelimiters sets customized delimiters for template parsing. 28 func (view *View) SetDelimiters(left, right string) { 29 view.mu.Lock() 30 view.delimiters[0] = left 31 view.delimiters[1] = right 32 view.mu.Unlock() 33 } 34 35 // BindFunc registers customized template function named <name> 36 // with given function <function> to current view object. 37 // The <name> is the function name which can be called in template content. 38 func (view *View) BindFunc(name string, function interface{}) { 39 view.mu.Lock() 40 view.funcMap[name] = function 41 view.mu.Unlock() 42 } 43 44 // BindFuncMap registers customized template functions by map to current view object. 45 // The key of map is the template function name 46 // and the value of map is the address of customized function. 47 func (view *View) BindFuncMap(funcMap FuncMap) { 48 view.mu.Lock() 49 for k, v := range funcMap { 50 view.funcMap[k] = v 51 } 52 view.mu.Unlock() 53 }