handler

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Websocket = faygo.WrapDoc(func(ctx *faygo.Context) error {
	var upgrader = websocket.Upgrader{}
	conn, err := upgrader.FayUpgrade(ctx, nil)
	if err != nil {
		return err
	}
	defer conn.Close()

	for {
		var req interface{}
		if err := conn.ReadJSON(&req); err != nil {
			ctx.Log().Warning("read:", err)
			return nil
		}
		ctx.Log().Info("req:", req)
		if err := conn.WriteJSON(map[string]string{"server_time": time.Now().String()}); err != nil {
			ctx.Log().Warning("write:", err)
			return nil
		}
	}
},
	"websocket example",
	map[string]string{"server_time": time.Now().String()},
)

Functions

func Index

func Index() faygo.HandlerFunc

func WebsocketPage

func WebsocketPage() faygo.HandlerFunc

Types

type Body

type Body struct {
	Json map[string]interface{} `param:"<in:body>"`
}

func (*Body) Serve

func (b *Body) Serve(ctx *faygo.Context) error

type Param

type Param struct {
	Id           int                   `param:"<in:path> <required> <desc:ID> <range: 0:10>"`
	Title        string                `param:"<in:query> <nonzero>"`
	Num          float32               `param:"<in:formData> <required> <name:n> <range: 0.1:10> <err: formData param 'n' must be number in 0.1~10>"`
	Paragraph    []string              `param:"<in:formData> <name:p> <len: 1:20> <regexp: ^[\\w&=]*$>"`
	Picture      *multipart.FileHeader `param:"<in:formData> <name:pic> <maxmb:30>"`
	Cookie       *http.Cookie          `param:"<in:cookie> <name:faygo>"`
	CookieString string                `param:"<in:cookie> <name:faygo>"`
}

func (*Param) Doc

func (p *Param) Doc() faygo.Doc

Doc returns the API's note, result or parameters information.

func (*Param) Serve

func (p *Param) Serve(ctx *faygo.Context) error

Implement the handler interface

type Render

type Render struct {
	Title      string `param:"<in:query> <nonzero>"`
	Paragraph  string `param:"<in:query> <name:p> <len: 1:10> <regexp: ^[\\w]*$>"`
	TestHeader string `param:"<in:header><name:Test-Header> <required><test header>"`
}

func (*Render) Serve

func (r *Render) Serve(ctx *faygo.Context) error
type Search int

func (Search) Doc

func (Search) Doc() faygo.Doc

func (Search) Serve

func (Search) Serve(ctx *faygo.Context) error

Jump to

Keyboard shortcuts

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