Documentation

Overview

    Package cue is a transition package for supporting the cue.Value API. It aims to be plugin compatible with the old API.

    Index

    Examples

    Constants

    View Source
    const (
    	NoOp = adt.NoOp
    
    	AndOp = adt.AndOp
    	OrOp  = adt.OrOp
    
    	SelectorOp = adt.SelectorOp
    	IndexOp    = adt.IndexOp
    	SliceOp    = adt.SliceOp
    	CallOp     = adt.CallOp
    
    	BooleanAndOp = adt.BoolAndOp
    	BooleanOrOp  = adt.BoolOrOp
    
    	EqualOp            = adt.EqualOp
    	NotOp              = adt.NotOp
    	NotEqualOp         = adt.NotEqualOp
    	LessThanOp         = adt.LessThanOp
    	LessThanEqualOp    = adt.LessEqualOp
    	GreaterThanOp      = adt.GreaterThanOp
    	GreaterThanEqualOp = adt.GreaterEqualOp
    
    	RegexMatchOp    = adt.MatchOp
    	NotRegexMatchOp = adt.NotMatchOp
    
    	AddOp           = adt.AddOp
    	SubtractOp      = adt.SubtractOp
    	MultiplyOp      = adt.MultiplyOp
    	FloatQuotientOp = adt.FloatQuotientOp
    	IntQuotientOp   = adt.IntQuotientOp
    	IntRemainderOp  = adt.IntRemainderOp
    	IntDivideOp     = adt.IntDivideOp
    	IntModuloOp     = adt.IntModuloOp
    
    	InterpolationOp = adt.InterpolationOp
    )

      Values of Op.

      View Source
      const (
      	// NullKind indicates a null value.
      	NullKind Kind = adt.NullKind
      
      	// BoolKind indicates a boolean value.
      	BoolKind = adt.BoolKind
      
      	// IntKind represents an integral number.
      	IntKind = adt.IntKind
      
      	// FloatKind represents a decimal float point number that cannot be
      	// converted to an integer. The underlying number may still be integral,
      	// but resulting from an operation that enforces the float type.
      	FloatKind = adt.FloatKind
      
      	// StringKind indicates any kind of string.
      	StringKind = adt.StringKind
      
      	// BytesKind is a blob of data.
      	BytesKind = adt.BytesKind
      
      	// StructKind is a kev-value map.
      	StructKind = adt.StructKind
      
      	// ListKind indicates a list of values.
      	ListKind = adt.ListKind
      
      	// NumberKind represents any kind of number.
      	NumberKind = IntKind | FloatKind
      
      	TopKind = adt.TopKind
      )

      Variables

      View Source
      var (
      
      	// AnyIndex can be used to ask for any index.
      	//
      	// In paths it is used to select constraints that apply to all elements.
      	AnyIndex = anyIndex
      
      	// AnyString can be used to ask for any regular string field.
      	//
      	// In paths it is used to select constraints that apply to all elements.
      	AnyString = anyLabel
      )
      View Source
      var (
      	// ErrBelow indicates that a value was rounded down in a conversion.
      	ErrBelow = errors.New("value was rounded down")
      
      	// ErrAbove indicates that a value was rounded up in a conversion.
      	ErrAbove = errors.New("value was rounded up")
      
      	// ErrInfinite indicates that a value is infinite.
      	ErrInfinite = errors.New("infinite")
      )

      Functions

      func NewRuntime

      func NewRuntime() *runtime.Runtime

        NewRuntime creates a *runtime.Runtime with builtins preloaded.

        Types

        type AttrKind

        type AttrKind int

          AttrKind indicates the location of an attribute within CUE source.

          const (
          	// FieldAttr indicates a field attribute.
          	// foo: bar @attr()
          	FieldAttr AttrKind = AttrKind(internal.FieldAttr)
          
          	// DeclAttr indicates a declaration attribute.
          	// foo: {
          	//     @attr()
          	// }
          	DeclAttr AttrKind = AttrKind(internal.DeclAttr)
          
          	// A ValueAttr is a bit mask to request any attribute that is locally
          	// associated with a field, instead of, for instance, an entire file.
          	ValueAttr AttrKind = FieldAttr | DeclAttr
          )

          type Attribute

          type Attribute struct {
          	// contains filtered or unexported fields
          }

            An Attribute contains meta data about a field.

            func (*Attribute) Arg

            func (a *Attribute) Arg(i int) (key, value string)

              Arg reports the contents of the ith comma-separated argument of a.

              If the argument contains an unescaped equals sign, it returns a key-value pair. Otherwise it returns the contents in value.

              func (*Attribute) Contents

              func (a *Attribute) Contents() string

                Contents reports the full contents of an attribute within parentheses, so contents in @attr(contents).

                func (*Attribute) Err

                func (a *Attribute) Err() error

                  Err returns the error associated with this Attribute or nil if this attribute is valid.

                  func (*Attribute) Flag

                  func (a *Attribute) Flag(pos int, key string) (bool, error)

                    Flag reports whether an entry with the given name exists at position pos or onwards or an error if the attribute is invalid or if the first pos-1 entries are not defined.

                    func (Attribute) Format

                    func (a Attribute) Format(w fmt.State, verb rune)

                      Format implements fmt.Formatter.

                      func (*Attribute) Int

                      func (a *Attribute) Int(pos int) (int64, error)

                        Int reports the integer at the given position or an error if the attribute is invalid, the position does not exist, or the value at the given position is not an integer.

                        func (*Attribute) Kind

                        func (a *Attribute) Kind() AttrKind

                          Kind reports the type of location within CUE source where the attribute was specified.

                          func (*Attribute) Lookup

                          func (a *Attribute) Lookup(pos int, key string) (val string, found bool, err error)

                            Lookup searches for an entry of the form key=value from position pos onwards and reports the value if found. It reports an error if the attribute is invalid or if the first pos-1 entries are not defined.

                            func (*Attribute) Name

                            func (a *Attribute) Name() string

                              Name returns the name of the attribute, for instance, "json" for @json(...).

                              func (*Attribute) NumArgs

                              func (a *Attribute) NumArgs() int

                                NumArgs reports the number of arguments parsed for this attribute.

                                func (*Attribute) RawArg

                                func (a *Attribute) RawArg(i int) string

                                  RawArg reports the raw contents of the ith comma-separated argument of a, including surrounding spaces.

                                  func (*Attribute) String

                                  func (a *Attribute) String(pos int) (string, error)

                                    String reports the possibly empty string value at the given position or an error the attribute is invalid or if the position does not exist.

                                    type FieldInfo

                                    type FieldInfo struct {
                                    	Selector string
                                    	Name     string // Deprecated: use Selector
                                    	Pos      int
                                    	Value    Value
                                    
                                    	IsDefinition bool
                                    	IsOptional   bool
                                    	IsHidden     bool
                                    }

                                      FieldInfo contains information about a struct field.

                                      type Instance

                                      type Instance struct {
                                      	ImportPath  string
                                      	Dir         string
                                      	PkgName     string
                                      	DisplayName string
                                      
                                      	Incomplete bool         // true if Pkg and all its dependencies are free of errors
                                      	Err        errors.Error // non-nil if the package had errors
                                      	// contains filtered or unexported fields
                                      }

                                        An Instance defines a single configuration based on a collection of underlying CUE files.

                                        func Build

                                        func Build(instances []*build.Instance) []*Instance

                                          Build creates one Instance for each build.Instance. A returned Instance may be incomplete, in which case its Err field is set.

                                          Example:

                                          inst := cue.Build(load.Instances(args))
                                          

                                          func Merge

                                          func Merge(inst ...*Instance) *Instance

                                            DO NOT USE.

                                            Deprecated: do not use.

                                            func (*Instance) Build

                                            func (inst *Instance) Build(p *build.Instance) *Instance

                                              Build creates a new instance from the build instances, allowing unbound identifier to bind to the top-level field in inst. The top-level fields in inst take precedence over predeclared identifier and builtin functions.

                                              func (*Instance) Doc

                                              func (inst *Instance) Doc() []*ast.CommentGroup

                                                Doc returns the package comments for this instance.

                                                func (*Instance) Eval

                                                func (inst *Instance) Eval(expr ast.Expr) Value

                                                  Eval evaluates an expression within an existing instance.

                                                  Expressions may refer to builtin packages if they can be uniquely identified.

                                                  func (*Instance) Fill

                                                  func (inst *Instance) Fill(x interface{}, path ...string) (*Instance, error)

                                                    Fill creates a new instance with the values of the old instance unified with the given value. It is not possible to update the emit value.

                                                    Values may be any Go value that can be converted to CUE, an ast.Expr or a Value. In the latter case, it will panic if the Value is not from the same Runtime.

                                                    func (*Instance) ID

                                                    func (inst *Instance) ID() string

                                                      ID returns the package identifier that uniquely qualifies module and package name.

                                                      func (*Instance) Lookup

                                                      func (inst *Instance) Lookup(path ...string) Value

                                                        Lookup reports the value at a path starting from the top level struct. The Exists method of the returned value will report false if the path did not exist. The Err method reports if any error occurred during evaluation. The empty path returns the top-level configuration struct. Use LookupDef for definitions or LookupField for any kind of field.

                                                        func (*Instance) LookupDef

                                                        func (inst *Instance) LookupDef(path string) Value

                                                          LookupDef reports the definition with the given name within struct v. The Exists method of the returned value will report false if the definition did not exist. The Err method reports if any error occurred during evaluation.

                                                          func (*Instance) LookupField

                                                          func (inst *Instance) LookupField(path ...string) (f FieldInfo, err error)

                                                            LookupField reports a Field at a path starting from v, or an error if the path is not. The empty path returns v itself.

                                                            It cannot look up hidden or unexported fields.

                                                            Deprecated: this API does not work with new-style definitions. Use FieldByName defined on inst.Value().

                                                            func (*Instance) Value

                                                            func (inst *Instance) Value() Value

                                                              Value returns the root value of the configuration. If the configuration defines in emit value, it will be that value. Otherwise it will be all top-level values.

                                                              type Iterator

                                                              type Iterator struct {
                                                              	// contains filtered or unexported fields
                                                              }

                                                                An Iterator iterates over values.

                                                                func (*Iterator) Feature

                                                                func (i *Iterator) Feature() adt.Feature

                                                                func (*Iterator) IsDefinition

                                                                func (i *Iterator) IsDefinition() bool

                                                                  IsDefinition reports if a field is a definition.

                                                                  func (*Iterator) IsHidden

                                                                  func (i *Iterator) IsHidden() bool

                                                                    IsHidden reports if a field is hidden from the data model.

                                                                    func (*Iterator) IsOptional

                                                                    func (i *Iterator) IsOptional() bool

                                                                      IsOptional reports if a field is optional.

                                                                      func (*Iterator) Label

                                                                      func (i *Iterator) Label() string

                                                                        Label reports the label of the value if i iterates over struct fields and "" otherwise.

                                                                        func (*Iterator) Next

                                                                        func (i *Iterator) Next() bool

                                                                          Next advances the iterator to the next value and reports whether there was any. It must be called before the first call to Value or Key.

                                                                          func (*Iterator) Value

                                                                          func (i *Iterator) Value() Value

                                                                            Value returns the current value in the list. It will panic if Next advanced past the last entry.

                                                                            type Kind

                                                                            type Kind = adt.Kind

                                                                              Kind determines the underlying type of a Value.

                                                                              const BottomKind Kind = 0

                                                                              type Op

                                                                              type Op = adt.Op

                                                                                Op indicates the operation at the top of an expression tree of the expression use to evaluate a value.

                                                                                type Option

                                                                                type Option option

                                                                                  An Option defines modes of evaluation.

                                                                                  func All

                                                                                  func All() Option

                                                                                    All indicates that all fields and values should be included in processing even if they can be elided or omitted.

                                                                                    func Attributes

                                                                                    func Attributes(include bool) Option

                                                                                      Attributes indicates that attributes should be included.

                                                                                      func Concrete

                                                                                      func Concrete(concrete bool) Option

                                                                                        Concrete ensures that all values are concrete.

                                                                                        For Validate this means it returns an error if this is not the case. In other cases a non-concrete value will be replaced with an error.

                                                                                        func Definitions

                                                                                        func Definitions(include bool) Option

                                                                                          Definitions indicates whether definitions should be included.

                                                                                          Definitions may still be included for certain functions if they are referred to by other other values.

                                                                                          func DisallowCycles

                                                                                          func DisallowCycles(disallow bool) Option

                                                                                            DisallowCycles forces validation in the precense of cycles, even if non-concrete values are allowed. This is implied by Concrete(true).

                                                                                            func Docs

                                                                                            func Docs(include bool) Option

                                                                                              Docs indicates whether docs should be included.

                                                                                              func Final

                                                                                              func Final() Option

                                                                                                Final indicates a value is final. It implicitly closes all structs and lists in a value and selects defaults.

                                                                                                func Hidden

                                                                                                func Hidden(include bool) Option

                                                                                                  Hidden indicates that definitions and hidden fields should be included.

                                                                                                  Deprecated: Hidden fields are deprecated.

                                                                                                  func Optional

                                                                                                  func Optional(include bool) Option

                                                                                                    Optional indicates that optional fields should be included.

                                                                                                    func Raw

                                                                                                    func Raw() Option

                                                                                                      Raw tells Syntax to generate the value as is without any simplifications.

                                                                                                      func ResolveReferences

                                                                                                      func ResolveReferences(resolve bool) Option

                                                                                                        ResolveReferences forces the evaluation of references when outputting. This implies the input cannot have cycles.

                                                                                                        func Schema

                                                                                                        func Schema() Option

                                                                                                          Schema specifies the input is a Schema. Used by Subsume.

                                                                                                          type Path

                                                                                                          type Path struct {
                                                                                                          	// contains filtered or unexported fields
                                                                                                          }

                                                                                                            A Path is series of selectors to query a CUE value.

                                                                                                            func MakePath

                                                                                                            func MakePath(selectors ...Selector) Path

                                                                                                              MakePath creates a Path from a sequence of selectors.

                                                                                                              func ParsePath

                                                                                                              func ParsePath(s string) Path

                                                                                                                ParsePath parses a CUE expression into a Path. Any error resulting from this conversion can be obtained by calling Err on the result.

                                                                                                                Unlike with normal CUE expressions, the first element of the path may be a string literal.

                                                                                                                A path may not contain hidden fields. To create a path with hidden fields, use MakePath and Ident.

                                                                                                                func (Path) Err

                                                                                                                func (p Path) Err() error

                                                                                                                  Err reports errors that occurred when generating the path.

                                                                                                                  func (Path) Optional

                                                                                                                  func (p Path) Optional() Path

                                                                                                                    Optional returns the optional form of a Path. For instance,

                                                                                                                    foo.bar  --> foo?.bar?
                                                                                                                    

                                                                                                                    func (Path) Selectors

                                                                                                                    func (p Path) Selectors() []Selector

                                                                                                                      Selectors reports the individual selectors of a path.

                                                                                                                      func (Path) String

                                                                                                                      func (p Path) String() string

                                                                                                                        String reports the CUE representation of p.

                                                                                                                        type Runtime

                                                                                                                        type Runtime struct {
                                                                                                                        	// contains filtered or unexported fields
                                                                                                                        }

                                                                                                                          A Runtime is used for creating CUE interpretations.

                                                                                                                          Any operation that involves two Values or Instances should originate from the same Runtime.

                                                                                                                          The zero value of a Runtime is ready to use.

                                                                                                                          func (*Runtime) Build

                                                                                                                          func (r *Runtime) Build(instance *build.Instance) (*Instance, error)

                                                                                                                            Build creates an Instance from the given build.Instance. A returned Instance may be incomplete, in which case its Err field is set.

                                                                                                                            func (*Runtime) Compile

                                                                                                                            func (r *Runtime) Compile(filename string, source interface{}) (*Instance, error)

                                                                                                                              Compile compiles the given source into an Instance. The source code may be provided as a string, byte slice, io.Reader. The name is used as the file name in position information. The source may import builtin packages. Use Build to allow importing non-builtin packages.

                                                                                                                              func (*Runtime) CompileExpr

                                                                                                                              func (r *Runtime) CompileExpr(expr ast.Expr) (*Instance, error)

                                                                                                                                CompileExpr compiles the given source expression into an Instance. The source may import builtin packages. Use Build to allow importing non-builtin packages.

                                                                                                                                func (*Runtime) CompileFile

                                                                                                                                func (r *Runtime) CompileFile(file *ast.File) (*Instance, error)

                                                                                                                                  CompileFile compiles the given source file into an Instance. The source may import builtin packages. Use Build to allow importing non-builtin packages.

                                                                                                                                  func (*Runtime) FromExpr

                                                                                                                                  func (r *Runtime) FromExpr(expr ast.Expr) (*Instance, error)

                                                                                                                                    FromExpr creates an instance from an expression. Any references must be resolved beforehand.

                                                                                                                                    Deprecated: use CompileExpr

                                                                                                                                    func (*Runtime) Marshal

                                                                                                                                    func (r *Runtime) Marshal(instances ...*Instance) (b []byte, err error)

                                                                                                                                      Marshal creates bytes from a group of instances. Imported instances will be included in the emission.

                                                                                                                                      The stored instances are functionally the same, but preserving of file information is only done on a best-effort basis.

                                                                                                                                      func (*Runtime) Parse

                                                                                                                                      func (r *Runtime) Parse(name string, source interface{}) (*Instance, error)

                                                                                                                                        Parse parses a CUE source value into a CUE Instance. The source code may be provided as a string, byte slice, or io.Reader. The name is used as the file name in position information. The source may import builtin packages.

                                                                                                                                        Deprecated: use Compile

                                                                                                                                        func (*Runtime) Unmarshal

                                                                                                                                        func (r *Runtime) Unmarshal(b []byte) ([]*Instance, error)

                                                                                                                                          Unmarshal creates an Instance from bytes generated by the MarshalBinary method of an instance.

                                                                                                                                          type Selector

                                                                                                                                          type Selector struct {
                                                                                                                                          	// contains filtered or unexported fields
                                                                                                                                          }

                                                                                                                                            A Selector is a component of a path.

                                                                                                                                            func Def

                                                                                                                                            func Def(s string) Selector

                                                                                                                                              A Def marks a string as a definition label. An # will be added if a string is not prefixed with a #. It will panic if s cannot be written as a valid identifier.

                                                                                                                                              func Hid

                                                                                                                                              func Hid(name, pkg string) Selector

                                                                                                                                                Hid returns a selector for a hidden field. It panics is pkg is empty. Hidden fields are scoped by package, and pkg indicates for which package the hidden field must apply.For anonymous packages, it must be set to "_".

                                                                                                                                                Example
                                                                                                                                                Output:
                                                                                                                                                
                                                                                                                                                1 <nil>
                                                                                                                                                2 <nil>
                                                                                                                                                

                                                                                                                                                func Index

                                                                                                                                                func Index(x int) Selector

                                                                                                                                                  An Index selects a list element by index.

                                                                                                                                                  func Label

                                                                                                                                                  func Label(label ast.Label) Selector

                                                                                                                                                    Label converts an AST label to a Selector.

                                                                                                                                                    func Str

                                                                                                                                                    func Str(s string) Selector

                                                                                                                                                      A Str is a CUE string label. Definition selectors are defined with Def.

                                                                                                                                                      func (Selector) IsString

                                                                                                                                                      func (sel Selector) IsString() bool

                                                                                                                                                        IsString reports whether sel is a regular label type.

                                                                                                                                                        func (Selector) Optional

                                                                                                                                                        func (sel Selector) Optional() Selector

                                                                                                                                                          Optional converts sel into an optional equivalent.

                                                                                                                                                          foo -> foo?
                                                                                                                                                          

                                                                                                                                                          func (Selector) String

                                                                                                                                                          func (sel Selector) String() string

                                                                                                                                                            String reports the CUE representation of a selector.

                                                                                                                                                            type Struct

                                                                                                                                                            type Struct struct {
                                                                                                                                                            	// contains filtered or unexported fields
                                                                                                                                                            }

                                                                                                                                                              Struct represents a CUE struct value.

                                                                                                                                                              func (*Struct) At

                                                                                                                                                              func (o *Struct) At(i int) (key string, v Value)

                                                                                                                                                                At reports the key and value of the ith field, i < o.Len().

                                                                                                                                                                func (*Struct) Field

                                                                                                                                                                func (s *Struct) Field(i int) FieldInfo

                                                                                                                                                                  field reports information about the ith field, i < o.Len().

                                                                                                                                                                  func (*Struct) FieldByName

                                                                                                                                                                  func (s *Struct) FieldByName(name string, isIdent bool) (FieldInfo, error)

                                                                                                                                                                    FieldByName looks up a field for the given name. If isIdent is true, it will look up a definition or hidden field (starting with `_` or `_#`). Otherwise it interprets name as an arbitrary string for a regular field.

                                                                                                                                                                    func (*Struct) Fields

                                                                                                                                                                    func (s *Struct) Fields(opts ...Option) *Iterator

                                                                                                                                                                      Fields creates an iterator over the Struct's fields.

                                                                                                                                                                      func (*Struct) Len

                                                                                                                                                                      func (s *Struct) Len() int

                                                                                                                                                                      func (*Struct) Lookup

                                                                                                                                                                      func (o *Struct) Lookup(key string) Value

                                                                                                                                                                        Lookup reports the field for the given key. The returned Value is invalid if it does not exist.

                                                                                                                                                                        type Value

                                                                                                                                                                        type Value struct {
                                                                                                                                                                        	// contains filtered or unexported fields
                                                                                                                                                                        }

                                                                                                                                                                          Value holds any value, which may be a Boolean, Error, List, Null, Number, Struct, or String.

                                                                                                                                                                          func Dereference

                                                                                                                                                                          func Dereference(v Value) Value

                                                                                                                                                                            Dereference reports the value v refers to if v is a reference or v itself otherwise.

                                                                                                                                                                            func MakeValue

                                                                                                                                                                            func MakeValue(ctx *adt.OpContext, v adt.Value) Value

                                                                                                                                                                              MakeValue converts an adt.Value and given OpContext to a Value. The context must be directly or indirectly obtained from the NewRuntime defined in this package and it will panic if this is not the case.

                                                                                                                                                                              For internal use only.

                                                                                                                                                                              func (Value) Allows

                                                                                                                                                                              func (v Value) Allows(sel Selector) bool

                                                                                                                                                                                Allows reports whether a field with the given selector could be added to v.

                                                                                                                                                                                Allows does not take into account validators like list.MaxItems(4). This may change in the future.

                                                                                                                                                                                Example
                                                                                                                                                                                Output:
                                                                                                                                                                                
                                                                                                                                                                                a allows:
                                                                                                                                                                                  index 4:        true
                                                                                                                                                                                  any index:      true
                                                                                                                                                                                  any string:     false
                                                                                                                                                                                b allows:
                                                                                                                                                                                  field x:        true
                                                                                                                                                                                  field z:        true
                                                                                                                                                                                  field foo:      false
                                                                                                                                                                                  index 4:        false
                                                                                                                                                                                  any string:     false
                                                                                                                                                                                c allows:
                                                                                                                                                                                  field z:        true
                                                                                                                                                                                  field foo:      true
                                                                                                                                                                                  index 4:        false
                                                                                                                                                                                  any string:     true
                                                                                                                                                                                d allows:
                                                                                                                                                                                  field z:        true
                                                                                                                                                                                  field foo:      false
                                                                                                                                                                                  index 4:        false
                                                                                                                                                                                  any string:     false
                                                                                                                                                                                

                                                                                                                                                                                func (Value) AppendFloat

                                                                                                                                                                                func (v Value) AppendFloat(buf []byte, fmt byte, prec int) ([]byte, error)

                                                                                                                                                                                  AppendFloat appends to buf the string form of the floating-point number x. It returns an error if v is not a number.

                                                                                                                                                                                  func (Value) AppendInt

                                                                                                                                                                                  func (v Value) AppendInt(buf []byte, base int) ([]byte, error)

                                                                                                                                                                                    AppendInt appends the string representation of x in the given base to buf and returns the extended buffer, or an error if the underlying number was not an integer.

                                                                                                                                                                                    func (Value) Attribute

                                                                                                                                                                                    func (v Value) Attribute(key string) Attribute

                                                                                                                                                                                      Attribute returns the attribute data for the given key. The returned attribute will return an error for any of its methods if there is no attribute for the requested key.

                                                                                                                                                                                      func (Value) Attributes

                                                                                                                                                                                      func (v Value) Attributes(mask AttrKind) []Attribute

                                                                                                                                                                                        Attributes reports all field attributes for the Value.

                                                                                                                                                                                        To retrieve attributes of multiple kinds, you can bitwise-or kinds together. Use ValueKind to query attributes associated with a value.

                                                                                                                                                                                        func (Value) Bool

                                                                                                                                                                                        func (v Value) Bool() (bool, error)

                                                                                                                                                                                          Bool returns the bool value of v or false and an error if v is not a boolean.

                                                                                                                                                                                          func (Value) Bytes

                                                                                                                                                                                          func (v Value) Bytes() ([]byte, error)

                                                                                                                                                                                            Bytes returns a byte slice if v represents a list of bytes or an error otherwise.

                                                                                                                                                                                            func (Value) Decimal

                                                                                                                                                                                            func (v Value) Decimal() (d *internal.Decimal, err error)

                                                                                                                                                                                              Decimal is for internal use only. The Decimal type that is returned is subject to change.

                                                                                                                                                                                              func (Value) Decode

                                                                                                                                                                                              func (v Value) Decode(x interface{}) error

                                                                                                                                                                                                Decode initializes x with Value v. If x is a struct, it will validate the constraints specified in the field tags.

                                                                                                                                                                                                func (Value) Default

                                                                                                                                                                                                func (v Value) Default() (Value, bool)

                                                                                                                                                                                                  Default reports the default value and whether it existed. It returns the normal value if there is no default.

                                                                                                                                                                                                  func (Value) Doc

                                                                                                                                                                                                  func (v Value) Doc() []*ast.CommentGroup

                                                                                                                                                                                                    Doc returns all documentation comments associated with the field from which the current value originates.

                                                                                                                                                                                                    func (Value) Elem

                                                                                                                                                                                                    func (v Value) Elem() (Value, bool)

                                                                                                                                                                                                      Elem returns the value of undefined element types of lists and structs.

                                                                                                                                                                                                      Deprecated: use LookupPath in combination with "AnyString" or "AnyIndex".

                                                                                                                                                                                                      func (Value) Equals

                                                                                                                                                                                                      func (v Value) Equals(other Value) bool

                                                                                                                                                                                                        Equals reports whether two values are equal, ignoring optional fields. The result is undefined for incomplete values.

                                                                                                                                                                                                        func (Value) Err

                                                                                                                                                                                                        func (v Value) Err() error

                                                                                                                                                                                                          Err returns the error represented by v or nil v is not an error.

                                                                                                                                                                                                          func (Value) Eval

                                                                                                                                                                                                          func (v Value) Eval() Value

                                                                                                                                                                                                            Eval resolves the references of a value and returns the result. This method is not necessary to obtain concrete values.

                                                                                                                                                                                                            func (Value) Exists

                                                                                                                                                                                                            func (v Value) Exists() bool

                                                                                                                                                                                                              Exists reports whether this value existed in the configuration.

                                                                                                                                                                                                              func (Value) Expr

                                                                                                                                                                                                              func (v Value) Expr() (Op, []Value)

                                                                                                                                                                                                                Expr reports the operation of the underlying expression and the values it operates on.

                                                                                                                                                                                                                For unary expressions, it returns the single value of the expression.

                                                                                                                                                                                                                For binary expressions it returns first the left and right value, in that order. For associative operations however, (for instance '&' and '|'), it may return more than two values, where the operation is to be applied in sequence.

                                                                                                                                                                                                                For selector and index expressions it returns the subject and then the index. For selectors, the index is the string value of the identifier.

                                                                                                                                                                                                                For interpolations it returns a sequence of values to be concatenated, some of which will be literal strings and some unevaluated expressions.

                                                                                                                                                                                                                A builtin call expression returns the value of the builtin followed by the args of the call.

                                                                                                                                                                                                                func (Value) FieldByName

                                                                                                                                                                                                                func (v Value) FieldByName(name string, isIdent bool) (f FieldInfo, err error)

                                                                                                                                                                                                                  FieldByName looks up a field for the given name. If isIdent is true, it will look up a definition or hidden field (starting with `_` or `_#`). Otherwise it interprets name as an arbitrary string for a regular field.

                                                                                                                                                                                                                  Deprecated: use LookupPath.

                                                                                                                                                                                                                  func (Value) Fields

                                                                                                                                                                                                                  func (v Value) Fields(opts ...Option) (*Iterator, error)

                                                                                                                                                                                                                    Fields creates an iterator over v's fields if v is a struct or an error otherwise.

                                                                                                                                                                                                                    func (Value) Fill

                                                                                                                                                                                                                    func (v Value) Fill(x interface{}, path ...string) Value

                                                                                                                                                                                                                      Fill creates a new value by unifying v with the value of x at the given path.

                                                                                                                                                                                                                      Values may be any Go value that can be converted to CUE, an ast.Expr or a Value. In the latter case, it will panic if the Value is not from the same Runtime.

                                                                                                                                                                                                                      Any reference in v referring to the value at the given path will resolve to x in the newly created value. The resulting value is not validated.

                                                                                                                                                                                                                      Deprecated: use FillPath.

                                                                                                                                                                                                                      func (Value) FillPath

                                                                                                                                                                                                                      func (v Value) FillPath(p Path, x interface{}) Value

                                                                                                                                                                                                                        FillPath creates a new value by unifying v with the value of x at the given path.

                                                                                                                                                                                                                        If x is an cue/ast.Expr, it will be evaluated within the context of the given path: identifiers that are not resolved within the expression are resolved as if they were defined at the path position.

                                                                                                                                                                                                                        If x is a Value, it will be used as is. It panics if x is not created from the same Runtime as v.

                                                                                                                                                                                                                        Otherwise, the given Go value will be converted to CUE.

                                                                                                                                                                                                                        Any reference in v referring to the value at the given path will resolve to x in the newly created value. The resulting value is not validated.

                                                                                                                                                                                                                        List paths are not supported at this time.

                                                                                                                                                                                                                        func (Value) Float64

                                                                                                                                                                                                                        func (v Value) Float64() (float64, error)

                                                                                                                                                                                                                          Float64 returns the float64 value nearest to x. It reports an error if v is not a number. If x is too small to be represented by a float64 (|x| < math.SmallestNonzeroFloat64), the result is (0, ErrBelow) or (-0, ErrAbove), respectively, depending on the sign of x. If x is too large to be represented by a float64 (|x| > math.MaxFloat64), the result is (+Inf, ErrAbove) or (-Inf, ErrBelow), depending on the sign of x.

                                                                                                                                                                                                                          func (Value) Format

                                                                                                                                                                                                                          func (v Value) Format(state fmt.State, verb rune)

                                                                                                                                                                                                                            Format prints a debug version of a value.

                                                                                                                                                                                                                            func (Value) IncompleteKind

                                                                                                                                                                                                                            func (v Value) IncompleteKind() Kind

                                                                                                                                                                                                                              IncompleteKind returns a mask of all kinds that this value may be.

                                                                                                                                                                                                                              func (Value) Int

                                                                                                                                                                                                                              func (v Value) Int(z *big.Int) (*big.Int, error)

                                                                                                                                                                                                                                Int converts the underlying integral number to an big.Int. It reports an error if the underlying value is not an integer type. If a non-nil *Int argument z is provided, Int stores the result in z instead of allocating a new Int.

                                                                                                                                                                                                                                func (Value) Int64

                                                                                                                                                                                                                                func (v Value) Int64() (int64, error)

                                                                                                                                                                                                                                  Int64 converts the underlying integral number to int64. It reports an error if the underlying value is not an integer type or cannot be represented as an int64. The result is (math.MinInt64, ErrAbove) for x < math.MinInt64, and (math.MaxInt64, ErrBelow) for x > math.MaxInt64.

                                                                                                                                                                                                                                  func (Value) IsClosed

                                                                                                                                                                                                                                  func (v Value) IsClosed() bool

                                                                                                                                                                                                                                    IsClosed reports whether a list of struct is closed. It reports false when when the value is not a list or struct.

                                                                                                                                                                                                                                    Deprecated: use Allows and Kind/IncompleteKind.

                                                                                                                                                                                                                                    func (Value) IsConcrete

                                                                                                                                                                                                                                    func (v Value) IsConcrete() bool

                                                                                                                                                                                                                                      IsConcrete reports whether the current value is a concrete scalar value (not relying on default values), a terminal error, a list, or a struct. It does not verify that values of lists or structs are concrete themselves. To check whether there is a concrete default, use v.Default().IsConcrete().

                                                                                                                                                                                                                                      func (Value) Kind

                                                                                                                                                                                                                                      func (v Value) Kind() Kind

                                                                                                                                                                                                                                        Kind returns the kind of value. It returns BottomKind for atomic values that are not concrete. For instance, it will return BottomKind for the bounds >=0.

                                                                                                                                                                                                                                        func (Value) Label

                                                                                                                                                                                                                                        func (v Value) Label() (string, bool)

                                                                                                                                                                                                                                          Label reports he label used to obtain this value from the enclosing struct.

                                                                                                                                                                                                                                          TODO: get rid of this somehow. Probably by including a FieldInfo struct or the like.

                                                                                                                                                                                                                                          func (Value) Len

                                                                                                                                                                                                                                          func (v Value) Len() Value

                                                                                                                                                                                                                                            Len returns the number of items of the underlying value. For lists it reports the capacity of the list. For structs it indicates the number of fields, for bytes the number of bytes.

                                                                                                                                                                                                                                            func (Value) List

                                                                                                                                                                                                                                            func (v Value) List() (Iterator, error)

                                                                                                                                                                                                                                              List creates an iterator over the values of a list or reports an error if v is not a list.

                                                                                                                                                                                                                                              func (Value) Lookup

                                                                                                                                                                                                                                              func (v Value) Lookup(path ...string) Value

                                                                                                                                                                                                                                                Lookup reports the value at a path starting from v. The empty path returns v itself.

                                                                                                                                                                                                                                                The Exists() method can be used to verify if the returned value existed. Lookup cannot be used to look up hidden or optional fields or definitions.

                                                                                                                                                                                                                                                Deprecated: use LookupPath. At some point before v1.0.0, this method will be removed to be reused eventually for looking up a selector.

                                                                                                                                                                                                                                                func (Value) LookupDef

                                                                                                                                                                                                                                                func (v Value) LookupDef(name string) Value

                                                                                                                                                                                                                                                  LookupDef is equal to LookupPath(MakePath(Def(name))).

                                                                                                                                                                                                                                                  Deprecated: use LookupPath.

                                                                                                                                                                                                                                                  func (Value) LookupField

                                                                                                                                                                                                                                                  func (v Value) LookupField(name string) (FieldInfo, error)

                                                                                                                                                                                                                                                    LookupField reports information about a field of v.

                                                                                                                                                                                                                                                    Deprecated: use LookupPath

                                                                                                                                                                                                                                                    func (Value) LookupPath

                                                                                                                                                                                                                                                    func (v Value) LookupPath(p Path) Value

                                                                                                                                                                                                                                                      LookupPath reports the value for path p relative to v.

                                                                                                                                                                                                                                                      func (Value) MantExp

                                                                                                                                                                                                                                                      func (v Value) MantExp(mant *big.Int) (exp int, err error)

                                                                                                                                                                                                                                                        MantExp breaks x into its mantissa and exponent components and returns the exponent. If a non-nil mant argument is provided its value is set to the mantissa of x. The components satisfy x == mant × 10**exp. It returns an error if v is not a number.

                                                                                                                                                                                                                                                        The components are not normalized. For instance, 2.00 is represented mant == 200 and exp == -2. Calling MantExp with a nil argument is an efficient way to get the exponent of the receiver.

                                                                                                                                                                                                                                                        func (Value) MarshalJSON

                                                                                                                                                                                                                                                        func (v Value) MarshalJSON() (b []byte, err error)

                                                                                                                                                                                                                                                          MarshalJSON marshalls this value into valid JSON.

                                                                                                                                                                                                                                                          func (Value) Null

                                                                                                                                                                                                                                                          func (v Value) Null() error

                                                                                                                                                                                                                                                            Null reports an error if v is not null.

                                                                                                                                                                                                                                                            func (Value) Path

                                                                                                                                                                                                                                                            func (v Value) Path() Path

                                                                                                                                                                                                                                                              Path returns the path to this value from the root of an Instance.

                                                                                                                                                                                                                                                              This is currently only defined for values that have a fixed path within a configuration, and thus not those that are derived from Elem, Template, or programmatically generated values such as those returned by Unify.

                                                                                                                                                                                                                                                              func (Value) Pos

                                                                                                                                                                                                                                                              func (v Value) Pos() token.Pos

                                                                                                                                                                                                                                                                Pos returns position information.

                                                                                                                                                                                                                                                                func (Value) Reader

                                                                                                                                                                                                                                                                func (v Value) Reader() (io.Reader, error)

                                                                                                                                                                                                                                                                  Reader returns a new Reader if v is a string or bytes type and an error otherwise.

                                                                                                                                                                                                                                                                  func (Value) Reference

                                                                                                                                                                                                                                                                  func (v Value) Reference() (inst *Instance, path []string)

                                                                                                                                                                                                                                                                    Reference returns the instance and path referred to by this value such that inst.Lookup(path) resolves to the same value, or no path if this value is not a reference. If a reference contains index selection (foo[bar]), it will only return a reference if the index resolves to a concrete value.

                                                                                                                                                                                                                                                                    func (Value) Source

                                                                                                                                                                                                                                                                    func (v Value) Source() ast.Node

                                                                                                                                                                                                                                                                      Source returns the original node for this value. The return value may not be a syntax.Expr. For instance, a struct kind may be represented by a struct literal, a field comprehension, or a file. It returns nil for computed nodes. Use Split to get all source values that apply to a field.

                                                                                                                                                                                                                                                                      func (Value) Split

                                                                                                                                                                                                                                                                      func (v Value) Split() []Value

                                                                                                                                                                                                                                                                        Split returns a list of values from which v originated such that the unification of all these values equals v and for all returned values. It will also split unchecked unifications (embeddings), so unifying the split values may fail if actually unified. Source returns a non-nil value.

                                                                                                                                                                                                                                                                        Deprecated: use Expr.

                                                                                                                                                                                                                                                                        func (Value) String

                                                                                                                                                                                                                                                                        func (v Value) String() (string, error)

                                                                                                                                                                                                                                                                          String returns the string value if v is a string or an error otherwise.

                                                                                                                                                                                                                                                                          func (Value) Struct

                                                                                                                                                                                                                                                                          func (v Value) Struct() (*Struct, error)

                                                                                                                                                                                                                                                                            Struct returns the underlying struct of a value or an error if the value is not a struct.

                                                                                                                                                                                                                                                                            func (Value) Subsume

                                                                                                                                                                                                                                                                            func (v Value) Subsume(w Value, opts ...Option) error

                                                                                                                                                                                                                                                                              Subsume reports nil when w is an instance of v or an error otherwise.

                                                                                                                                                                                                                                                                              Without options, the entire value is considered for assumption, which means Subsume tests whether v is a backwards compatible (newer) API version of w.

                                                                                                                                                                                                                                                                              Use the Final option to check subsumption if a w is known to be final, and should assumed to be closed.

                                                                                                                                                                                                                                                                              Use the Raw option to do a low-level subsumption, taking defaults into account.

                                                                                                                                                                                                                                                                              Value v and w must be obtained from the same build. TODO: remove this requirement.

                                                                                                                                                                                                                                                                              func (Value) Subsumes

                                                                                                                                                                                                                                                                              func (v Value) Subsumes(w Value) bool

                                                                                                                                                                                                                                                                                Deprecated: use Subsume.

                                                                                                                                                                                                                                                                                Subsumes reports whether w is an instance of v.

                                                                                                                                                                                                                                                                                Without options, Subsumes checks whether v is a backwards compatbile schema of w.

                                                                                                                                                                                                                                                                                By default, Subsumes tests whether two values are compatible Value v and w must be obtained from the same build. TODO: remove this requirement.

                                                                                                                                                                                                                                                                                func (Value) Syntax

                                                                                                                                                                                                                                                                                func (v Value) Syntax(opts ...Option) ast.Node

                                                                                                                                                                                                                                                                                  Syntax converts the possibly partially evaluated value into syntax. This can use used to print the value with package format.

                                                                                                                                                                                                                                                                                  func (Value) Template

                                                                                                                                                                                                                                                                                  func (v Value) Template() func(label string) Value

                                                                                                                                                                                                                                                                                    Template returns a function that represents the template definition for a struct in a configuration file. It returns nil if v is not a struct kind or if there is no template associated with the struct.

                                                                                                                                                                                                                                                                                    The returned function returns the value that would be unified with field given its name.

                                                                                                                                                                                                                                                                                    Deprecated: use LookupPath in combination with using optional selectors.

                                                                                                                                                                                                                                                                                    func (Value) Uint64

                                                                                                                                                                                                                                                                                    func (v Value) Uint64() (uint64, error)

                                                                                                                                                                                                                                                                                      Uint64 converts the underlying integral number to uint64. It reports an error if the underlying value is not an integer type or cannot be represented as a uint64. The result is (0, ErrAbove) for x < 0, and (math.MaxUint64, ErrBelow) for x > math.MaxUint64.

                                                                                                                                                                                                                                                                                      func (Value) Unify

                                                                                                                                                                                                                                                                                      func (v Value) Unify(w Value) Value

                                                                                                                                                                                                                                                                                        Unify reports the greatest lower bound of v and w.

                                                                                                                                                                                                                                                                                        Value v and w must be obtained from the same build. TODO: remove this requirement.

                                                                                                                                                                                                                                                                                        func (Value) UnifyAccept

                                                                                                                                                                                                                                                                                        func (v Value) UnifyAccept(w Value, accept Value) Value

                                                                                                                                                                                                                                                                                          UnifyAccept is as v.Unify(w), but will disregard any field that is allowed in the Value accept.

                                                                                                                                                                                                                                                                                          func (Value) Validate

                                                                                                                                                                                                                                                                                          func (v Value) Validate(opts ...Option) error

                                                                                                                                                                                                                                                                                            Validate reports any errors, recursively. The returned error may represent more than one error, retrievable with errors.Errors, if more than one exists.

                                                                                                                                                                                                                                                                                            func (Value) Walk

                                                                                                                                                                                                                                                                                            func (v Value) Walk(before func(Value) bool, after func(Value))

                                                                                                                                                                                                                                                                                              Walk descends into all values of v, calling f. If f returns false, Walk will not descent further. It only visits values that are part of the data model, so this excludes optional fields, hidden fields, and definitions.

                                                                                                                                                                                                                                                                                              Directories

                                                                                                                                                                                                                                                                                              Path Synopsis
                                                                                                                                                                                                                                                                                              ast
                                                                                                                                                                                                                                                                                              Package ast declares the types used to represent syntax trees for CUE packages.
                                                                                                                                                                                                                                                                                              Package ast declares the types used to represent syntax trees for CUE packages.
                                                                                                                                                                                                                                                                                              Package build defines data types and utilities for defining CUE configuration instances.
                                                                                                                                                                                                                                                                                              Package build defines data types and utilities for defining CUE configuration instances.
                                                                                                                                                                                                                                                                                              Package encoding provides support for managing data format files supported by CUE.
                                                                                                                                                                                                                                                                                              Package encoding provides support for managing data format files supported by CUE.
                                                                                                                                                                                                                                                                                              Package errors defines shared types for handling CUE errors.
                                                                                                                                                                                                                                                                                              Package errors defines shared types for handling CUE errors.
                                                                                                                                                                                                                                                                                              Package format implements standard formatting of CUE configurations.
                                                                                                                                                                                                                                                                                              Package format implements standard formatting of CUE configurations.
                                                                                                                                                                                                                                                                                              Package literal implements conversions to and from string representations of basic data types.
                                                                                                                                                                                                                                                                                              Package literal implements conversions to and from string representations of basic data types.
                                                                                                                                                                                                                                                                                              Package load loads CUE instances.
                                                                                                                                                                                                                                                                                              Package load loads CUE instances.
                                                                                                                                                                                                                                                                                              Package parser implements a parser for CUE source files.
                                                                                                                                                                                                                                                                                              Package parser implements a parser for CUE source files.
                                                                                                                                                                                                                                                                                              Package scanner implements a scanner for CUE source text.
                                                                                                                                                                                                                                                                                              Package scanner implements a scanner for CUE source text.
                                                                                                                                                                                                                                                                                              Package token defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).
                                                                                                                                                                                                                                                                                              Package token defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).