You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/vendor/github.com/gogf/gf/v2/util/gtag/gtag_enums.go

38 lines
1.0 KiB

// 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 gtag
import (
"github.com/gogf/gf/v2/internal/json"
)
var (
// Type name => enums json.
enumsMap = make(map[string]json.RawMessage)
)
// SetGlobalEnums sets the global enums into package.
// Note that this operation is not concurrent safety.
func SetGlobalEnums(enumsJson string) error {
return json.Unmarshal([]byte(enumsJson), &enumsMap)
}
// GetGlobalEnums retrieves and returns the global enums.
func GetGlobalEnums() (string, error) {
enumsByes, err := json.Marshal(enumsMap)
if err != nil {
return "", err
}
return string(enumsByes), nil
}
// GetEnumsByType retrieves and returns the stored enums json by type name.
// The type name is like: github.com/gogf/gf/v2/encoding/gjson.ContentType
func GetEnumsByType(typeName string) string {
return string(enumsMap[typeName])
}