Releases: goplus/yap
v0.8.1
features:
- yap: nested templates (#49 #109)
- yap: support builtin http HEAD impl (#108)
- yap: http delete method (#111)
- ytest: match (#103)
- ytest: README (#103 #107 #110)
changes:
- yap classfile v2 fix: handler.AppV2 = app (#104)
- mod: github.com/go-sql-driver/mysql v1.8.1
- mod: github.com/qiniu/x v1.13.10
v0.8.0
features:
- yap: classfile v2 (#94)
- yap: ${name} - operator Gop_Env (#98 #100)
- ytest for YAP classfile v2 (#101 #102)
- yap doc (#89 #95 #96 #99)
- qiniu/x/stringutil (#90 #91)
changes:
- mod: github.com/golang-jwt/jwt/v5 v5.2.1
- mod: github.com/qiniu/x v1.13.9
Router and Parameters
Create a file named get.yap with the following content:
html `<html><body>Hello, YAP!</body></html>`
Execute the following commands:
gop mod init hello
gop get github.com/goplus/yap@latest
gop mod tidy
gop run .
A simplest web program is running now. At this time, if you visit http://localhost:8080, you will get:
Hello, YAP!
YAP uses filenames to define routes. get.yap
's route is get "/"
(GET homepage), and get_p_#id.yap
's route is get "/p/:id"
(In fact, the filename can also be get_p_:id.yap
, but it is not recommended because :
is not allowed to exist in filenames under Windows).
Let's create a file named get_p_#id.yap with the following content:
json {
"id": ${id},
}
Execute gop run .
and visit http://localhost:8080/p/123, you will get:
{"id": "123"}
YAP Template
In most cases, we don't use the html
directive to generate html pages, but use the yap
template engine. See get_p_#id.yap:
yap "article", {
"id": ${id},
}
It means finding a template called article
to render. See yap/article_yap.html:
<html>
<head><meta charset="utf-8"/></head>
<body>Article {{.id}}</body>
</html>
Run at specified address
By default the YAP server runs on localhost:8080
, but you can change it in main.yap file:
run ":8888"
v0.7.6
v0.7.5
features:
- yaptest: match (#42 #43)
- yaptest: authentication (#36 #41 #45 #47 #48)
- yaptest: head/put/options/patch (and delete?) (#37)
- yaptest: mock/testServer (#38 #39 #40)
- ydb: engine (#61 #66 #67 #76)
- ydb: table spec (#53 #54 #57)
- ydb: api call (#56 #63 #65 #70 #71)
- ydb: insert (#58 #59 #79)
- ydb: delete (#77 #78)
- ydb: query (#60)
- stringutil (#62 #78)
- yap/test (#55 #72 #73 #80 #82)
changes:
- rename
_yunit.gox
=>_yapt.gox
(#35)
v0.7.2
v0.7.1
features:
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"
v0.6.0
incompatible 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"
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"
v0.5.0
features:
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"
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"
v0.3.0
features:
- YAP template (#1)
demo (blog.go, article.yap):
import (
"embed"
"io/fs"
"github.com/goplus/yap"
)
type article struct {
ID string
}
//go:embed yap
var yapFS embed.FS
fsYap, _ := fs.Sub(yapFS, "yap")
y := yap.New(fsYap)
y.GET("/p/:id", func(ctx *yap.Context) {
ctx.YAP(200, "article", article{
ID: ctx.Param("id"),
})
})
y.Run(":8080")
v0.2.0
features:
demo (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")