server

package
v0.0.0-...-b5d11a7 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2017 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Methods dealing with files writing/reading from either the FS or a distant service (s3, ...) Copyright © 2015 - Rémy MATHIEU

Route giving the last uploaded files. Copyright © 2015 - Rémy MATHIEU

Saving information on the hosted files. Copyright © 2015 - Rémy MATHIEU

Route to search by tags Copyright © 2015 - Rémy MATHIEU

Route receiving the data when a file is uploaded. Copyright © 2015 - Rémy MATHIEU

Index

Constants

View Source
const (
	FS_STORAGE = "fs"
	S3_STORAGE = "s3"
)
View Source
const (
	MAX_MEMORY = 1024 * 1024
	DICTIONARY = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
View Source
const (
	HEADER_ORIGINAL_FILENAME = "X-Upd-Orig-Filename"
)
View Source
const (
	LAST_UPLOADED_KEY = "LastUploaded"
)
View Source
const (
	MAX_LAST_UPLOADED = 20
)
View Source
const (
	SECRET_KEY_HEADER = "X-upd-key"
)

Variables

This section is empty.

Functions

func IsAuthValid

func IsAuthValid(s *Server, r *http.Request) bool

IsAuthValid returns whether the HTTP request contains the expected secret key, if the configuration requires one

Types

type AuthCheckHandler

type AuthCheckHandler struct {
	Server *Server // pointer to the started server
}

AuthCheckHandler simply tests whether the presented auth credentials are valid or not without doing any useless work

func (*AuthCheckHandler) ServeHTTP

func (a *AuthCheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type CleanJob

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

func (CleanJob) Run

func (j CleanJob) Run()

Run deals with cleaning the expired files by checking their TTL.

type Config

type Config struct {
	Addr            string `toml:"listen_addr"`     // Address to listen to
	SecretKey       string `toml:"secret_key"`      // Secret between the client and the server
	RuntimeDir      string `toml:"runtime_dir"`     // Where the server can write the runtime files.
	Route           string `toml:"route"`           // Route served by the webserver
	CertificateFile string `toml:"certificate"`     // Filepath to an tls certificate
	CertificateKey  string `toml:"certificate_key"` // Filepath to the key part of a certificate

	Storage string `toml:"storage"` // possible values 'fs', 's3'

	FSConfig FSConfig `toml:"fsstorage"`
	S3Config S3Config `toml:"s3storage"`
}

Server configuration

type CorsHandler

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

CorsHandler adds the required CORS headers, and forwards the request to the real handler (with the notable exception of OPTIONS requests, that it will eat)

func (*CorsHandler) ServeHTTP

func (c *CorsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type DeleteHandler

type DeleteHandler struct {
	Server *Server // pointer to the started server
}

func (*DeleteHandler) ServeHTTP

func (s *DeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type FSConfig

type FSConfig struct {
	OutputDirectory string `toml:"output_dir"`
}

type Flags

type Flags struct {
	ConfigFile string // the file configuration to use for the server
}

Server flags

type LastUploadedHandler

type LastUploadedHandler struct {
	Server *Server // pointer to the started server
}

func (*LastUploadedHandler) ServeHTTP

func (l *LastUploadedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LastUploadedResponse

type LastUploadedResponse struct {
	Name         string    `json:"name"`
	Original     string    `json:"original"`
	DeleteKey    string    `json:"delete_key"`
	CreationTime time.Time `json:"creation_time"`
}

Json returned to the client

type Metadata

type Metadata struct {
	Original       string    `json:"original"`        // original name of the file.
	Filename       string    `json:"filename"`        // name of the file on the FS
	Tags           []string  `json:"tags"`            // tags attached to the uploaded file
	TTL            string    `json:"ttl"`             // time.Duration representing the lifetime of the file.
	ExpirationTime time.Time `json:"expiration_time"` // at which time this file should expire.
	DeleteKey      string    `json:"delete_key"`      // The key to delete this file.
	CreationTime   time.Time `json:"creation_time"`
}

type S3Config

type S3Config struct {
	AccessKey    string `toml:"access_key"`
	AccessSecret string `toml:"access_secret"`
	Region       string `toml:"region"`
	Bucket       string `toml:"bucket"`
}

type SearchTagsEntryResponse

type SearchTagsEntryResponse struct {
	Filename       string    `json:"filename"`        // name attributed by upd
	Original       string    `json:"original"`        // original name of the file
	DeleteKey      string    `json:"delete_key"`      // the delete key
	CreationTime   time.Time `json:"creation_time"`   // creation time of the given file
	ExpirationTime time.Time `json:"expiration_time"` // When this file expired
	Tags           []string  `json:"tags"`            // Tags attached to this file.
}

actually contains everything in Metadata but eh, looks more clean to do so if oneee daaay...

type SearchTagsHandler

type SearchTagsHandler struct {
	Server *Server // pointer to the started server
}

func (*SearchTagsHandler) ServeHTTP

func (l *SearchTagsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SearchTagsResponse

type SearchTagsResponse struct {
	Results []SearchTagsEntryResponse `json:"results"`
}

Json returned to the client

type SendHandler

type SendHandler struct {
	Server *Server // pointer to the started server
}

func (*SendHandler) ServeHTTP

func (s *SendHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SendResponse

type SendResponse struct {
	Name           string    `json:"name"`
	DeleteKey      string    `json:"delete_key"`
	ExpirationTime time.Time `json:"expiration_time"`
}

Json returned to the client

type Server

type Server struct {
	Config   Config   // Configuration
	Database *bolt.DB // opened bolt db
	Storage  string   // Storage used with this metadata file.
}

func NewServer

func NewServer(config Config) *Server

func (*Server) Expire

func (s *Server) Expire(m Metadata) error

Expire expires a file : delete it from the metadata and from the FS.

func (*Server) GetEntry

func (s *Server) GetEntry(id string) (*Metadata, error)

getEntry looks in the Bolt DB whether this entry exists and returns it if found, otherwise, nil is returned.

func (*Server) GetLastUploaded

func (s *Server) GetLastUploaded() ([]string, error)

GetLastUploaded reads into BoltDB the array of last uploaded entries.

func (*Server) ReadFile

func (s *Server) ReadFile(filename string) ([]byte, error)

readFile is the method to read the file from wherever it is stored. The serverFlags are used to know where to read, the filename is used to know what to read.

func (*Server) SetLastUploaded

func (s *Server) SetLastUploaded(lastUploaded []string) error

func (*Server) Start

func (s *Server) Start()

Starts the listening daemon.

func (*Server) StartCleanJob

func (s *Server) StartCleanJob()

Starts the Clean Job

func (*Server) WriteFile

func (s *Server) WriteFile(filename string, data []byte) error

writeFile deals with writing the file, using the flags to know where and the filename / data to store it.

type ServingHandler

type ServingHandler struct {
	Server *Server // pointer to the started server
}

func (*ServingHandler) Resize

func (s *ServingHandler) Resize(id string, contentType string, data []byte, width uint, height uint) []byte

func (*ServingHandler) ServeHTTP

func (s *ServingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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