From e3a754d4d24ef4e06c0c5cefe1c56d9d060c8587 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 6 Jan 2024 23:02:07 +0800 Subject: [PATCH] demo: blog --- README.md | 31 +++++++++++++++++++++++++++++++ demo/blog/blog.go | 28 ++++++++++++++++++++++++++++ demo/blog/yap/article.yap | 8 ++++++++ 3 files changed, 67 insertions(+) create mode 100644 demo/blog/blog.go create mode 100644 demo/blog/yap/article.yap diff --git a/README.md b/README.md index 6646593..6aaa428 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,34 @@ y.Handle("/", func(ctx *yap.Context) { }) y.Run(":8080") ``` + +### YAP Template + +demo ([blog.go](demo/blog/blog.go)): + +```go +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") +``` diff --git a/demo/blog/blog.go b/demo/blog/blog.go new file mode 100644 index 0000000..d58c762 --- /dev/null +++ b/demo/blog/blog.go @@ -0,0 +1,28 @@ +package main + +import ( + "embed" + "io/fs" + + "github.com/goplus/yap" +) + +type article struct { + ID string +} + +//go:embed yap +var yapFS embed.FS + +func main() { + 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") +} diff --git a/demo/blog/yap/article.yap b/demo/blog/yap/article.yap new file mode 100644 index 0000000..6b0bd8f --- /dev/null +++ b/demo/blog/yap/article.yap @@ -0,0 +1,8 @@ + + + + + +Article {{.ID}} + +