model

package
v15.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package model holds the business logic for the operations made available by profileBuilder.

This package is not governed by the SemVer associated with the rest of the Azure-SDK-for-Go.

Index

Constants

This section is empty.

Variables

View Source
var VersionLE = func() func(string, string) (bool, error) {
	wellKnownStrategies := map[*regexp.Regexp]func([]string, []string) (bool, error){

		regexp.MustCompile(`^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})(?:[\.\-](?P<tag>.+))?$`): func(leftMatch, rightMatch []string) (bool, error) {
			var err error
			for i := 1; i <= 3; i++ {
				if leftMatch[i] == rightMatch[i] {
					continue
				}

				var leftNum, rightNum int
				leftNum, err = strconv.Atoi(leftMatch[i])
				if err != nil {
					return false, err
				}

				rightNum, err = strconv.Atoi(rightMatch[i])
				if err != nil {
					return false, err
				}

				if leftNum < rightNum {
					return true, nil
				}
				return false, nil
			}

			if leftTag, rightTag := leftMatch[4], rightMatch[4]; leftTag == "" && rightTag != "" {
				return false, nil
			} else if leftTag != "" && rightTag != "" {
				return leftTag <= rightTag, nil
			}
			return true, nil
		},

		regexp.MustCompile(`(?P<major>\d+)\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?-?(?P<tag>.*)`): func(leftMatch, rightMatch []string) (bool, error) {
			for i := 1; i <= 3; i++ {
				if len(leftMatch[i]) == 0 || len(rightMatch[i]) == 0 {
					return leftMatch[i] <= rightMatch[i], nil
				}
				numLeft, err := strconv.Atoi(leftMatch[i])
				if err != nil {
					return false, err
				}
				numRight, err := strconv.Atoi(rightMatch[i])
				if err != nil {
					return false, err
				}

				if numLeft < numRight {
					return true, nil
				}

				if numLeft > numRight {
					return false, nil
				}
			}

			return leftMatch[4] <= rightMatch[4], nil
		},
	}

	return func(left, right string) (bool, error) {
		if left == right {
			return true, nil
		}

		for versionStrategy, handler := range wellKnownStrategies {
			if leftMatch, rightMatch := versionStrategy.FindAllStringSubmatch(left, 1), versionStrategy.FindAllStringSubmatch(right, 1); len(leftMatch) > 0 && len(rightMatch) > 0 {
				return handler(leftMatch[0], rightMatch[0])
			}
		}
		return false, fmt.Errorf("Unable to find versioning strategy that could compare %q and %q", left, right)
	}
}()

VersionLE takes two version strings that share a format and returns true if the one on the left is less than or equal to the one on the right. If the two do not match in format, or are not in a well known format, this will return false and an error.

Functions

func AcceptAll

func AcceptAll(name string) bool

AcceptAll is a predefined value for `LatestStrategy.Predicate` which always returns true.

func AzureSDKforGoLocation

func AzureSDKforGoLocation() string

AzureSDKforGoLocation returns the default location for the Azure-SDK-for-Go to reside.

func BuildProfile

func BuildProfile(packageList collection.Enumerable, name, outputLocation string, outputLog, errLog *log.Logger)

BuildProfile takes a list of packages and creates a profile

func DefaultInputRoot

func DefaultInputRoot() string

DefaultInputRoot establishes the location where we expect to find the packages to create aliases for.

func DefaultOutputLocation

func DefaultOutputLocation() string

DefaultOutputLocation establishes the location where profiles should be output to unless otherwise specified.

func DeleteChildDirs

func DeleteChildDirs(dir string) (err error)

DeleteChildDirs deletes all child directories of the directory specified by `path`. If it fails to delete a child, it halts execution and returns an err immediately.

func GenerateAliasPackages

func GenerateAliasPackages(packages collection.Enumerator, profileName string, outputLog, errLog *log.Logger) collection.Enumerator

GenerateAliasPackages creates an enumerator, which when called, will create Alias packages ready to be written to disk.

func GetAliasMaker

func GetAliasMaker(profileName string, outputLog, errLog *log.Logger) collection.Transform

GetAliasMaker creates a lambda which fetches Alias packages when given a pointer to an existing

func GetAliasPath

func GetAliasPath(subject, profile string) (transformed string, err error)

GetAliasPath takes an existing API Version path and a package name, and converts the path to a path which uses the new profile layout.

func GetAliasWriter

func GetAliasWriter(outputLocation string, outputLog, errLog *log.Logger) collection.Transform

GetAliasWriter gets a `collection.Transform` which writes a package to disk at the specified location.

func GetUserAgentUpdater

func GetUserAgentUpdater(profileName string) collection.Transform

GetUserAgentUpdater creates a lambda which will transform alias packages into professing the Profile that the package is a part of.

func IgnorePreview

func IgnorePreview(name string) (result bool)

IgnorePreview searches a packages "API Version" to see if it contains the word "preview". It only returns true when a package is not a preview.

func TrimGoPath

func TrimGoPath(subject string) string

TrimGoPath removes the prefix defined in the environment variabe GOPATH if it is present in the string provided.

Types

type Alias

type Alias struct {
	*goalias.AliasPackage
	TargetPath string
}

type ErrNotVersionString

type ErrNotVersionString string

ErrNotVersionString is instantiated when a string not conforming to known Azure API Version patterns is parsed is if it did.

func (ErrNotVersionString) Error

func (err ErrNotVersionString) Error() string

type LatestStrategy

type LatestStrategy struct {
	Root          string
	Predicate     func(packageName string) bool
	VerboseOutput *log.Logger
}

LatestStrategy evaluates the Azure-SDK-for-Go repository for the latest available API versions of each service.

func (LatestStrategy) Enumerate

func (latest LatestStrategy) Enumerate(cancel <-chan struct{}) collection.Enumerator

Enumerate scans through the known Azure SDK for Go packages and finds each

type ListStrategy

type ListStrategy struct {
	io.Reader
}

ListStrategy allows a mechanism for a list of packages that should be included in a profile.

func (ListStrategy) Enumerate

func (list ListStrategy) Enumerate(cancel <-chan struct{}) collection.Enumerator

Enumerate reads a new line delimited list of packages names relative to $GOPATH

Jump to

Keyboard shortcuts

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