responsehandler

package
v0.0.0-...-8f1e39b Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneralBadRequestError

func GeneralBadRequestError(
	req *http.Request,
	res http.ResponseWriter,
	cfgManager config.Manager,
	err error,
)

func GeneralForbiddenError

func GeneralForbiddenError(
	req *http.Request,
	res http.ResponseWriter,
	cfgManager config.Manager,
	err error,
)

func GeneralInternalServerError

func GeneralInternalServerError(
	req *http.Request,
	res http.ResponseWriter,
	cfgManager config.Manager,
	err error,
)

func GeneralNotFoundError

func GeneralNotFoundError(
	req *http.Request,
	res http.ResponseWriter,
	cfgManager config.Manager,
)

func GeneralUnauthorizedError

func GeneralUnauthorizedError(
	req *http.Request,
	res http.ResponseWriter,
	cfgManager config.Manager,
	err error,
)

func HTTPMiddleware

func HTTPMiddleware(cfgManager config.Manager, targetKey string) func(next http.Handler) http.Handler

HTTPMiddleware will add a new response handler on each request.

func SetResponseHandlerInContext

func SetResponseHandlerInContext(ctx context.Context, resH ResponseHandler) context.Context

SetResponseHandlerInContext will set a response handler object in a context.

Types

type DeleteInput

type DeleteInput struct {
	Key string
}

DeleteInput represents a delete input.

type Entry

type Entry struct {
	LastModified time.Time
	Type         string
	ETag         string
	Name         string
	Key          string
	Path         string
	Size         int64
}

Entry Entry with path for internal use (template).

type PutInput

type PutInput struct {
	Metadata     map[string]string
	Key          string
	ContentType  string
	StorageClass string
	Filename     string
	ContentSize  int64
}

PutInput represents a put input.

type ResponseHandler

type ResponseHandler interface {
	// TargetList will answer for the target list response.
	TargetList()
	// Put will answer for the put response.
	Put(
		loadFileContent func(ctx context.Context, path string) (string, error),
		input *PutInput,
	)
	// Delete will answer for the delete response.
	Delete(
		loadFileContent func(ctx context.Context, path string) (string, error),
		input *DeleteInput,
	)
	// NotModified will answer with a Not Modified status code.
	NotModified()
	// PreconditionFailed will answer with a Precondition Failed status code.
	PreconditionFailed()
	// RedirectWithTrailingSlash will redirect with a trailing slash.
	RedirectWithTrailingSlash()
	// RedirectTo will redirect to an url.
	RedirectTo(url string)
	// StreamFile will stream file in output.
	// Error will be managed outside of this function because of the workflow in the caller function.
	StreamFile(
		loadFileContent func(ctx context.Context, path string) (string, error),
		input *StreamInput,
	) error
	// FoldersFilesList will answer with the folder list output coming from template.
	FoldersFilesList(
		loadFileContent func(ctx context.Context, path string) (string, error),
		entries []*Entry,
	)
	// NotFoundError will answer for not found error.
	NotFoundError(
		loadFileContent func(ctx context.Context, path string) (string, error),
	)
	// ForbiddenError will answer for forbidden error.
	ForbiddenError(
		loadFileContent func(ctx context.Context, path string) (string, error),
		err error,
	)
	// BadRequestError will answer for bad request error.
	BadRequestError(
		loadFileContent func(ctx context.Context, path string) (string, error),
		err error,
	)
	// UnauthorizedError will answer for unauthorized error.
	UnauthorizedError(
		loadFileContent func(ctx context.Context, path string) (string, error),
		err error,
	)
	// InternalServerError will answer for internal server error.
	InternalServerError(
		loadFileContent func(ctx context.Context, path string) (string, error),
		err error,
	)
	// UpdateRequestAndResponse will update request and response in object.
	// This will used to update request and response in order to have the latest context values.
	UpdateRequestAndResponse(req *http.Request, res http.ResponseWriter)
	// GetRequest will return the actual request object.
	GetRequest() *http.Request
}

ResponseHandler will handle responses.

func GetResponseHandlerFromContext

func GetResponseHandlerFromContext(ctx context.Context) ResponseHandler

GetResponseHandlerFromContext will return the response handler object from context.

func NewHandler

func NewHandler(req *http.Request, res http.ResponseWriter, cfgManager config.Manager, targetKey string) ResponseHandler

NewHandler will return a new response handler object.

type StreamInput

type StreamInput struct {
	LastModified       time.Time
	Body               io.ReadCloser
	Metadata           map[string]string
	CacheControl       string
	Expires            string
	ContentDisposition string
	ContentEncoding    string
	ContentLanguage    string
	ContentRange       string
	ContentType        string
	ETag               string
	ContentLength      int64
}

StreamInput represents a stream input file.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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