github.com/gogf/gf/v2@v2.7.4/os/gview/gview_instance.go (about) 1 // Copyright GoFrame Author(https://goframe.org). 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/gogf/gf. 6 7 package gview 8 9 import "github.com/gogf/gf/v2/container/gmap" 10 11 const ( 12 // DefaultName is the default group name for instance usage. 13 DefaultName = "default" 14 ) 15 16 var ( 17 // Instances map. 18 instances = gmap.NewStrAnyMap(true) 19 ) 20 21 // Instance returns an instance of View with default settings. 22 // The parameter `name` is the name for the instance. 23 func Instance(name ...string) *View { 24 key := DefaultName 25 if len(name) > 0 && name[0] != "" { 26 key = name[0] 27 } 28 return instances.GetOrSetFuncLock(key, func() interface{} { 29 return New() 30 }).(*View) 31 }