server

package
v0.0.0-...-ffc5bd3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const CompressionDeflate = "deflate"

CompressionDeflate compressionType deflate

Variables

This section is empty.

Functions

func GetResourceContent

func GetResourceContent(path string) ([]byte, error)

GetResourceContent receives a file path and return the content in a []byte

func StartServer

func StartServer(config Configuration) error

StartServer starts the HTTP Server and loads the resources

Types

type Compression

type Compression = string

Compression specifies the content compression type

type Configuration

type Configuration struct {
	Hostname        string
	Port            string
	DefaultResource string
	RootPath        string
}

Configuration allow to setup the server configurations

type InMemoryResource

type InMemoryResource struct {
	Name            string
	Type            ResourceType
	CompressionType Compression
	Size            int
	InitialSize     int
	Content         []byte
}

InMemoryResource hold the resouce that can be served by the server

func NewInMemoryResource

func NewInMemoryResource(name string, content []byte) (InMemoryResource, error)

NewInMemoryResource method will initialize a new InMemoryResource object and return it

func (*InMemoryResource) String

func (resource *InMemoryResource) String() string

String method will genereate a string representation of the InMemoryResource object

type ResourceCache

type ResourceCache struct {
	// contains filtered or unexported fields
}

ResourceCache hold all the resources to be served

func NewCache

func NewCache(files []ResourceFile) ResourceCache

NewCache creates a Cache object

func (ResourceCache) Exists

func (cache ResourceCache) Exists(name string) bool

Exists return true if the resource exists on cache and false otherwise

func (ResourceCache) GetResource

func (cache ResourceCache) GetResource(name string) (InMemoryResource, error)

GetResource return the in memory resource content

func (ResourceCache) Size

func (cache ResourceCache) Size() int

Size returns the number of resources in memory

type ResourceFile

type ResourceFile struct {
	RelPath string
	AbsPath string
}

ResourceFile holds the relative and absolute path of the file

func SearchFiles

func SearchFiles(rootDir string) ([]ResourceFile, error)

SearchFiles lookup for all the files on the rootDir and sub directories

type ResourceType

type ResourceType = string

ResourceType specifies the content type of the resource

Jump to

Keyboard shortcuts

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