Documentation
¶
Index ¶
- Constants
- Variables
- func AddParamToDoc(doc *pb.Document, target *SRI, param *pb.Parameter) error
- func AddParameterFields(field *pb.Field, params map[string]*pb.Field)
- func ApplyArguments(field *pb.Field, args ...*pb.Argument) error
- func CreateDocument(name, path string, ptr interface{}) (*pb.Document, error)
- func CreateLinkInDocument(doc *pb.Document, target *pb.Link, source *SRI) error
- func CreateObject(key string, ptr interface{}) (*pb.Object, error)
- func FieldValueEquals(this, other *pb.Field) bool
- func GetFieldFromDocument(doc *pb.Document, fieldpath string) (*pb.Field, error)
- func InteractiveArgs(r io.ReadCloser, w io.Writer, field *pb.Field, required bool) error
- func MapFromDocument(doc *pb.Document) (map[string]interface{}, error)
- func MapFromObject(obj *pb.Object) (map[string]interface{}, error)
- func NewLink(packageName string, target *SRI, override bool) *pb.Link
- func ObjectFromMap(key string, data map[string]interface{}) (*pb.Object, error)
- func ParameterFields(docs map[string]*pb.Document) map[string]*pb.Field
- func ParseArguments(in string, coerceStr bool) (args []*pb.Argument, err error)
- func ResolveRelativeField(field *pb.Field, fieldpath string) (resolvedField *pb.Field, err error)
- func Unmarshal(doc *pb.Document, ptr interface{}) error
- func ValidateField(fieldStr string) (string, error)
- func ValidateOID(oidStr string) (string, error)
- func ValidatePath(pathStr string) (string, error)
- type SRI
Constants ¶
const ( MaxObjectIDLen = 40 MinObjectIDLen = 7 ValidOIDChars = "abcdef0123456789" PathDelimiter = "/" FieldDelimiter = "?" )
Variables ¶
var ( OIDRegex = regexp.MustCompile(`[^a-f0-9]+`) PathRegex = regexp.MustCompile(`[^a-zA-Z0-9./-]+`) FieldRegex = regexp.MustCompile(`[^a-zA-Z0-9./()]+`) )
var (
ErrObjectNilFields = errors.New("object had nil for Fields")
)
Functions ¶
func AddParamToDoc ¶
AddParamToDoc adds the given parameter to the
func AddParameterFields ¶
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 ¶
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 ¶
CreateDocument creates a Document with an Object as it's value using CreateObject.
func CreateLinkInDocument ¶
CreateLinkInDocument creates a link from source to target with document.
func CreateObject ¶
CreateObject uses reflection to convert the data (usually a struct) into an Object.
func FieldValueEquals ¶
FieldValueEquals returns true if the value of the given fields is the same.
func GetFieldFromDocument ¶
GetFieldFromDocument returns a pointer to field in doc based on the given field path.
func InteractiveArgs ¶
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 ObjectFromMap ¶
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 ¶
ParameterFields returns the fields with parameters contained within a Document.
func ParseArguments ¶
ParseArguments returns arguments parsed from JSON. If coerceStr is true, will attempt to parse as string if parsing initially fails.
func ResolveRelativeField ¶
func ValidateField ¶
func ValidateOID ¶
func ValidatePath ¶
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]