server

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package server implements the file storage service functionality and API.

Index

Constants

View Source
const (
	HttpGET     = "GET"     // HTTP get method.
	HttpPOST    = "POST"    // HTTP post method.
	HttpPUT     = "PUT"     // HTTP put method.
	HttpDELETE  = "DELETE"  // HTTP delete method.
	HttpOPTIONS = "OPTIONS" // HTTP options method.
)
View Source
const (
	RootSymbol = "/"
)

Variables

View Source
var (
	FlagTrue  = true
	FlagFalse = false
)

Functions

func StartServer

func StartServer(cfg *Configuration) *http.Server

StartServer starts the file server.

func StopServer added in v0.0.8

func StopServer(httpServer *http.Server)

StopServer gracefully stops the server.

Types

type Configuration

type Configuration struct {
	ServerPort    int    `json:"serverPort"`    // Port number on which the server will be waiting for requests.
	RootDirectory string `json:"rootDirectory"` // Name of the root directory, where all content will be stored.
	UrlPrefix     string `json:"urlPrefix"`     // Prefix that will be prepended to all API endpoints.
}

Configuration structure stores all configuration options available for the server. ServerPort defines the port number the file server will be listening for incoming API requests. RootDirectory defines the directory that is a parent for all other directories and files stored on server. All directory or file names used in API calls should be relative to root directory. UrlPrefix defines the prefix that will be prepended to all API endpoints.

func (*Configuration) DisplaySummary

func (c *Configuration) DisplaySummary()

DisplaySummary prints current configuration setting to standard output.

type Directory

type Directory struct {
	Name        string       `json:"name,omitempty"         api:"Name of the directory without parent path."`
	Directories []*Directory `json:"directories,omitempty"  api:"Child directories in this directory."`
	Files       []*File      `json:"files,omitempty"        api:"Files contained in this directory."`
}

Directory stores directory attributes like name and contained files and directories.

func (*Directory) AddDirectory

func (d *Directory) AddDirectory(name string) *Directory

AddDirectory adds new subdirectory with specified name.

func (*Directory) AddFile

func (d *Directory) AddFile(name string, size int64) *File

AddFile adds new file with specified name and size.

type DirectoryDto

type DirectoryDto struct {
	Data *Directory `json:"data"  api:"Directory details."`
}

DTO for directory.

type DirectoryListDto added in v0.0.8

type DirectoryListDto struct {
	Data []string `json:"data"  api:"List of directories."`
}

DTO for directory list.

type ErrorDto

type ErrorDto struct {
	Status string `json:"status"  api:"The HTTP status code applicable to this problem."`
	Code   string `json:"code"    api:"An application-specific error code."`
	Title  string `` /* 136-byte string literal not displayed */
	Detail string `json:"detail"  api:"A human-readable explanation specific to this occurrence of the problem."`
}

type ErrorsDto

type ErrorsDto struct {
	Errors []ErrorDto `json:"errors"  api:"List of encountered problems"`
}

type File

type File struct {
	Name     *string `json:"name,omitempty"      api:"File name without parent path."`
	Size     *int64  `json:"size,omitempty"      api:"File size in bytes."`
	Checksum *string `json:"checksum,omitempty"  api:"File checksum (SHA256)."`
	Exists   *bool   `json:"exists,omitempty"    api:"Flag indicating if file exists."`
}

File stores single file attributes like name and size.

type FileDto

type FileDto struct {
	Data *File `json:"data,omitempty"  api:"File details."`
}

DTO object for file.

type Handler

type Handler func(w http.ResponseWriter, req *http.Request)

Type for defining request handlers.

type RouteHandler

type RouteHandler func(cfg *Configuration, w http.ResponseWriter, req *http.Request)

Type for defining route handlers.

Jump to

Keyboard shortcuts

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