fresh

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

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

Go to latest
Published: Jul 19, 2022 License: GPL-3.0 Imports: 26 Imported by: 2

README

Build status GoReport GoDoc License Gitter


RESTful framework built on top of the best dev patterns


Quickstart

go get github.com/tockins/fresh

Documentation

You can read the full documentation of Fresh here.

Contributing

Please read our guideline here.

License

Fresh is licensed under the GNU GENERAL PUBLIC LICENSE V3.

TODO

  • input validation
  • dto?

Documentation

Index

Constants

View Source
const (
	MIMEAppJSON    = "application/json" + ";" + UTF8
	MIMEAppJS      = "application/javascript" + ";" + UTF8
	MIMEAppXML     = "application/xml" + ";" + UTF8
	MIMEUrlencoded = "application/x-www-form-urlencoded"
	MIMEMultipart  = "multipart/form-data"
	MIMETextHTML   = "text/html" + ";" + UTF8
	MIMETextXML    = "text/xml" + ";" + UTF8
	MIMEText       = "text/plain" + ";" + UTF8
	MIMEGzip       = "gzip"
)

MIME types

View Source
const (
	AccessControlMaxAge           = "Access-Control-Max-Age"
	AccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	AccessControlAllowMethods     = "Access-Control-Allow-Methods"
	AccessControlAllows           = "Access-Control-Allow-s"
	AccessControlRequestMethod    = "Access-Control-Request-Method"
	AccessControlExposes          = "Access-Control-Expose-s"
	AccessControlRequests         = "Access-Control-Request-s"
	AccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	AccessControlAllowHeaders     = "Access-Control-Allow-Headers"
)

Access

View Source
const (
	Accept              = "Accept"
	AcceptEncoding      = "Accept-Encoding"
	Allow               = "Allow"
	Authorization       = "Authorization"
	ContentDisposition  = "Content-Disposition"
	ContentEncoding     = "Content-Encoding"
	ContentLength       = "Content-Length"
	ContentType         = "Content-Type"
	Cookie              = "Cookie"
	SetCookie           = "Set-Cookie"
	IfModifiedSince     = "If-Modified-Since"
	LastModified        = "Last-Modified"
	Location            = "Location"
	Upgrade             = "Upgrade"
	Vary                = "Vary"
	WWWAuthenticate     = "WWW-Authenticate"
	XForwardedFor       = "X-Forwarded-For"
	XForwardedProto     = "X-Forwarded-Proto"
	XForwardedProtocol  = "X-Forwarded-Protocol"
	XForwardedSsl       = "X-Forwarded-Ssl"
	XUrlScheme          = "X-Url-Scheme"
	XHTTPMethodOverride = "X-HTTP-Method-Override"
	XRealIP             = "X-Real-IP"
	XRequestID          = "X-Request-ID"
	Server              = "Server"
	Origin              = "Origin"
)

Request

View Source
const (
	UTF8     = "charset=UTF-8"
	ISO88591 = "chartset=ISO-8859-1"
)

Encoding chartset

View Source
const (
	B = 1 << (10 * iota)
	K
	M
	G
	T
)

Variables

This section is empty.

Functions

func PrintRouter

func PrintRouter(r *router)

Print the list of routes

Types

type CORS

type CORS struct {
	Origins     []string `yaml:"origins,omitempty"`
	Methods     []string `yaml:"methods,omitempty"`
	Headers     []string `yaml:"headers,omitempty"`
	Expose      []string `yaml:"expose,omitempty"`
	MaxAge      int      `yaml:"maxage,omitempty"`
	Credentials bool     `yaml:"credentials,omitempty"`
	Filters     []Filter `yaml:"-,omitempty"`
}

type Config

type Config struct {
	Host    string            `yaml:"host,omitempty"`    // server host
	Port    int               `yaml:"port,omitempty"`    // server port
	Logs    Logs              `yaml:"logs,omitempty"`    // server logs
	TSL     *TSL              `yaml:"tsl,omitempty"`     // tsl options
	Gzip    *Gzip             `yaml:"gzip,omitempty"`    // gzip Config
	CORS    *CORS             `yaml:"cors,omitempty"`    // cors options
	Limit   *Limit            `yaml:"limit,omitempty"`   // limit options
	Default []string          `yaml:"default,omitempty"` // default static files (index.html or main.html and so on)
	Statics map[string]string `yaml:"static,omitempty"`  // serve static files
	Banner  bool              `yaml:"banner,omitempty"`  // enable / disable startup banner
	Options bool              `yaml:"options,omitempty"` // accept all OPTIONS requests
	Router  *Router           `yaml:"router,omitempty"`  // router related config
	// contains filtered or unexported fields
}

func (Config) CRUD

func (f Config) CRUD(path string, h ...HandlerFunc) Resource

Register a resource (get, post, put, delete)

func (Config) Config

func (f Config) Config() *Config

