Files
gf/os/gview/gview_instance.go

32 lines
803 B
Go
Raw Permalink Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gview
2021-10-11 21:41:56 +08:00
import "github.com/gogf/gf/v2/container/gmap"
const (
2021-12-30 00:20:38 +08:00
// DefaultName is the default group name for instance usage.
DefaultName = "default"
)
2019-06-19 09:06:52 +08:00
var (
// Instances map.
instances = gmap.NewStrAnyMap(true)
)
// Instance returns an instance of View with default settings.
// The parameter `name` is the name for the instance.
func Instance(name ...string) *View {
key := DefaultName
2019-07-28 17:37:13 +08:00
if len(name) > 0 && name[0] != "" {
key = name[0]
}
return instances.GetOrSetFuncLock(key, func() interface{} {
return New()
}).(*View)
}