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