Help us shape the future of Go! Take the 2026 Go Developer Survey

atreugo

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: GPL-3.0 Imports: 8 Imported by: 22

README

Atreugo

Fasthttp Micro-framework is based on erikdubbelboer's fasthttp fork that it more active than valyala's fasthttp

This framework make simple to use the routing and middlewares.

package examples

import (
	"errors"

	"github.com/erikdubbelboer/fasthttp"
	"github.com/savsgio/atreugo"
)

func main() {
	server := atreugo.New()

	fnMiddlewareOne := func(ctx *fasthttp.RequestCtx) (int, error) {
		return fasthttp.StatusOK, nil
	}

	fnMiddlewareTwo := func(ctx *fasthttp.RequestCtx) (int, error) {
		println("This middleware launch an error...")
		return fasthttp.StatusBadRequest, errors.New("Fake error")
	}

	server.UseMiddleware(fnMiddlewareOne, fnMiddlewareTwo)

	server.Path("GET", "/", func(ctx *fasthttp.RequestCtx) error {
		return atreugo.HttpResponse(ctx, []byte("<h1>Atreugo Micro-Framework</h1>"))
	})

	server.Path("GET", "/jsonPage", func(ctx *fasthttp.RequestCtx) error {
		return atreugo.JsonResponse(ctx, atreugo.Json{"Atreugo": true})
	})

	server.ListenAndServe("0.0.0.0", 8000)
}

Contributing

Feel free to contribute it or fork me... 😉

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func B2S

func B2S(b []byte) string

B2S convert bytes array to string without memory allocation

func HttpResponse

func HttpResponse(ctx *fasthttp.RequestCtx, response []byte, statusCode ...int) error

func JsonResponse

func JsonResponse(ctx *fasthttp.RequestCtx, response interface{}, statusCode ...int) error

Types

type Atreugo

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

Atreugo config for make up a server

func New

func New() *Atreugo

New create a new instance of Atreugo Server

func (*Atreugo) ListenAndServe

func (server *Atreugo) ListenAndServe(host string, port int, logLevel ...string)

ListenAndServe start Atreugo server

func (*Atreugo) Path

func (server *Atreugo) Path(httpMethod string, url string, viewFn view)

Path add the views to serve

func (*Atreugo) Static

func (server *Atreugo) Static(rootStaticDirPath string)

Static add view for static files

func (*Atreugo) UseMiddleware

func (server *Atreugo) UseMiddleware(fns ...middleware)

UseMiddleware register middleware functions that viewHandler will use

type Json

type Json map[string]interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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