floz

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 5 Imported by: 0

README

Floz

An efficient and easy-to-use web framework based on fasthttp for Go.

Install
go get github/Quaestiox@v0.1.0
QuickStart
func main() {
    app := floz.Default()
    app.Server().Get("/", handleRoot).
        Scope("/v1").Get("/hello", handle1)

    app.Run(":8788")
}

func handleRoot(ctx *floz.Ctx) {
    ctx.JSON(floz.H{
        "username": "x",
        "password": "123456",
    })
}

func handle1(ctx *floz.Ctx) {
    ctx.String("hello world!")
}
Middleware

You can use Wrap() to add middleware for Floz or Scopes.
Here are two ways to add middleware for Floz application.

app := floz.New().Wrap(Log)
mw  := floz.NewMW(Log)
app := floz.New(mw)
Data

The Data is shared by all routes and scopes in the application.

example:

type State struct {
    name  string
    count int
}

func main() {
    app := floz.Default().Data(State{name: "try", count: 0})
    app.Server().Get("/data", handleData)
    app.Run(":8788")
}

func handleData(ctx *floz.Ctx) {
    data := ctx.Data().(State)
    ctx.JSON(floz.H{
        "appName": data.name,
        "count":   data.count,
    })
}

Documentation

Index

Constants

View Source
const (
	MIMETextXML         = "text/xml"
	MIMETextHTML        = "text/html"
	MIMETextPlain       = "text/plain"
	MIMETextJavaScript  = "text/javascript"
	MIMETextCSS         = "text/css"
	MIMEApplicationXML  = "application/xml"
	MIMEApplicationJSON = "application/json"
)

===== MIME type =====

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	JSONEncoder JSONMarshal
}

func NewConfig

func NewConfig() *Config

type Ctx

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

func NewCtx

func NewCtx(floz *Floz, ctx *fasthttp.RequestCtx) *Ctx

func (*Ctx) Data added in v0.1.3

func (c *Ctx) Data() any

func (*Ctx) JSON

func (c *Ctx) JSON(data any, code ...int) error

func (*Ctx) Method

func (c *Ctx) Method() string

func (*Ctx) Next

func (c *Ctx) Next()

func (*Ctx) Para

func (c *Ctx) Para(key string) string

func (*Ctx) Paras

func (c *Ctx) Paras() map[string]string

func (*Ctx) Path

func (c *Ctx) Path() string

func (*Ctx) Set

func (c *Ctx) Set(key, v string)

func (*Ctx) Status

func (c *Ctx) Status(code int) *Ctx

func (*Ctx) String

func (c *Ctx) String(str string, code ...int) error

func (*Ctx) URI

func (c *Ctx) URI() string

func (*Ctx) Write

func (c *Ctx) Write(p []byte) (n int, err error)

type Floz

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

func Default added in v0.1.1

func Default() *Floz

Default Floz has default middleware: recover.

func New

func New(middleware ...*MiddleWare) *Floz

func (*Floz) Data added in v0.1.3

func (floz *Floz) Data(data any) *Floz

func (*Floz) Handle

func (floz *Floz) Handle(c *fasthttp.RequestCtx)

func (*Floz) Run

func (floz *Floz) Run(port string)

func (*Floz) Server

func (floz *Floz) Server() *Server

func (*Floz) Wrap

func (floz *Floz) Wrap(middlewares ...ReqHandler) *Floz

type H

type H map[string]any

type JSONMarshal

type JSONMarshal func(v any) ([]byte, error)

type MiddleWare

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

func NewMW

func NewMW(mws ...ReqHandler) *MiddleWare

type ReqHandler

type ReqHandler func(*Ctx)

func MWRecover added in v0.1.3

func MWRecover() ReqHandler

type Scope

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

func (*Scope) Get

func (s *Scope) Get(path string, handler ReqHandler) *Scope

func (*Scope) Post

func (s *Scope) Post(path string, handler ReqHandler) *Scope

func (*Scope) Scope

func (s *Scope) Scope(prefix string, middlewares ...ReqHandler) *Scope

func (*Scope) Wrap

func (s *Scope) Wrap(middlewares ...ReqHandler) *Scope

type Server

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

func (*Server) Get

func (s *Server) Get(path string, handler ReqHandler) *Server

func (*Server) Post

func (s *Server) Post(path string, handler ReqHandler) *Server

func (*Server) Scope

func (s *Server) Scope(prefix string) *Scope

Jump to

Keyboard shortcuts

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