weeb

package module
v0.0.0-...-4c8c6fa Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: MIT Imports: 10 Imported by: 0

README

Weeb Web Framework

Weeb is a web framework written in Go (Golang). It features an expressjs-like API.

Quick Start

package main

import (
	"io"
	"log"
	"net/http"

	"github.com/weebgo/weeb"
)

func main() {
	app := weeb.New()
	app.Get("/", func(w http.ResponseWriter, req *http.Request, next func()) {
		io.WriteString(w, "Hello World")
	})
	log.Fatal(http.ListenAndServe(":3000", app))
}

Documentation

Index

Constants

View Source
const (
	// Enables automatic use similar route if the current route can't be
	// matched but a handle for the path with (without) the trailing slash exists.
	// For example if /foo/ is requested but a route only exists for /foo,
	// the handler for /foo will be used to handle /foo/ as well.
	TrailingSlashPolicyStatic = TrailingSlashPolicy(iota)

	// Enables automatic redirection if the current route can't be matched but a
	// handle for the path with (without) the trailing slash exists.
	// For example if /foo/ is requested but a route only exists for /foo, the
	// client is redirected to /foo with http status code 301.
	TrailingSlashPolicyRedirect

	// Disable automatic handle the trailing slash in URL.
	TrailingSlashPolicyNone

	HTTPMethodAll = "ALL"
)
View Source
const DefaultDelimiter = "/"

Default configs.

Variables

View Source
var PathRegexp = regexp2.MustCompile(strings.Join([]string{
	"(\\\\.)",
	"(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?",
}, "|"), regexp2.None)

The main path matching regexp utility.

Functions

This section is empty.

Types

type App

type App struct {
	*Router
}

func New

func New() *App

func (*App) Use

func (app *App) Use(params ...interface{})

type Handle

type Handle func(http.ResponseWriter, *http.Request, func())

type Router

type Router struct {

	// How to handle the trailing slash in URL
	// TrailingSlashPolicyStatic (default) or TrailingSlashPolicyRedirect
	// or TrailingSlashPolicyNone
	TrailingSlashPolicy TrailingSlashPolicy

	// Function to handle panics recovered from http handlers.
	// It should be used to generate a error page and return the http error code
	// 500 (Internal Server Error).
	// The handle can be used to keep your server from crashing because of
	// unrecovered panics.
	PanicHandler func(http.ResponseWriter, *http.Request, interface{})
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) All

func (r *Router) All(route string, handle Handle)

func (*Router) Delete

func (r *Router) Delete(route string, handle Handle)

func (*Router) Get

func (r *Router) Get(route string, handle Handle)

func (*Router) Handle

func (r *Router) Handle(method, route string, handle Handle)

func (*Router) Head

func (r *Router) Head(route string, handle Handle)

func (*Router) Options

func (r *Router) Options(route string, handle Handle)

func (*Router) Patch

func (r *Router) Patch(route string, handle Handle)

func (*Router) Post

func (r *Router) Post(route string, handle Handle)

func (*Router) Put

func (r *Router) Put(route string, handle Handle)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) Use

func (r *Router) Use(middleware Handle)

type TrailingSlashPolicy

type TrailingSlashPolicy int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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