Movatterモバイル変換


[0]ホーム

URL:


containers

package
v0.26.1Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2025 License:Apache-2.0, BSD-3-ClauseImports:4Imported by:4

Details

Repository

github.com/google/cel-go

Links

Documentation

Overview

Package containers defines types and functions for resolving qualified names within a namespaceor type provided to CEL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcToQualifiedName

func ToQualifiedName(east.Expr) (string,bool)

ToQualifiedName converts an expression AST into a qualified name if possible, with a boolean'found' value that indicates if the conversion is successful.

Types

typeContainer

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

Container holds a reference to an optional qualified container name and set of aliases.

The program container can be used to simplify variable, function, and type specification withinCEL programs and behaves more or less like a C++ namespace. See ResolveCandidateNames for moredetails.

var (// DefaultContainer has an empty container name.DefaultContainer *Container =nil)

funcNewContainer

func NewContainer(opts ...ContainerOption) (*Container,error)

NewContainer creates a new Container with the fully-qualified name.

func (*Container)AliasSetadded inv0.24.0

func (c *Container) AliasSet() map[string]string

AliasSet returns the alias to fully-qualified name mapping stored in the container.

func (*Container)Extend

func (c *Container) Extend(opts ...ContainerOption) (*Container,error)

Extend creates a new Container with the existing settings and applies a series ofContainerOptions to further configure the new container.

func (*Container)Name

func (c *Container) Name()string

Name returns the fully-qualified name of the container.

The name may conceptually be a namespace, package, or type.

func (*Container)ResolveCandidateNames

func (c *Container) ResolveCandidateNames(namestring) []string

ResolveCandidateNames returns the candidates name of namespaced identifiers in C++ resolutionorder.

Names which shadow other names are returned first. If a name includes a leading dot ('.'),the name is treated as an absolute identifier which cannot be shadowed.

Given a container name a.b.c.M.N and a type name R.s, this will deliver in order:

a.b.c.M.N.R.sa.b.c.M.R.sa.b.c.R.sa.b.R.sa.R.sR.s

If aliases or abbreviations are configured for the container, then alias names will takeprecedence over containerized names.

typeContainerOption

type ContainerOption func(*Container) (*Container,error)

ContainerOption specifies a functional configuration option for a Container.

Note, ContainerOption implementations must be able to handle nil container inputs.

funcAbbrevs

func Abbrevs(qualifiedNames ...string)ContainerOption

Abbrevs configures a set of simple names as abbreviations for fully-qualified names.

An abbreviation (abbrev for short) is a simple name that expands to a fully-qualified name.Abbreviations can be useful when working with variables, functions, and especially types frommultiple namespaces:

// CEL object constructionqual.pkg.version.ObjTypeName{   field: alt.container.ver.FieldTypeName{value: ...}}

Only one the qualified names above may be used as the CEL container, so at least one of thesereferences must be a long qualified name within an otherwise short CEL program. Using thefollowing abbreviations, the program becomes much simpler:

// CEL Go optionAbbrevs("qual.pkg.version.ObjTypeName", "alt.container.ver.FieldTypeName")// Simplified Object constructionObjTypeName{field: FieldTypeName{value: ...}}

There are a few rules for the qualified names and the simple abbreviations generated from them:- Qualified names must be dot-delimited, e.g. `package.subpkg.name`.- The last element in the qualified name is the abbreviation.- Abbreviations must not collide with each other.- The abbreviation must not collide with unqualified names in use.

Abbreviations are distinct from container-based references in the following important ways:

  • Abbreviations must expand to a fully-qualified name.
  • Expanded abbreviations do not participate in namespace resolution.
  • Abbreviation expansion is done instead of the container search for a matching identifier.
  • Containers follow C++ namespace resolution rules with searches from the most qualified nameto the least qualified name.
  • Container references within the CEL program may be relative, and are resolved to fullyqualified names at either type-check time or program plan time, whichever comes first.

If there is ever a case where an identifier could be in both the container and as anabbreviation, the abbreviation wins as this will ensure that the meaning of a program ispreserved between compilations even as the container evolves.

funcAlias

func Alias(qualifiedName, aliasstring)ContainerOption

Alias associates a fully-qualified name with a user-defined alias.

In general, Abbrevs is preferred to Alias since the names generated from the Abbrevs optionare more easily traced back to source code. The Alias option is useful for propagating aliasconfiguration from one Container instance to another, and may also be useful for remappingpoorly chosen protobuf message / package names.

Note: all of the rules that apply to Abbrevs also apply to Alias.

funcName

func Name(namestring)ContainerOption

Name sets the fully-qualified name of the Container.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp