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}} + +