2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2019-04-03 23:39:31 +08:00
|
|
|
//
|
|
|
|
|
// 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"
|
2019-04-03 23:39:31 +08:00
|
|
|
|
|
|
|
|
const (
|
2021-12-30 00:20:38 +08:00
|
|
|
// DefaultName is the default group name for instance usage.
|
2020-12-14 13:02:08 +08:00
|
|
|
DefaultName = "default"
|
2019-04-03 23:39:31 +08:00
|
|
|
)
|
2019-06-19 09:06:52 +08:00
|
|
|
|
2019-04-03 23:39:31 +08:00
|
|
|
var (
|
|
|
|
|
// Instances map.
|
2019-07-23 23:20:27 +08:00
|
|
|
instances = gmap.NewStrAnyMap(true)
|
2019-04-03 23:39:31 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Instance returns an instance of View with default settings.
|
2021-08-25 20:00:53 +08:00
|
|
|
// The parameter `name` is the name for the instance.
|
2019-04-03 23:39:31 +08:00
|
|
|
func Instance(name ...string) *View {
|
2020-12-14 13:02:08 +08:00
|
|
|
key := DefaultName
|
2019-07-28 17:37:13 +08:00
|
|
|
if len(name) > 0 && name[0] != "" {
|
2019-04-03 23:39:31 +08:00
|
|
|
key = name[0]
|
|
|
|
|
}
|
|
|
|
|
return instances.GetOrSetFuncLock(key, func() interface{} {
|
|
|
|
|
return New()
|
|
|
|
|
}).(*View)
|
|
|
|
|
}
|