hosting

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AttributeContentType             = "Content-Type"
	AttributeContentDisposition      = "Content-Disposition"
	AttributeContentLanguage         = "Content-Language"
	AttributeContentEncoding         = "Content-Encoding"
	AttributeCacheControl            = "Cache-Control"
	AttributeWebsiteRedirectLocation = "Website-Redirect-Location"
)

Valid attribute types names

ValidAttributeNames stores the attribute names that Realm static hosting supports

Functions

func AssetAttributesEqual

func AssetAttributesEqual(a, b []AssetAttribute) bool

AssetAttributesEqual determines whether the []AssetAttribute are the same

func MetadataFileToAssetDescriptions

func MetadataFileToAssetDescriptions(path string) (map[string]AssetDescription, error)

MetadataFileToAssetDescriptions attempts to open the file at the path given and build AssetDescriptions from this file

func UpdateCacheFile

func UpdateCacheFile(path string, assetCache AssetCache) error

UpdateCacheFile attempts to update the file at the path given with the AssetCache passed in

Types

type AssetAttribute

type AssetAttribute struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

AssetAttribute represents an attribute of a particular static hosting asset

type AssetCache

type AssetCache interface {
	Dirty() bool
	Entries() entryMap
	Get(appID, filePath string) (AssetCacheEntry, bool)
	Set(appID string, ace AssetCacheEntry)
}

AssetCache represents the entires that make up the cache

func CacheFileToAssetCache

func CacheFileToAssetCache(path string) (AssetCache, error)

CacheFileToAssetCache attempts to open the file at the path given and build a map of appID to a map of file path strings a AssetCache

func NewAssetCache

func NewAssetCache() AssetCache

NewAssetCache returns a new empty AssetCache

type AssetCacheEntry

type AssetCacheEntry struct {
	FilePath     string `json:"path"`
	LastModified int64  `json:"last_modified,omitempty"`
	FileSize     int64  `json:"size,omitempty"`
	FileHash     string `json:"hash,omitempty"`
}

AssetCacheEntry represents the relevant data for caching

type AssetDescription

type AssetDescription struct {
	FilePath string           `json:"path"`
	Attrs    []AssetAttribute `json:"attrs"`
}

AssetDescription is the struct that contains the metadata we store for the CLI

func AssetMetadataToAssetDescriptions

func AssetMetadataToAssetDescriptions(assetMetadata []AssetMetadata) []AssetDescription

AssetMetadataToAssetDescriptions takes AssetMetadata and outputs the slice of AssetDescriptions that should be written into the metadata file

type AssetMetadata

type AssetMetadata struct {
	AppID        string           `json:"appId,omitempty"`
	FilePath     string           `json:"path"`
	FileHash     string           `json:"hash,omitempty"`
	FileSize     int64            `json:"size,omitempty"`
	Attrs        []AssetAttribute `json:"attrs"`
	LastModified int64            `json:"last_modified,omitempty"`
	URL          string           `json:"url,omitempty"`
}

AssetMetadata represents the metadata of a static hosted asset

func FileToAssetMetadata

func FileToAssetMetadata(appID, path, assetPath string, info os.FileInfo, desc *AssetDescription, assetCache AssetCache) (*AssetMetadata, error)

FileToAssetMetadata generates a file hash for the given file and generates the assetAttributes and creates an AssetMetadata from these if the file hash has changed this will update the assetCache

func ListLocalAssetMetadata

func ListLocalAssetMetadata(appID, rootDirectory string, assetDescriptions map[string]AssetDescription, assetCache AssetCache) ([]AssetMetadata, error)

ListLocalAssetMetadata walks all files from the rootDirectory and builds []AssetMetadata from those files returns the assetMetadata and possibly alters the assetCache

func NewAssetMetadata

func NewAssetMetadata(appID, filePath, fileHash string, fileSize int64, attrs []AssetAttribute, lastModified int64) *AssetMetadata

NewAssetMetadata is a constructor for AssetMetadata

func (*AssetMetadata) IsDir

func (amd *AssetMetadata) IsDir() bool

IsDir is true if the asset represents a directory

type AssetMetadataDiffs

type AssetMetadataDiffs struct {
	AddedLocally    []AssetMetadata
	DeletedLocally  []AssetMetadata
	ModifiedLocally []ModifiedAssetMetadata
}

AssetMetadataDiffs represents a set of locally deleted, locally added, and locally modified AssetMetadata

func DiffAssetMetadata

func DiffAssetMetadata(local, remote []AssetMetadata, merge bool) *AssetMetadataDiffs

DiffAssetMetadata compares a local and remote []AssetMetadata and returns a AssetMetadataDiffs which contains information about the differences between the two. If the merge parameter is true, we ignore deleted assets

func NewAssetMetadataDiffs

func NewAssetMetadataDiffs(added, deleted []AssetMetadata, modified []ModifiedAssetMetadata) *AssetMetadataDiffs

NewAssetMetadataDiffs is a constructor for AssetMetadataDiffs

func (*AssetMetadataDiffs) Diff

func (amd *AssetMetadataDiffs) Diff() []string

Diff returns a list of strings representing the diff

type AssetsMetadata

type AssetsMetadata []AssetMetadata

AssetsMetadata is a list of AssetMetadata

func (AssetsMetadata) MapByPath

func (assetsMetadata AssetsMetadata) MapByPath() map[string]AssetMetadata

MapByPath returns the AssetMetadata as a map

type ModifiedAssetMetadata

type ModifiedAssetMetadata struct {
	AssetMetadata AssetMetadata
	BodyModified  bool
	AttrModified  bool
}

ModifiedAssetMetadata represents a description of changes to assetMetadata

func GetModifiedAssetMetadata

func GetModifiedAssetMetadata(local, remote AssetMetadata) ModifiedAssetMetadata

GetModifiedAssetMetadata returns a ModifiedAssetMetadata created from the diff between local and remote

Jump to

Keyboard shortcuts

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