core

package module
v0.0.0-...-70e99ff Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func App

func App(cfg *Config, controllers ...Controller)

func StartStop

func StartStop(startFunc, stopFunc func())

Types

type Config

type Config struct {
	Server struct {
		Protocol string
		Http     struct {
			Addr string
		}

		Https struct {
			Addr string
			Tls  struct {
				CertFile string
				KeyFile  string
			}
		}

		Timeout struct {
			Read       int64
			ReadHeader int64
			Write      int64
			Idle       int64
			StopServer int64
		}

		FileServer struct {
			Used                 bool
			SearchFileIfError404 bool
			PathPrefix, Dir      string
		}
	}

	Token struct {
		Backend    string
		CookieName string
		CryptAES   struct {
			//The key argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
			SecretKeyNext, SecretKeyPrevious string
		}
		JoseSign struct {
			SecretKeyNext, SecretKeyPrevious string
			// https://pkg.go.dev/github.com/dvsekhvalnov/jose2go@v1.5.0?utm_source=gopls#Sign
			Algorithm string
			Compress  bool
		}
		JoseCrypt struct {
			SecretKeyNext, SecretKeyPrevious string
			// https://pkg.go.dev/github.com/dvsekhvalnov/jose2go@v1.5.0?utm_source=gopls#Encrypt
			Alg, Enc string
			Compress bool
		}
	}

	Sessions struct {
		Backend string
		Ram     struct {
			Expiries        int64
			CleanupInterval int64

			IsSnapshot       bool
			SnapshotFile     string
			SnapshotInterval int64
		}
	}

	Cache struct {
		Backend   string
		Freecache struct {
			BytesMaxSize int
		}
	}

	Renderer struct {
		Dir    string
		Suffix string
	}

	Error struct {
		Display bool
	}

	Log struct {
		// trace, debug, info, warn, error, fatal, panic
		// https://pkg.go.dev/github.com/sirupsen/logrus?utm_source=godoc#Level
		Level string
		//json else text
		Format string
		// write log to file
		File   string
		Stdout bool
	}
}

func (*Config) SetDefaultValuesAndVAlidateRequire

func (cfg *Config) SetDefaultValuesAndVAlidateRequire()

type Controller

type Controller interface {
	Construct(c *Core)
	Destruct(c *Core)
}

type Core

type Core struct {
	Errors *Errors

	Middlewares struct {
		Token   CoreMiddleware
		Session CoreMiddleware
	}

	Log      logger.Logger
	Services *Services
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) *Core

func (Core) DELETE

func (r Core) DELETE(p string, fn Handler, m ...Middleware)

func (Core) GET

func (r Core) GET(p string, fn Handler, m ...Middleware)

func (*Core) GetCfgFileServerAndRun

func (c *Core) GetCfgFileServerAndRun()

func (Core) Handle

func (r Core) Handle(method string, p string, fn Handler, m ...Middleware)

func (*Core) MergeGroup

func (c *Core) MergeGroup(group *Group)

func (*Core) NewGroup

func (c *Core) NewGroup(prefix string) *Group

func (Core) PATCH

func (r Core) PATCH(p string, fn Handler, m ...Middleware)

func (Core) POST

func (r Core) POST(p string, fn Handler, m ...Middleware)

func (Core) PUT

func (r Core) PUT(p string, fn Handler, m ...Middleware)

func (*Core) ServeFiles

func (c *Core) ServeFiles(path string, root http.FileSystem)

func (*Core) ServeHTTP

func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Core) Start

func (c *Core) Start()

func (*Core) Stop

func (c *Core) Stop() error

type CoreMiddleware

type CoreMiddleware interface {
	Request(Handler) Handler
	Response(Handler) Handler
}

type DefaultMiddlewareSession

type DefaultMiddlewareSession struct {
}

func (*DefaultMiddlewareSession) Request

func (*DefaultMiddlewareSession) Response

func (s *DefaultMiddlewareSession) Response(h Handler) Handler

type DefaultMiddlewareToken

type DefaultMiddlewareToken struct {
}

func (*DefaultMiddlewareToken) Request

func (s *DefaultMiddlewareToken) Request(h Handler) Handler

func (*DefaultMiddlewareToken) Response

func (s *DefaultMiddlewareToken) Response(h Handler) Handler

