core

package
v0.2.7 Latest Latest
Warning

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

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

Documentation

Overview

Package core provides an extensible core implementation as well as standard handlers for a http server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultServe

func DefaultServe(w http.ResponseWriter, r Resource) error

DefaultServe serve the Resource.

func SetDefaultHeaders

func SetDefaultHeaders(w http.ResponseWriter, info ResourceInfo)

SetDefaultHeaders set headers for the http response.

Types

type Core

type Core struct {
	Handlers
	Sugared
	// contains filtered or unexported fields
}

Core describes the state of application

func NewCore

func NewCore() Core

NewCore creates a new Core.

func (*Core) ApplyExtension

func (c *Core) ApplyExtension(ext Extension) *Core

ApplyExtension applies an extension on core state.

func (*Core) ApplyGetObject

func (c *Core) ApplyGetObject(decorator HandlerDecorator) *Core

ApplyGetObject decorate the current GetObject handler.

func (*Core) ApplyHeader

func (c *Core) ApplyHeader(decorator HeaderHandlerDecorator) *Core

ApplyHeader decorate the current Header handler.

func (*Core) ApplyServe

func (c *Core) ApplyServe(decorator ServeHandlerDecorator) *Core

ApplyServe decorate the current Serve handler.

func (*Core) ApplyStatObject

func (c *Core) ApplyStatObject(decorator HandlerDecorator) *Core

ApplyStatObject decorate the current StatObject handler.

func (*Core) ChainGetObject

func (c *Core) ChainGetObject(handler Handler) *Core

ChainGetObject applies a GetObject handler.

func (*Core) ChainStatObject

func (c *Core) ChainStatObject(handler Handler) *Core

ChainStatObject applies a StatObject handler.

func (*Core) Init

func (c *Core) Init() *Core

Init initialize the core state.

type Extension

type Extension = func(*Core) (string, error)

Extension is a function that decorates a Core struct.

type Handler

type Handler = func(url string) (Resource, error)

Handler is a returns a Resource with a provided url.

func ChainHandlers

func ChainHandlers(handlers ...Handler) Handler

ChainHandlers returns a new handler that chains handlers sequetially

type HandlerDecorator

type HandlerDecorator = func(Handler) Handler

HandlerDecorator decorates a Handler.

type Handlers

type Handlers struct {
	StatObject func(url string) (Resource, error)
	GetObject  func(url string) (Resource, error)
	ListFolder func(url string) (Resource, error)
	SetHeaders func(w http.ResponseWriter, info ResourceInfo)
	Serve      func(w http.ResponseWriter, r Resource) error
	Sugared
}

Handlers describes how to get Resource metadata, retrieve Resource from S3 compatible backend, how to set the Headers, as well as how to serve the Resource.

func (*Handlers) GetHandler

func (h *Handlers) GetHandler(w http.ResponseWriter, r *http.Request)

GetHandler handles the request when method is GET.

func (*Handlers) Handler

func (h *Handlers) Handler() func(w http.ResponseWriter, r *http.Request)

Handler sets some defaults and returns a handler function.

func (*Handlers) HeadHandler

func (h *Handlers) HeadHandler(w http.ResponseWriter, r *http.Request)

HeadHandler handles the request when method is HEAD.

type HandlersToUse

type HandlersToUse struct {
	StatObjects []Handler
	GetObjects  []Handler
}

HandlersToUse describes the types of handlers.

type HeaderHandler

type HeaderHandler = func(w http.ResponseWriter, info ResourceInfo)

HeaderHandler handles the response header with the provided resource info.

type HeaderHandlerDecorator

type HeaderHandlerDecorator = func(HeaderHandler) HeaderHandler

HeaderHandlerDecorator decorates a HeaderHandler.

type Resource

type Resource struct {
	Data io.Reader
	Info ResourceInfo
	Msg  string
}

Resource represents the retrieved resource from the S3 compatible backend to be streamed.

type ResourceInfo

type ResourceInfo struct {
	Key          string
	Size         int64
	ETag         string
	ContentType  string
	LastModified time.Time
}

ResourceInfo describes the metadata of the resource.

type ServeHandler

type ServeHandler = func(w http.ResponseWriter, r Resource) error

ServeHandler handles the serving of a resource.

type ServeHandlerDecorator

type ServeHandlerDecorator = func(ServeHandler) ServeHandler

ServeHandlerDecorator decorates a ServeHandler.

type Sugared added in v0.2.1

type Sugared struct {
	Sugar *zap.SugaredLogger
}

Sugared can be used to composite other object witj a sugared logger

Jump to

Keyboard shortcuts

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