github.com/gogf/gf/v2@v2.7.4/util/gtag/gtag_enums.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 gtag 8 9 import ( 10 "github.com/gogf/gf/v2/internal/json" 11 ) 12 13 var ( 14 // Type name => enums json. 15 enumsMap = make(map[string]json.RawMessage) 16 ) 17 18 // SetGlobalEnums sets the global enums into package. 19 // Note that this operation is not concurrent safety. 20 func SetGlobalEnums(enumsJson string) error { 21 return json.Unmarshal([]byte(enumsJson), &enumsMap) 22 } 23 24 // GetGlobalEnums retrieves and returns the global enums. 25 func GetGlobalEnums() (string, error) { 26 enumsBytes, err := json.Marshal(enumsMap) 27 if err != nil { 28 return "", err 29 } 30 return string(enumsBytes), nil 31 } 32 33 // GetEnumsByType retrieves and returns the stored enums json by type name. 34 // The type name is like: github.com/gogf/gf/v2/encoding/gjson.ContentType 35 func GetEnumsByType(typeName string) string { 36 return string(enumsMap[typeName]) 37 }