data

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxObjectIDLen = 40
	MinObjectIDLen = 7
	ValidOIDChars  = "abcdef0123456789"

	PathDelimiter  = "/"
	FieldDelimiter = "?"
)

Variables

View Source
var (
	OIDRegex   = regexp.MustCompile(`[^a-f0-9]+`)
	PathRegex  = regexp.MustCompile(`[^a-zA-Z0-9./-]+`)
	FieldRegex = regexp.MustCompile(`[^a-zA-Z0-9./()]+`)
)
View Source
var (
	ErrObjectNilFields = errors.New("object had nil for Fields")
)

Functions

func AddParamToDoc

func AddParamToDoc(doc *pb.Document, target *SRI, param *pb.Parameter) error

AddParamToDoc adds the given parameter to the

func AddParameterFields

func AddParameterFields(field *pb.Field, params map[string]*pb.Field)

AddParameterFields adds fields with parameters from the given field (and its subfields) to the map given. The name of the parameter is the key.

func ApplyArguments

func ApplyArguments(field *pb.Field, args ...*pb.Argument) error

ApplyArguments takes the given arguments and uses them to satisfy a field parameter. If a single argument and no formatting pattern are given the single argument is used as the field value. Otherwise the arguments will be used as arguments to Printf with the formatting string as the pattern.

func CreateDocument

func CreateDocument(name, path string, ptr interface{}) (*pb.Document, error)

CreateDocument creates a Document with an Object as it's value using CreateObject.

func CreateLinkInDocument

func CreateLinkInDocument(doc *pb.Document, target *pb.Link, source *SRI) error

CreateLinkInDocument creates a link from source to target with document.

func CreateObject

func CreateObject(key string, ptr interface{}) (*pb.Object, error)

CreateObject uses reflection to convert the data (usually a struct) into an Object.

func FieldValueEquals

func FieldValueEquals(this, other *pb.Field) bool

FieldValueEquals returns true if the value of the given fields is the same.

func GetFieldFromDocument

func GetFieldFromDocument(doc *pb.Document, fieldpath string) (*pb.Field, error)

GetFieldFromDocument returns a pointer to field in doc based on the given field path.

func InteractiveArgs

func InteractiveArgs(r io.ReadCloser, w io.Writer, field *pb.Field, required bool) error

InteractiveArgs hosts an interactive session using a Reader and Writer which prompts for input which is used to populate the provided field. If required is true then only fields without defaults will be prompted for.

func MapFromDocument

func MapFromDocument(doc *pb.Document) (map[string]interface{}, error)

func MapFromObject

func MapFromObject(obj *pb.Object) (map[string]interface{}, error)
func NewLink(packageName string, target *SRI, override bool) *pb.Link

NewLink creates a new link from with the given details.

func ObjectFromMap

func ObjectFromMap(key string, data map[string]interface{}) (*pb.Object, error)

ObjectFromMap creates an Object, using the entries of a map as fields. This supports maps embedded as values. It is assumed that types are limited to JSON types.

func ParameterFields

func ParameterFields(docs map[string]*pb.Document) map[string]*pb.Field

ParameterFields returns the fields with parameters contained within a Document.

func ParseArguments

func ParseArguments(in string, coerceStr bool) (args []*pb.Argument, err error)

ParseArguments returns arguments parsed from JSON. If coerceStr is true, will attempt to parse as string if parsing initially fails.

func ResolveRelativeField

func ResolveRelativeField(field *pb.Field, fieldpath string) (resolvedField *pb.Field, err error)

func Unmarshal

func Unmarshal(doc *pb.Document, ptr interface{}) error

func ValidateField

func ValidateField(fieldStr string) (string, error)

func ValidateOID

func ValidateOID(oidStr string) (string, error)

func ValidatePath

func ValidatePath(pathStr string) (string, error)

Types

type SRI

type SRI struct {
	// Treeish is a Git Object ID to either a Commit or a Tree Git object.
	// The use of a Git OID (treeish) allows for any document or field to be addressed regardless if it is accessible.
	// The Object ID may be truncated down to a minimum of 7 characters.
	// A single character “*” indicates a relative reference, this intentionally can’t be formed into a URL.
	Treeish string

	// Path to the Spread Document being addressed. If omitted, SRI refers to treeish.
	// This will be traversed starting from the given Treeish.
	Path string

	// Field specifies a path to the field within the Document that is being referred to. If omitted, the SRI refers to the entire document.
	// Path must be given to have a Field.
	// Fieldpaths are specified by name using the character “.” to specify sub-fields.
	// Fieldpath of arrays are addressed using their 0 indexed position wrapped with parentheses.
	// The use of parentheses is due to restrictions in the syntax of URLs.
	Field string
}

A SRI represents a parsed Spread Resource Identifier (SRI), a globally unique address for an document or field stored within a repository. This is represented as:

treeish/path[?field]

func ParseSRI

func ParseSRI(rawsri string) (*SRI, error)

ParseSRI parses rawsri into SRI struct.

func (*SRI) IsDocument

func (s *SRI) IsDocument() bool

IsDocument is true if points to document.

func (*SRI) IsField

func (s *SRI) IsField() bool

IsField is true if points to field.

func (*SRI) IsTree

func (s *SRI) IsTree() bool

IsTreeish is true if identifier points to tree.

func (*SRI) Proto

func (s *SRI) Proto() *pb.SRI

Proto returns the protobuf representation of an SRI

func (*SRI) String

func (s *SRI) String() string

String returns a textual representation of the SRI which will be similar to the input.

Jump to

Keyboard shortcuts

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