gsvc_metadata.go 867 B

123456789101112131415161718192021222324252627282930313233343536
  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. package gsvc
  7. import (
  8. "github.com/gogf/gf/v2/container/gvar"
  9. )
  10. // Set sets key-value pair into metadata.
  11. func (m Metadata) Set(key string, value string) {
  12. m[key] = value
  13. }
  14. // Sets sets key-value pairs into metadata.
  15. func (m Metadata) Sets(kvs map[string]interface{}) {
  16. for k, v := range kvs {
  17. m[k] = v
  18. }
  19. }
  20. // Get retrieves and returns value of specified key as gvar.
  21. func (m Metadata) Get(key string) *gvar.Var {
  22. if v, ok := m[key]; ok {
  23. return gvar.New(v)
  24. }
  25. return nil
  26. }
  27. // IsEmpty checks and returns whether current Metadata is empty.
  28. func (m Metadata) IsEmpty() bool {
  29. return len(m) == 0
  30. }