github.com/zhongdalu/gf@v1.0.0/g/os/gview/gview_instance.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 import "github.com/zhongdalu/gf/g/container/gmap" 10 11 const ( 12 // Default group name for instance usage. 13 DEFAULT_INSTANCE_NAME = "default" 14 ) 15 16 var ( 17 // Instances map. 18 instances = gmap.NewStrAnyMap() 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 := DEFAULT_INSTANCE_NAME 25 if len(name) > 0 { 26 key = name[0] 27 } 28 return instances.GetOrSetFuncLock(key, func() interface{} { 29 return New() 30 }).(*View) 31 }