github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/thirdparty/eventlog/loggable.go (about)

     1  package eventlog
     2  
     3  // Loggable describes objects that can be marshalled into Metadata for logging
     4  type Loggable interface {
     5  	Loggable() map[string]interface{}
     6  }
     7  
     8  type LoggableMap map[string]interface{}
     9  
    10  func (l LoggableMap) Loggable() map[string]interface{} {
    11  	return l
    12  }
    13  
    14  // LoggableF converts a func into a Loggable
    15  type LoggableF func() map[string]interface{}
    16  
    17  func (l LoggableF) Loggable() map[string]interface{} {
    18  	return l()
    19  }
    20  
    21  func Deferred(key string, f func() string) Loggable {
    22  	function := func() map[string]interface{} {
    23  		return map[string]interface{}{
    24  			key: f(),
    25  		}
    26  	}
    27  	return LoggableF(function)
    28  }
    29  
    30  func Pair(key string, l Loggable) Loggable {
    31  	return LoggableMap{
    32  		key: l,
    33  	}
    34  }