github.com/psiphon-inc/goarista@v0.0.0-20160825065156-d002785f4c67/value/value.go (about)

     1  // Copyright (C) 2016  Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  // Package value defines an interface for user-defined types with value
     6  // semantics to implement in order to be compatible with the rest of the
     7  // Arista Go infrastructure.
     8  package value
     9  
    10  import (
    11  	"encoding/json"
    12  	"fmt"
    13  )
    14  
    15  // Value is the interface that all types with value semantics must implement
    16  // in order to be compatible with the Entity infrastructure and streaming
    17  // protocols we support.  By default all value types are just represented as
    18  // a map[string]interface{}, but when a TypeMapper is used to remap the value
    19  // to a user-defined type (as opposed to a built-in type), then these user
    20  // defined types must fulfill the contract defined by this interface.
    21  //
    22  // Types that implement this interface must have value semantics, meaning they
    23  // are not allowed to contain anything with pointer semantics such as slices,
    24  // maps, channels, etc.  They must be directly usable as keys in maps and
    25  // behave properly when compared with the built-in == operator.
    26  type Value interface {
    27  	fmt.Stringer
    28  	json.Marshaler
    29  
    30  	// ToBuiltin returns the best possible representation of this type as one
    31  	// of the built-in types we support.  Most often this means returning the
    32  	// string representation of this type (for example for an IP address or an
    33  	// IP prefix), but sometimes not (e.g. a VLAN ID is better represented as
    34  	// uint16).
    35  	ToBuiltin() interface{}
    36  }