func (*DefaultMiddlewareToken) UnmarshalIfNew

func (s *DefaultMiddlewareToken) UnmarshalIfNew(p *Provider, val string)

type ErrorHandler

type ErrorHandler func(*Core, http.ResponseWriter, *http.Request)

func (ErrorHandler) ToHttpHandler

func (er ErrorHandler) ToHttpHandler(c *Core) http.Handler

type ErrorHttpHandler

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

func (*ErrorHttpHandler) ServeHTTP

func (er *ErrorHttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Errors

type Errors struct {
	NotFound         ErrorHandler
	MethodNotAllowed ErrorHandler

	PanicHandler func(*Core, http.ResponseWriter, *http.Request, interface{})
	ErrorHandler func(*Core, http.ResponseWriter, *http.Request, error)
}

type Group

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

func (*Group) AddRequestMiddleware

func (g *Group) AddRequestMiddleware(add Middleware)

func (*Group) AddResponseMiddleware

func (g *Group) AddResponseMiddleware(add Middleware)

func (*Group) DELETE

func (g *Group) DELETE(path string, fn Handler, m ...Middleware)

func (*Group) GET

func (g *Group) GET(path string, fn Handler, m ...Middleware)

func (*Group) PATCH

func (g *Group) PATCH(path string, fn Handler, m ...Middleware)

func (*Group) POST

func (g *Group) POST(path string, fn Handler, m ...Middleware)

func (*Group) PUT

func (g *Group) PUT(path string, fn Handler, m ...Middleware)

type Handler

type Handler func(*Provider) error

type Middleware

type Middleware func(Handler) Handler

type MiddlewarePre

type MiddlewarePre func(http.HandlerFunc) http.HandlerFunc

type Multiplexor

type Multiplexor interface {
	Init(c *Core) error
	ServeFiles(patch string, dir http.FileSystem)
	Handle(method string, path string, fn Handler)
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

type MultiplexorJulienschmidtHttpRouter

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

func (*MultiplexorJulienschmidtHttpRouter) Handle

func (m *MultiplexorJulienschmidtHttpRouter) Handle(method string, path string, fn Handler)

func (*MultiplexorJulienschmidtHttpRouter) Init

func (*MultiplexorJulienschmidtHttpRouter) ServeFiles

func (m *MultiplexorJulienschmidtHttpRouter) ServeFiles(patch string, dir http.FileSystem)

func (*MultiplexorJulienschmidtHttpRouter) ServeHTTP

type Param

type Param interface {
	Param(key string) string
}

type Provider

type Provider struct {
	Log     *Logger
	Context context.Context
	Token   *token.Token
	Session *values.Value
	Cache   cache.CacheInterface

	WriterBuff *bytes.Buffer

	Services *Services
	// contains filtered or unexported fields
}

func (*Provider) Close

func (c *Provider) Close()

func (*Provider) GetConfig

func (c *Provider) GetConfig() Config

func (*Provider) GetCookie

func (c *Provider) GetCookie(name string) (*http.Cookie, error)

func (*Provider) GetStatusCode

func (c *Provider) GetStatusCode() int

func (*Provider) Header

func (c *Provider) Header() http.Header

func (*Provider) Param

func (p *Provider) Param(key string) string

func (*Provider) PostFormValue

func (c *Provider) PostFormValue(name string) string

func (*Provider) SetCookie

func (c *Provider) SetCookie(Cookie *http.Cookie)

func (*Provider) SetStatusCode

func (c *Provider) SetStatusCode(status int)

func (*Provider) WriteHtml

func (c *Provider) WriteHtml(status int, html string) error

func (*Provider) WriteJson

func (c *Provider) WriteJson(status int, in interface{}) error

func (*Provider) WriteRaw

func (c *Provider) WriteRaw(status int, contentType string, val []byte) error

type Services

type Services struct {
	Token       TokenService
	Sessions    sessions.Session
	Cache       *cache.Cache
	Multiplexor Multiplexor
}

type TokenService

type TokenService struct {
	CookieName     string
	Next, Previous token.Encoder
}

Directories

Path Synopsis
adapters
lib
values
Code generated by easyjson for marshaling/unmarshaling.
Code generated by easyjson for marshaling/unmarshaling.
services

Jump to

Keyboard shortcuts

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