Пример #1
0
func HandleAPIVersion(h string) (string, error) {
	if len(h) <= 0 || h == "*/*" {
		return API_MAX_VERSION, nil
	}

	foundRequestVersion := false

	for _, val := range strings.Split(h, ",") {
		versionIndex := strings.Index(val, VersionTag)
		if versionIndex < 0 {
			continue
		}

		foundRequestVersion = true

		requestVersion := val[versionIndex+len(VersionTag):]
		if cbgt.VersionGTE(API_MAX_VERSION, requestVersion) &&
			cbgt.VersionGTE(requestVersion, API_MIN_VERSION) {
			return requestVersion, nil
		}
	}

	if !foundRequestVersion {
		return API_MAX_VERSION, nil
	}

	return "", fmt.Errorf("version: unsupported version")
}
Пример #2
0
func HandleVersion(h string) (string, error) {
	if h == "*/*" {
		return API_MAX_VERSION, nil
	}
	found := false
	for _, val := range strings.Split(h, ",") {
		versionIndex := strings.Index(val, VersionTag)
		if versionIndex == -1 {
			continue
		}
		found = true
		requestVersion := val[versionIndex+len(VersionTag):]
		if cbgt.VersionGTE(API_MAX_VERSION, requestVersion) &&
			cbgt.VersionGTE(requestVersion, API_MIN_VERSION) {
			return requestVersion, nil
		}
	}
	// no version string found
	if !found {
		return API_MAX_VERSION, nil
	}
	// unsupported version
	return "", fmt.Errorf("Version number is not supported")
}