utils

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediaTypeTextPlain         = MediaType("text/plain; charset=utf-8")
	MediaTypeOctetStream       = MediaType("application/octet-stream")
	MediaTypeHTML              = MediaType("text/html")
	MediaTypeJSON              = MediaType("application/json")
	MediaTypeMultipartFormData = MediaType("multipart/form-data")
	MediaTypeFormURLEncoded    = MediaType("application/x-www-form-urlencoded")
	MediaTypeZip               = MediaType("application/zip")
)

The set of known MediaTypes

View Source
const (
	// FunctionsRoot is the root directory for functions and dependencies
	FunctionsRoot = "functions"
)

Variables

View Source
var (
	// HostingRoot is the root directory for hosting assets and attributes
	HostingRoot = "hosting"
	// HostingFilesDirectory is the directory to place the static hosting assets
	HostingFilesDirectory = fmt.Sprintf("%s/files", HostingRoot)
	// HostingAttributes is the file that stores the static hosting asset descriptions struct
	HostingAttributes = fmt.Sprintf("%s/metadata.json", HostingRoot)
	// HostingCacheFileName is the file that stores the cached hosting asset data
	HostingCacheFileName = ".asset-cache.json"
)
View Source
var (
	// CLIVersion represents the current version of the CLI. This version is dynamically replaced at build-time
	CLIVersion = "1.0.0"

	// CLIOSArch represents the OS Architecture of the CLI. It is used to select the appropriate URL for the CLI
	// binary based on the user's OS
	CLIOSArch string
)

Functions

func CheckForNewCLIVersion

func CheckForNewCLIVersion(client HTTPClient) string

CheckForNewCLIVersion looks for and returns a url for a new version of the CLI, if one exists. Any errors are swallowed.

func GenerateFileHashStr added in v1.2.0

func GenerateFileHashStr(fName string) (string, error)

GenerateFileHashStr takes a file name and opens and generates a string of the hash.Hash for that file

func GetContentTypeByExtension added in v1.2.0

func GetContentTypeByExtension(ext string) (string, bool)

GetContentTypeByExtension takes an extension (String) and outputs the default content type used to represent it

func GetDirectoryContainingFile

func GetDirectoryContainingFile(wd, filename string) (string, error)

GetDirectoryContainingFile searches upwards for a valid Stitch app directory

func IsDefaultContentType added in v1.2.0

func IsDefaultContentType(cType string) bool

IsDefaultContentType that takes a content / MIME type and outputs if it is one of the default content-types in fileName

func RandomAlphaNumericSpecialString

func RandomAlphaNumericSpecialString(length int) string

RandomAlphaNumericSpecialString generates a new random alphanumeric key with special characters

func RandomAlphaNumericSpecialStringStrict

func RandomAlphaNumericSpecialStringStrict(length int) string

RandomAlphaNumericSpecialStringStrict generates a new random alphanumeric key with special characters

func RandomAlphaNumericString

func RandomAlphaNumericString(length int) string

RandomAlphaNumericString generates a new random alphanumeric key

func RandomAlphaString

func RandomAlphaString(length int) string

RandomAlphaString generates a new random alphabetic string of given length

func ResolveAppDirectory added in v1.5.0

func ResolveAppDirectory(appPath, workingDirectory string) (string, error)

ResolveAppDirectory returns the directory path for an app

func ResolveAppInstanceData added in v1.5.0

func ResolveAppInstanceData(appID, path string) (models.AppInstanceData, error)

ResolveAppInstanceData loads data for an app from a stitch.json file located in the provided directory path, merging in any overridden parameters from command line flags

func TraverseArchiveReader added in v1.11.0

func TraverseArchiveReader(archiveReader ArchiveReader, fileHandler func(header *FileHeader) error) error

TraverseArchiveReader traverses the archive reader while invoking the provided handler for each new file

func UnmarshalFromDir

func UnmarshalFromDir(path string) (map[string]interface{}, error)

UnmarshalFromDir unmarshals a Stitch app from the given directory into a map[string]interface{}

func WriteFileToDir added in v1.2.0

func WriteFileToDir(dest string, data io.Reader) error

WriteFileToDir writes the data to dest and creates the necessary directories along the path

func WriteZipToDir

func WriteZipToDir(dest string, zipData io.Reader, overwrite bool) error

WriteZipToDir takes a destination and an io.Reader containing zip data and unpacks it

Types

type ArchiveInputReader added in v1.11.0

type ArchiveInputReader interface {
	io.Reader
	io.ReaderAt
}

ArchiveInputReader is an interface that wraps Reader and ReaderAt.

type ArchiveReader added in v1.11.0

type ArchiveReader interface {
	Next() (*FileHeader, error)
	Read(b []byte) (int, error)
}

ArchiveReader provides sequential access to the contents of the supported archive formats. Reader.Next advances to the next file in the archive (including the first), and then ArchiveReader can be treated as an io.Reader to access the file's data.

func NewArchiveReader added in v1.11.0

func NewArchiveReader(r ArchiveInputReader, fullPath string, size int64) (ArchiveReader, error)

NewArchiveReader creates a new ArchiveReader reading from r.

func NewDirReader added in v1.11.0

func NewDirReader(dirName string) (ArchiveReader, error)

NewDirReader creates a new dir reader by traversing through all the files in the directory

func NewGZReader added in v1.11.0

func NewGZReader(r io.Reader) (ArchiveReader, error)

NewGZReader creates a new gzip archive reader reading from r

func NewTarReader added in v1.11.0

func NewTarReader(r io.Reader) ArchiveReader

NewTarReader creates a new tar archive reader reading from r

func NewZipReader added in v1.11.0

func NewZipReader(r io.ReaderAt, size int64) (ArchiveReader, error)

NewZipReader creates a new zip archive reader reading from r

type FileHeader added in v1.11.0

type FileHeader struct {
	FullPath string
	// contains filtered or unexported fields
}

FileHeader holds file header information

func (*FileHeader) FileInfo added in v1.11.0

func (header *FileHeader) FileInfo() os.FileInfo

FileInfo returns an os.FileInfo for the FileHeader.

type HTTPClient

type HTTPClient interface {
	Get(url string) (*http.Response, error)
}

HTTPClient represents the minimum HTTP client required to check for version information

type MediaType

type MediaType string

MediaType defines the type of HTTP media in a request/response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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