Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rester report card GitHub release GoDoc view Go网络编程群

Fast and concise RESTful web framework based on fasthttp.

Example

package main

import "github.com/henrylee2cn/rester"

type MwCtl struct {
	rester.BaseCtl
	skip bool
}

func (ctl *MwCtl) Any(args struct {
	A string `query:"a"`
}) {
	ctl.Logger().Printf("MwCtl: a=%s", args.A)
	if !ctl.skip {
		ctl.SetUserValue("a", args.A)
	}
}

type EchoCtl struct {
	MwCtl
}

func (ctl *EchoCtl) GET(args struct {
	B []string `query:"b"`
}) {
	ctl.Logger().Printf("EchoCtl: b=%v", args.B)
	ctl.OK(rester.H{
		"a": ctl.UserValue("a"),
		"b": args.B,
	})
}

func main() {
	engine := rester.New()
	engine.DefControl("/", new(EchoCtl))
	engine.Control("/from", func() rester.Controller {
		return &EchoCtl{
			MwCtl{skip: true},
		}
	})
	err := engine.ListenAndServe(":8080")
	if err != nil {
		panic(err)
	}
	// request:
	//  GET http://localhost:8080/?a=x&b=y&b=z
	// log:
	//  - MwCtl: a=x
	//  - EchoCtl: b=[y z]
	// response:
	//  {"a":"x","b":["y","z"]}

	// request:
	//  GET http://localhost:8080/from?a=x&b=y&b=z
	// log:
	//  - MwCtl: a=x
	//  - EchoCtl: b=[y z]
	// response:
	//  {"a":null,"b":["y","z"]}
}

More examples

Binding

binding doc

Controller

Design of method call chain for anonymous field of controller

Struct Method Chain

About

Fast and concise RESTful web framework based on fasthttp

Topics

Resources

Stars

27 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages