Skip to content

v0.7.1

Compare
Choose a tag to compare
@xushiwei xushiwei released this 19 Jan 16:38
· 241 commits to main since this release
faea65d

features:

  • ctx.Redirect (#17)
  • static files (#23 #24)
  • static: support http filesystem (#26)
  • TODO: yaptest (#22)

changes:

Router and Parameters

demo in Go (hello.go):

import "github.com/goplus/yap"

y := yap.New()
y.GET("/p/:id", func(ctx *yap.Context) {
	ctx.JSON(200, yap.H{
		"id": ctx.Param("id"),
	})
})
y.Handle("/", func(ctx *yap.Context) {
	ctx.TEXT(200, "text/html", `<html><body>Hello, <a href="/p/123">Yap</a>!</body></html>`)
})
y.Run(":8080")

demo in Go+ classfile (hello_yap.gox):

get "/p/:id", ctx => {
	ctx.json {
		"id": ctx.param("id"),
	}
}
handle "/", ctx => {
	ctx.html `<html><body>Hello, <a href="/p/123">Yap</a>!</body></html>`
}

run ":8080"

Static files

Static files server demo in Go:

y := yap.New(os.DirFS("."))
y.Static("/foo", y.FS("public"))
y.Static("/") // means: y.Static("/", y.FS("static"))
y.Run(":8888")

Static files server demo in Go+ classfile (staticfile_yap.gox):

static "/foo", FS("public")
static "/"
run ":8888"

YAP Template

demo in Go (blog.go, article_yap.html):

import (
	"os"

	"github.com/goplus/yap"
)

y := yap.New(os.DirFS("."))

y.GET("/p/:id", func(ctx *yap.Context) {
	ctx.YAP(200, "article", yap.H{
		"id": ctx.Param("id"),
	})
})

y.Run(":8080")

demo in Go+ classfile (blog_yap.gox, article_yap.html):

get "/p/:id", ctx => {
	ctx.yap "article", {
		"id": ctx.param("id"),
	}
}

run ":8080"