gf/i18n/gi18n/gi18n_instance.go

32 lines
778 B
Go
Raw Normal View History

2019-08-31 18:04:12 +08:00
// Copyright 2019 gf Author(https://github.com/gogf/gf). 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 gi18n
import "github.com/gogf/gf/container/gmap"
const (
// Default group name for instance usage.
DEFAULT_NAME = "default"
)
var (
// Instances map.
instances = gmap.NewStrAnyMap(true)
)
// Instance returns an instance of Resource.
// The parameter <name> is the name for the instance.
2019-09-01 00:30:01 +08:00
func Instance(name ...string) *Manager {
2019-08-31 18:04:12 +08:00
key := DEFAULT_NAME
if len(name) > 0 && name[0] != "" {
key = name[0]
}
return instances.GetOrSetFuncLock(key, func() interface{} {
return New()
2019-09-01 00:30:01 +08:00
}).(*Manager)
2019-08-31 18:04:12 +08:00
}