Skip to content

Commit

Permalink
demo: blog
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jan 6, 2024
1 parent 4b43ca5 commit e3a754d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```
28 changes: 28 additions & 0 deletions demo/blog/blog.go
Original file line number Diff line number Diff line change
@@ -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")
}
8 changes: 8 additions & 0 deletions demo/blog/yap/article.yap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
Article {{.ID}}
</body>
</html>

0 comments on commit e3a754d

Please sign in to comment.