rester

module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: Apache-2.0

README

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 Echo1Ctl struct {
	rester.BaseController
}

func (ctl *Echo1Ctl) GET(args struct {
	A string `query:"a"`
}) {
	ctl.Logger().Printf("Echo1Ctl: a=%s", args.A)
	ctl.SetUserValue("a", args.A)
}

type Echo2Ctl struct {
	Echo1Ctl
}

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

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

More examples

Binding

binding doc

Directories

Path Synopsis
Package chain convert the method of nested fields in structure to call chain function.
Package chain convert the method of nested fields in structure to call chain function.
example
cors command
echo command
file command

Jump to

Keyboard shortcuts

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