common

package
v0.0.0-...-7a27e4f Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxInt = int(^uint(0) >> 1)

MaxInt gives the maximum value of the machine-dependent default integer type. (Standard library constants are specific to machine-independent types.)

Variables

This section is empty.

Functions

func Bump

func Bump(input string, component int) (bumped string, err error)

Bump increments a `component` of the first three-part version number '#.#.#' found in `input`, returning the `bumped` version string alone.

func CheckClean

func CheckClean(rootDirectory string) error

CheckClean verifies that the given repository `rootDirectory` contains no uncommitted changes.

func CommandIn

func CommandIn(workingDirectory, program string, arguments ...string) *exec.Cmd

CommandIn returns the `exec.Cmd` struct to execute `program` with `arguments` in `workingDirectory`.

func PullSubrepo

func PullSubrepo(rootDirectory, subDirectory string) error

PullSubrepo pulls external changes for the subrepository `subDirectory` in the repository `rootDirectory`, using the git-subrepo tool. It should not be run concurrently with other operations modifying files in the repository.

func ReplacePattern

func ReplacePattern(input []byte, format, change string) (modified []byte, changed string, err error)

ReplacePattern replaces the first instance in `input` of a pattern corresponding to a `format` string, by a `change` string. It returns a non-nil error if no match appears; otherwise, it returns the `modified` input and the `changed` portion obtained by expanding any template variables in the `change` string (see: https://golang.org/pkg/regexp/).

The `format` string is assumed to contain string substitutions denoted by `%s` and numeric substitutions denoted by `%v`. The corresponding regexp pattern is derived by quoting regexp metacharacters, matching string substitutions to shortest corresponding substrings without newlines, and matching integer substitutions to longest corresponding nonempty digit substrings.

func ReplaceValue

func ReplaceValue(object []byte, field string, changed interface{}) (modified []byte, err error)

ReplaceValue replaces the value of a top-level `field` in a JSON `object` with a `changed` value, returning the `modified` object.

This implementation works around the lack of order-preserving (un)marshaling in the standard library `json` package, by the most straightforward means available for our purposes: It uses the standard library decoder to locate the boundaries of the existing value, replacing it with an encoding of the changed value with no extraneous formatting, and leaving the remainder of the object encoding unchanged.

Note that Go developers have rejected order-preserving capabilities in the standard library with assertions that JSON is not a human-readable format (the standard library's support for indentation notwithstanding). Compare the second sentence of http://www.json.org, which states that "[JSON] is easy for humans to read and write."

func UpdateAPI

func UpdateAPI(API apiInfo, absolutePath string, permissions os.FileMode, updateChannel chan string) error

UpdateAPI reads the Discovery doc for an `API` indexed by the live Discovery service and updates the corresponding cached file in the top-level 'discoveries' directory at `absolutePath` with `permissions`, sending the intended file name to an `updateChannel` regardless of any error in the update.

To avoid unnecessary updates due to nondeterministic JSON field ordering from live Discovery docs for some APIs, UpdateAPI updates only files with meaningful changes, as determined by deep equality of maps parsed from JSON, ignoring changes to top-level `etag` and `revision` fields.

func UpdateDiscos

func UpdateDiscos() (names []string, err error)

UpdateDiscos updates local Discovery doc files for all APIs indexed by the live Discovery service, in a top-level directory 'discoveries', which must exist; and returns the absolute `names` of updated files.

func UpdateFile

func UpdateFile(directory, name string, update func([]byte) ([]byte, string, error)) (info string, err error)

UpdateFile rewrites the file `name` in `directory` by applying an `update` function to its contents, returning any auxiliary `info` returned by the `update` function.

func Version

func Version(input string) (numbers []string, err error)

Version finds the first three-part version number '#.#.#' in `input`, returning a slice of `numbers` consisting of the complete version number followed by each individual component.

Types

This section is empty.

Jump to

Keyboard shortcuts

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