fieldpath

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Path

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

Path provides a JSONPath-like struct and field-member "route" to a particular field within a resource. Path implements json.Marshaler interface.

func FromString

func FromString(dotted string) *Path

FromString returns a new Path from a dotted-notation string, e.g. "Author.Name".

func (*Path) At

func (p *Path) At(index int) string

At returns the part of the Path at the supplied index, or empty string if index exceeds boundary.

func (*Path) Back

func (p *Path) Back() string

Back returns the last part of the Path or empty string if the Path has no parts.

func (*Path) Copy

func (p *Path) Copy() *Path

Copy returns a new Path that is a copy of this Path

func (*Path) CopyAt

func (p *Path) CopyAt(index int) *Path

CopyAt returns a new Path that is a copy of this Path up to the supplied index.

e.g. given Path $A containing "X.Y", $A.CopyAt(0) would return a new Path containing just "X". $A.CopyAt(1) would return a new Path containing "X.Y".

func (*Path) Empty

func (p *Path) Empty() bool

Empty returns true if there are no parts to the Path

func (*Path) Front

func (p *Path) Front() string

Front returns the first part of the Path or empty string if the Path has no parts.

func (*Path) HasPrefix

func (p *Path) HasPrefix(subject string) bool

HasPrefix returns true if the supplied string, delimited on ".", matches p.parts up to the length of the supplied string. e.g. if the Path p represents "A.B":

subject "A" -> true
subject "A.B" -> true
subject "A.B.C" -> false
subject "B" -> false
subject "A.C" -> false

func (*Path) HasPrefixFold

func (p *Path) HasPrefixFold(subject string) bool

HasPrefixFold is the same as HasPrefix but uses case-insensitive comparisons

func (*Path) IterShapeRefs

func (p *Path) IterShapeRefs(
	subject *awssdkmodel.ShapeRef,
) []*awssdkmodel.ShapeRef

IterShapeRefs returns a slice of ShapeRef pointers representing each part of the path

func (*Path) MarshalJSON

func (p *Path) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of a Path object.

func (*Path) Pop

func (p *Path) Pop() (part string)

Pop removes the last part from the Path and returns it.

func (*Path) PopFront

func (p *Path) PopFront() (part string)

PopFront removes the first part of the Path and returns it.

func (*Path) PushBack

func (p *Path) PushBack(part string)

PushBack adds a new part to the end of the Path.

func (*Path) ShapeRef

func (p *Path) ShapeRef(
	subject *awssdkmodel.ShapeRef,
) *awssdkmodel.ShapeRef

ShapeRef returns an aws-sdk-go ShapeRef within the supplied ShapeRef that matches the Path. Returns nil if no matching ShapeRef could be found.

Assume a ShapeRef that looks like this:

authShapeRef := &awssdkmodel.ShapeRef{
  ShapeName: "Author",
  Shape: &awssdkmodel.Shape{
    Type: "structure",
    MemberRefs: map[string]*awssdkmodel.ShapeRef{
      "Name": &awssdkmodel.ShapeRef{
        ShapeName: "Name",
        Shape: &awssdkmodel.Shape{
          Type: "string",
        },
      },
      "Address": &awssdkmodel.ShapeRef{
        ShapeName: "Address",
        Shape: &awssdkmodel.Shape{
          Type: "structure",
          MemberRefs: map[string]*awssdkmodel.ShapeRef{
            "State": &awssdkmodel.ShapeRef{
              ShapeName: "StateCode",
              Shape: &awssdkmodel.Shape{
                Type: "string",
              },
            },
            "Country": &awssdkmodel.ShapeRef{
              ShapeName: "CountryCode",
              Shape: &awssdkmodel.Shape{
                Type: "string",
              },
            },
          },
        },
      },
    },
  },
}

If I have the following Path:

p := fieldpath.FromString("Author.Address.Country")

calling p.ShapeRef(authShapeRef) would return the following:

&awssdkmodel.ShapeRef{
  ShapeName: "CountryCode",
  Shape: &awssdkmodel.Shape{
    Type: "string",
  },
},

func (*Path) ShapeRefAt

func (p *Path) ShapeRefAt(
	subject *awssdkmodel.ShapeRef,
	index int,
) *awssdkmodel.ShapeRef

ShapeRefAt returns an aws-sdk-go ShapeRef within the supplied ShapeRef that matches the Path at the supplied index. Returns nil if no matching ShapeRef could be found or index out of bounds.

func (*Path) Size added in v0.16.4

func (p *Path) Size() int

Size returns the Path number of parts

func (*Path) String

func (p *Path) String() string

String returns the dotted-notation representation of the Path

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL