diff --git a/README.md b/README.md index 4a37b144..d72165c2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Go+ Community +Go+ Community written in Go+ ===== [![Build Status](https://github.com/goplus/community/actions/workflows/go.yml/badge.svg)](https://github.com/goplus/community/actions/workflows/go.yml) diff --git a/cmd/gopcomm/community.gop b/cmd/gopcomm/community.gop index aa9b94d0..666470d6 100644 --- a/cmd/gopcomm/community.gop +++ b/cmd/gopcomm/community.gop @@ -11,5 +11,10 @@ var yapFS embed.FS fsYap := fs.sub(yapFS, "yap")! y := yap.new(fsYap) -y.handle "/p/", ctx => { +y.GET "/p/:id", ctx => { + ctx.YAP 200, "article", yap.H{ + "id": ctx.param("id"), + } } + +y.run ":8080" diff --git a/cmd/gopcomm/gop_autogen.go b/cmd/gopcomm/gop_autogen.go index a1af593d..0a73fdd5 100644 --- a/cmd/gopcomm/gop_autogen.go +++ b/cmd/gopcomm/gop_autogen.go @@ -6,7 +6,7 @@ import ( "github.com/goplus/yap" "github.com/qiniu/x/errors" ) - +//go:embed yap var yapFS embed.FS //line cmd/gopcomm/community.gop:11 func main() { @@ -29,6 +29,10 @@ func main() { //line cmd/gopcomm/community.gop:12:1 y := yap.New(fsYap) //line cmd/gopcomm/community.gop:14:1 - y.Handle("/p/", func(ctx *yap.Context) { + y.GET("/p/:id", func(ctx *yap.Context) { +//line cmd/gopcomm/community.gop:15:1 + ctx.YAP(200, "article", yap.H{"id": ctx.Param("id")}) }) +//line cmd/gopcomm/community.gop:20:1 + y.Run(":8080") } diff --git a/cmd/gopcomm/yap/article.yap b/cmd/gopcomm/yap/article.yap new file mode 100644 index 00000000..118d8b68 --- /dev/null +++ b/cmd/gopcomm/yap/article.yap @@ -0,0 +1,8 @@ + + + + + +Article {{.id}} + + diff --git a/go.mod b/go.mod index 677dd7cd..5915f8ff 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/goplus/community go 1.18 require ( - github.com/goplus/yap v0.1.0 - github.com/qiniu/x v1.13.2 + github.com/goplus/yap v0.2.0 + github.com/qiniu/x v1.13.2 ) diff --git a/go.sum b/go.sum index 042a596d..eb4e66f4 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/goplus/yap v0.1.0 h1:POiEaS0ZlHPOo6Vw8guq+i9sOUfzF3ZHiSmK0NC+9I8= -github.com/goplus/yap v0.1.0/go.mod h1:VCbGlZo2lUgRWciTZwA5JEOuCUf8T2PhxZZ0HXqzgBk= +github.com/goplus/yap v0.2.0 h1:0RLQBxBOiUxKb+9AY/yhYtlnQKjfPyaOhDv720S1Izk= +github.com/goplus/yap v0.2.0/go.mod h1:VCbGlZo2lUgRWciTZwA5JEOuCUf8T2PhxZZ0HXqzgBk= github.com/qiniu/x v1.13.2 h1:mgWOfB9Rpk6AEtlBoObZVxH+b2FHSntYrxc4KX5Ta98= github.com/qiniu/x v1.13.2/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=