Package template implements handling of package name templates.

    Package name templates look like e.g. "foo/${platform}" and code in this package knows how to expand them into full package names.



    This section is empty.


    View Source
    var ErrSkipTemplate = errors.New("package template does not apply to the current system")

      ErrSkipTemplate may be returned from Expander.Expand to indicate that a given expansion doesn't apply to the current template parameters. For example, expanding `"foo/${os=linux,mac}"` with a template parameter of "os" == "win", would return ErrSkipTemplate.


      This section is empty.


      type Expander

      type Expander map[string]string

        Expander is a mapping of simple string substitutions which is used to expand cipd package name templates. For example:

        ex, err := template.Expander{
          "platform": "mac-amd64"

        `ex` would be "foo/mac-amd64".

        Use DefaultExpander() to obtain the default mapping for CIPD applications.

        func DefaultExpander

        func DefaultExpander() Expander

          DefaultExpander returns the default template expander.

          This has values populated for ${os}, ${arch} and ${platform}.

          func (Expander) Expand

          func (t Expander) Expand(template string) (pkg string, err error)

            Expand applies package template expansion rules to the package template,

            If err == ErrSkipTemplate, that means that this template does not apply to this os/arch combination and should be skipped.

            The expansion rules are as follows:

            - "some text" will pass through unchanged
            - "${variable}" will directly substitute the given variable
            - "${variable=val1,val2}" will substitute the given variable, if its value
              matches one of the values in the list of values. If the current value
              does not match, this returns ErrSkipTemplate.

            Attempting to expand an unknown variable is an error. After expansion, any lingering '$' in the template is an error.

            func (Expander) Validate

            func (t Expander) Validate(template string) (pkg string, err error)

              Validate returns an error if this template doesn't appear to be valid given the current Expander parameters.

              This will catch issues like malformed template parameters and unknown variables, and will replace all ${param=value} items with the first item in the value list, even if the current TemplateExpander value doesn't match.

              This is mostly used for validating user input when the correct values of Expander aren't known yet.

              type Platform

              type Platform struct {
              	OS   string
              	Arch string

                Platform contains the parameters for a "${platform}" template.

                The string value can be obtained by calling String(). be parsed using ParsePlatform.

                func ParsePlatform

                func ParsePlatform(v string) (Platform, error)

                  ParsePlatform parses a Platform from its string representation.

                  func (Platform) Expander

                  func (tp Platform) Expander() Expander

                    Expander returns an Expander populated with tp's fields.

                    func (Platform) String

                    func (tp Platform) String() string

                    Source Files