Skip to content

Releases: goplus/yap

v0.8.1

15 Apr 13:29
8b1dde6
Compare
Choose a tag to compare

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

10 Mar 16:30
d7f3fca
Compare
Choose a tag to compare

features:

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

16 Feb 00:50
804e905
Compare
Choose a tag to compare

feature:

  • ydb: new classfile style (#83)
  • ydb: support lastErr; callRet: allow omit nil error (#84)

changes:

  • remove //line for main func (#86)
  • rm ast.Node (#87)
  • autogen doc (#88)

v0.7.5

13 Feb 04:57
dca35d9
Compare
Choose a tag to compare

features:

changes:

  • rename _yunit.gox => _yapt.gox (#35)

v0.7.2

28 Jan 15:06
b9994a6
Compare
Choose a tag to compare

features:

  • classfile: yap test (#30 #32)
  • yap with x/http/fsx (#27 #28)

demo:

v0.7.1

19 Jan 16:38
faea65d
Compare
Choose a tag to compare

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"

v0.6.0

08 Jan 09:43
d4e8dde
Compare
Choose a tag to compare

incompatible changes:

  • rename yap template files: xxx.yap => xxx_yap.html (#11 #12)

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

07 Jan 19:22
1b292f3
Compare
Choose a tag to compare

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"

v0.3.0

06 Jan 15:05
245cfb0
Compare
Choose a tag to compare

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

06 Jan 14:23
b2406da
Compare
Choose a tag to compare

features:

  • router (#4)
  • request params (#4)

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