Beispiel #1
0
// "Constructor", parses the given string JSON reference
func (r *JsonReference) parse(jsonReferenceString string) (err error) {

	r.referenceUrl, err = url.Parse(jsonReferenceString)
	if err != nil {
		return
	}
	refUrl := r.referenceUrl

	if refUrl.Scheme != "" && refUrl.Host != "" {
		r.HasFullUrl = true
	} else {
		if refUrl.Path != "" {
			r.HasUrlPathOnly = true
		} else if refUrl.RawQuery == "" && refUrl.Fragment != "" {
			r.HasFragmentOnly = true
		}
	}

	r.HasFileScheme = refUrl.Scheme == "file"
	r.HasFullFilePath = strings.HasPrefix(refUrl.Path, "/")

	// invalid json-pointer error means url has no json-pointer fragment. simply ignore error
	r.referencePointer, _ = gojsonpointer.NewJsonPointer(refUrl.Fragment)

	return
}
Beispiel #2
0
func lastObj(path string) (ptr.JsonPointer, string, error) {
	lastSep := strings.LastIndex(path, "/")
	parentPath := path[0:lastSep]
	lastToken := path[lastSep+1:] // Skip "/"
	parentPtr, err := ptr.NewJsonPointer(parentPath)
	return parentPtr, lastToken, err
}
Beispiel #3
0
func BenchmarkGojsonpointer(b *testing.B) {
	p, _ := gojsonpointer.NewJsonPointer(`/a/0/c`)
	for i := 0; i < b.N; i++ {
		res, kind, err := p.Get(m)
		_ = res
		_ = kind
		_ = err
	}
}
Beispiel #4
0
func getValue(path string, doc interface{}) (*ptr.JsonPointer, reflect.Kind, interface{}, error) {
	ptr, err := ptr.NewJsonPointer(path)
	if err != nil {
		return nil, reflect.Invalid, nil, err
	}
	val, kind, err := ptr.Get(doc)
	if err != nil {
		return nil, reflect.Invalid, nil, err
	}
	return &ptr, kind, val, nil
}
Beispiel #5
0
//GetByJSONPointer returns subdata of json using json pointer
func GetByJSONPointer(inData interface{}, key string) (interface{}, error) {
	pointer, err := gojsonpointer.NewJsonPointer(key)
	if err != nil {
		return nil, err
	}
	data, _, err := pointer.Get(inData)
	if err != nil {
		return nil, err
	}
	return data, nil

}
func (e *enumLoader) ensureSubconfDirLoaded(path, pattern, ptrString string) (err error) {
	ptr, err := gojsonpointer.NewJsonPointer(ptrString)
	if err != nil {
		return
	}

	key := subconfKey(ptrString, path, pattern)
	if e.watchers[key] != nil {
		return
	}
	client := &subconfWatcherClient{e: e, key: key, ptr: ptr}
	watcher := wbgo.NewDirWatcher(pattern, client)
	e.watchers[key] = watcher
	watcher.Load(path)
	return
}
Beispiel #7
0
// "Constructor", parses the given string JSON reference
func (r *JsonReference) parse(jsonReferenceString string) (err error) {

	r.referenceUrl, err = url.Parse(jsonReferenceString)
	if err != nil {
		return
	}
	refUrl := r.referenceUrl

	if refUrl.Scheme != "" && refUrl.Host != "" {
		r.HasFullUrl = true
	} else {
		if refUrl.Path != "" {
			r.HasUrlPathOnly = true
		} else if refUrl.RawQuery == "" && refUrl.Fragment != "" {
			r.HasFragmentOnly = true
		}
	}

	r.HasFileScheme = refUrl.Scheme == "file"
	if runtime.GOOS == "windows" {
		// on Windows, a file URL may have an extra leading slash, and if it
		// doesn't then its first component will be treated as the host by the
		// Go runtime
		if refUrl.Host == "" && strings.HasPrefix(refUrl.Path, "/") {
			r.HasFullFilePath = filepath.IsAbs(refUrl.Path[1:])
		} else {
			r.HasFullFilePath = filepath.IsAbs(refUrl.Host + refUrl.Path)
		}
	} else {
		r.HasFullFilePath = filepath.IsAbs(refUrl.Path)
	}

	// invalid json-pointer error means url has no json-pointer fragment. simply ignore error
	r.referencePointer, _ = gojsonpointer.NewJsonPointer(refUrl.Fragment)

	return
}