simpleuploadserver

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FormFileKey       = "file"
	OverwriteQueryKey = "overwrite"
)
View Source
var (
	DefaultAddr = "127.0.0.1:8080"
)
View Source
var (
	ErrFileSizeLimitExceeded = fmt.Errorf("file size limit exceeded")
)

Functions

func SHA256Strategy

func SHA256Strategy(file multipart.File, info *multipart.FileHeader) (string, error)

func UUIDStrategy

func UUIDStrategy(multipart.File, *multipart.FileHeader) (string, error)

Types

type ErrorResult

type ErrorResult struct {
	OK    bool   `json:"ok"`
	Error string `json:"error"`
}

type FileNamingStrategy

type FileNamingStrategy func(multipart.File, *multipart.FileHeader) (string, error)
var DefaultNamingStrategy FileNamingStrategy = UUIDStrategy

func ResolveFileNamingStrategy

func ResolveFileNamingStrategy(name string) FileNamingStrategy

type Server

type Server struct {
	ServerConfig
	// contains filtered or unexported fields
}

func NewServer

func NewServer(config ServerConfig) *Server

NewServer creates a new Server.

func (*Server) Start

func (s *Server) Start(ctx context.Context, ready chan struct{}) error

Start starts listening on `addr`. This function blocks until the server is stopped. Optionally you can pass a channel to `ready` to be notified when the server is ready to accept connections. You can pass nil if you don't need it.

type ServerConfig

type ServerConfig struct {
	// Address where the server listens on.
	Addr string `json:"addr"`
	// Path to the document root.
	DocumentRoot string `json:"document_root"`
	// Determines whether to enable CORS header.
	EnableCORS bool `json:"enable_cors"`
	// Maximum upload size in bytes.
	MaxUploadSize int64 `json:"max_upload_size"`
	// File naming strategy.
	FileNamingStrategy string `json:"file_naming_strategy"`
	// Graceful shutdown timeout in milliseconds.
	ShutdownTimeout int `json:"shutdown_timeout"`
	// Enable authentication.
	EnableAuth bool `json:"enable_auth"`
	// Authentication tokens for read-only access.
	ReadOnlyTokens []string `json:"read_only_tokens"`
	// Authentication tokens for read-write access.
	ReadWriteTokens []string `json:"read_write_tokens"`
}

ServerConfig is a configuration for Server.

type SuccessfullyUploadedResult

type SuccessfullyUploadedResult struct {
	OK   bool   `json:"ok"`
	Path string `json:"path"`
}

Jump to

Keyboard shortcuts

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