github.com/gogf/gf/v2@v2.7.4/i18n/gi18n/gi18n_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 gi18n 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 is the instances map for management 18 // for multiple i18n instance by name. 19 instances = gmap.NewStrAnyMap(true) 20 ) 21 22 // Instance returns an instance of Resource. 23 // The parameter `name` is the name for the instance. 24 func Instance(name ...string) *Manager { 25 key := DefaultName 26 if len(name) > 0 && name[0] != "" { 27 key = name[0] 28 } 29 return instances.GetOrSetFuncLock(key, func() interface{} { 30 return New() 31 }).(*Manager) 32 }