Config return server settings

func (Config) DELETE

func (f Config) DELETE(path string, handler HandlerFunc) Handler

DELETE api registration

func (Config) GET

func (f Config) GET(path string, handler HandlerFunc) Handler

GET api registration

func (Config) Group

func (f Config) Group(path string) Group

Group registration

func (Config) OPTIONS

func (f Config) OPTIONS(path string, handler HandlerFunc) Handler

OPTIONS api registration

func (Config) PATCH

func (f Config) PATCH(path string, handler HandlerFunc) Handler

PATCH api registration

func (Config) POST

func (f Config) POST(path string, handler HandlerFunc) Handler

POST api registration

func (Config) PUT

func (f Config) PUT(path string, handler HandlerFunc) Handler

PUT api registration

func (Config) STATIC

func (f Config) STATIC(static map[string]string)

ASSETS serve a list of static files. Array of files or directories TODO write logic

func (Config) Start

func (f Config) Start() error

Start HTTP server

func (Config) Stop

func (f Config) Stop() error

Shutdown server

func (Config) TRACE

func (f Config) TRACE(path string, handler HandlerFunc) Handler

TRACE api registration

func (Config) WS

func (f Config) WS(path string, handler HandlerFunc) Handler

WS api registration

type Context

type Context interface {
	Request() Request
	Response() Response
	Writer(http.ResponseWriter)
}

Main Fresh structure

type Filter

type Filter func(Context) bool

type Fresh

type Fresh interface {
	Rest
	Stop() error
	Start() error
	Config() *Config
	Group(string) Group
}

Main Fresh structure

func New

func New() Fresh

New Fresh instance

type Group

type Group interface {
	Rest
	Group(string) Group
	After(...HandlerFunc) Group
	Before(...HandlerFunc) Group
}

type Gzip

type Gzip struct {
	Level   int      `yaml:"level,omitempty"`
	MinSize int      `yaml:"size,omitempty"`
	Types   []string `yaml:"types,omitempty"`
	Filters []Filter `yaml:"-,omitempty"`
	// contains filtered or unexported fields
}

func (*Gzip) Header

func (g *Gzip) Header() http.Header

Header return gzip header

func (*Gzip) Write

func (g *Gzip) Write(b []byte) (int, error)

Write gzip

func (*Gzip) WriteHeader

func (g *Gzip) WriteHeader(i int)

WriteHeader set a gzip header

type Handler

type Handler interface {
	After(...HandlerFunc) Handler
	Before(...HandlerFunc) Handler
}

Handler struct

type HandlerFunc

type HandlerFunc func(Context) error

Main Fresh structure

type Limit

type Limit struct {
	Body   string `yaml:"body,omitempty"`
	Header string `yaml:"header,omitempty"`
}

type Logs

type Logs struct {
	File   bool `yaml:"file,omitempty"`
	Stdout bool `yaml:"stdout,omitempty"`
}

type Request

type Request interface {
	IsWS() bool
	IsTSL() bool
	Auth() string
	AuthBearer() string
	URL() *url.URL
	Method() string
	Header() http.Header
	JSON(interface{}) error
	JSONraw() map[string]interface{}
	Form() url.Values
	Get() *http.Request
	WS() *websocket.Conn
	Body() io.ReadCloser
	QueryString() string
	SetWS(*websocket.Conn)
	RouteParam(string) string
	FormValue(string) string
	QueryParam(string) string
	// contains filtered or unexported methods
}

Request structure

type Resource

type Resource interface {
	After(...HandlerFunc) Resource
	Before(...HandlerFunc) Resource
}

type Response

type Response interface {
	Code(int) error
	Type(content string)
	Raw(int, string) error
	Error(int, error) error
	HTML(int, string) error
	File(int, string) error
	Get() http.ResponseWriter
	Download(int, string) error
	XML(int, interface{}) error
	Text(int, interface{}) error
	JSON(int, interface{}) error
	JSONP(int, string, interface{}) error
	XMLFormat(int, interface{}, string) error
	JSONFormat(int, interface{}, string) error
	JSONPFormat(int, string, interface{}, string) error
	// contains filtered or unexported methods
}

type Router

type Router struct {
	Print bool `yaml:"print,omitempty"`
}

type Security

type Security struct {
	XSS            string `yaml:"xss,omitempty"`
	HSTS           int    `yaml:"hsts,omitempty"`
	XDNS           bool   `yaml:"x-dns,omitempty"`
	CSFR           string `yaml:"csfr,omitempty"`
	XFrame         string `yaml:"x-frame,omitempty"`
	XContentType   string `yaml:"x-content-type,omitempty"`
	ReferrerPolicy string `yaml:"referrer-policy,omitempty"`
}

type TSL

type TSL struct {
	Force bool   `yaml:"force,omitempty"`
	Crt   string `yaml:"crt,omitempty"`
	Key   string `yaml:"key,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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