shift

package module
v0.0.0-...-dbec93a Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2020 License: MIT Imports: 7 Imported by: 0

README

status documentation actions atatus go report godoc go.dev reference license

Shift

Domain driven API framework written in Golang

Solution currently unusable and in active development.

Shift is based on idea of fully code-separated domains. The main benefit of such an approach would be the opportunity to work with a monolithic codebase in the early stages of the project and, over time, to move gradually towards microservices-based architecture. See project workflow graph.

Installation

go get -u github.com/DamianSkrzypczak/shift

Documentation

Index

Constants

View Source
const (
	TrailingSlashRedirect = "redirect" // Default trailing slash strategy
	TrailingSlashStrip    = "strip"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Server Server

	Router *Router
	Name   string
	Config *AppConfig
	// contains filtered or unexported fields
}

func New

func New(name string, config *AppConfig) *App

func (*App) Domain

func (app *App) Domain(path string, constructor func(d *Domain))

func (*App) Run

func (app *App) Run(addr string) error

func (*App) RunTLS

func (app *App) RunTLS(addr, certFile, keyFile string) error

type AppConfig

type AppConfig struct {
	Router RouterConfig
}

func NewAppConfig

func NewAppConfig() *AppConfig

type ContextProvider

type ContextProvider func(*Request) context.Context

type Domain

type Domain struct {
	Path   string
	Router *Router
	// contains filtered or unexported fields
}

type Handler

type Handler func(RequestContext)

func FromHTTPHandler

func FromHTTPHandler(h http.Handler) Handler

FromHTTP produces new Handler from http.HandlerFunc instance

func FromHTTPHandlerFunc

func FromHTTPHandlerFunc(h http.HandlerFunc) Handler

FromHTTP produces new Handler from http.HandlerFunc instance

func (Handler) ToHTTP

func (h Handler) ToHTTP() http.HandlerFunc

ToHTTTP adapts Handler interface to http.HandlerFunc interface

type Interceptor

type Interceptor func() (before, after func(RequestContext))

type Middleware

type Middleware func(next Handler) Handler

func FromHTTPMiddleware

func FromHTTPMiddleware(m func(h http.Handler) http.Handler) Middleware

FromHTTPMiddleware produces new Middleware from http-based middleware

func (Middleware) ToHTTP

func (m Middleware) ToHTTP() func(h http.Handler) http.Handler

type Middlewares

type Middlewares []Middleware

func (Middlewares) ToHTTP

func (ms Middlewares) ToHTTP() []func(h http.Handler) http.Handler

type QueryParameters

type QueryParameters map[string][]string

func (QueryParameters) PeekAll

func (qp QueryParameters) PeekAll(key string) []string

PeekAll values under given query parameter key. len(PeekAll()) == 0 for non-existing keys. PeekAll() == nil for non-existing keys.

func (QueryParameters) PeekFirst

func (qp QueryParameters) PeekFirst(key string) (value string, ok bool)

PeekFirst value under given query parameter key. v, ok := PeekFirst() ok == false for non-existing keys or no values for given key.

func (QueryParameters) PeekLast

func (qp QueryParameters) PeekLast(key string) (value string, ok bool)

PeekLast value under given query parameter key. v, ok := PeekFirst() ok == false for non-existing keys or no values for given key.

type Request

type Request struct {
	*http.Request

	QueryParameters QueryParameters
	QueryString     string
}

func NewRequest

func NewRequest(r *http.Request) *Request

func (*Request) BodyCopy

func (req *Request) BodyCopy() ([]byte, error)

func (*Request) JSON

func (req *Request) JSON(v interface{}) error

func (*Request) ToHTTP

func (req *Request) ToHTTP() *http.Request

func (*Request) URLParam

func (req *Request) URLParam(key string) string

type RequestContext

type RequestContext struct {
	Response *Response
	Request  *Request
}

func NewRequestContext

func NewRequestContext() RequestContext

type Response

type Response struct {
	http.ResponseWriter
}

func NewResponse

func NewResponse(r http.ResponseWriter) *Response

func (*Response) SetBodyBytes

func (resp *Response) SetBodyBytes(b []byte)

func (*Response) SetBodyJSON

func (resp *Response) SetBodyJSON(v interface{}) error

func (*Response) SetBodyString

func (resp *Response) SetBodyString(s string)

func (*Response) SetStatusCode

func (resp *Response) SetStatusCode(code int)

func (*Response) ToHTTP

func (resp *Response) ToHTTP() http.ResponseWriter

func (*Response) WithJSON

func (resp *Response) WithJSON(v interface{}, statusCode int) error

type Router

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

func (*Router) Connect

func (r *Router) Connect(path string, h Handler)

func (*Router) Delete

func (r *Router) Delete(path string, h Handler)

func (*Router) Get

func (r *Router) Get(path string, h Handler)

func (*Router) Head

func (r *Router) Head(path string, h Handler)

func (*Router) Method

func (r *Router) Method(method, path string, h Handler)

func (*Router) MethodNotAllowed

func (r *Router) MethodNotAllowed(h Handler)

func (*Router) NotFound

func (r *Router) NotFound(h Handler)

func (*Router) Options

func (r *Router) Options(path string, h Handler)

func (*Router) Patch

func (r *Router) Patch(path string, h Handler)

func (*Router) Post

func (r *Router) Post(path string, h Handler)

func (*Router) Put

func (r *Router) Put(path string, h Handler)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request)

func (*Router) Trace

func (r *Router) Trace(path string, h Handler)

func (*Router) Use

func (r *Router) Use(middlewares ...Middleware)

Use pushes given middleware onto router stack

func (*Router) UseContext

func (r *Router) UseContext(contextProvider ContextProvider)

UseContext works like Use but provides interface for contextProvider middleware

func (*Router) UseInterceptor

func (r *Router) UseInterceptor(interceptor Interceptor)

UseContext works like Use but provides interface for Interceptor middleware

func (*Router) With

func (r *Router) With(middlewares ...Middleware) *Router

Use pushes inlined middleware onto router stack.

func (*Router) WithContext

func (r *Router) WithContext(contextProvider ContextProvider) *Router

WithContext works like With but provides interface for contextProvider middleware

func (*Router) WithInterceptor

func (r *Router) WithInterceptor(interceptor Interceptor) *Router

WithContext works like With but provides interface for Interceptor middleware

type RouterConfig

type RouterConfig struct {
	TrailingSlashStrategy string
}

type Server

type Server interface {
	Initialize(addr string, router *Router)
	ListenAndServe() error
	ListenAndServeTLS(certFile, keyFile string) error
}

Jump to

Keyboard shortcuts

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