value.go 1.5 KB

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