Skip to content

v0.5.0

Compare
Choose a tag to compare
@xushiwei xushiwei released this 07 Jan 19:22
· 265 commits to main since this release
1b292f3

features:

  • yap classfile (#6 #9)
  • yap classfile demo (#10)

changes:

  • gop.mod refector (#7)
  • initYapFS bugfix: checking exists (#8)

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"

YAP Template

demo in Go (blog.go, article.yap):

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):

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

run ":8080"