Skip to content

Commit

Permalink
manual: todo
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Mar 8, 2024
1 parent c6a8b5c commit 60b65cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gop get github.com/goplus/yap@latest

For more details, see [YAP Framework Manual](doc/manual.md).


### How to use in Go+

First let us initialize a hello project:
Expand Down Expand Up @@ -88,7 +89,7 @@ yap "article", {
```


### Run at specified address
#### Run at specified address

By default the YAP server runs on `localhost:8080`, but you can change it in [main.yap](demo/classfile2_blog/main.yap) file:

Expand Down
2 changes: 1 addition & 1 deletion demo/hello/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
})
})
y.Handle("/", func(ctx *yap.Context) {
ctx.TEXT(200, "text/html", `<html><body>Hello, <a href="/p/123">Yap</a>!</body></html>`)
ctx.TEXT(200, "text/html", `<html><body>Hello, <a href="/p/123">YAP</a>!</body></html>`)
})
y.Run(":8080")
}
20 changes: 11 additions & 9 deletions doc/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ yap - Yet Another Go/Go+ HTTP Web Framework

This repo contains three [Go+ classfiles](https://github.com/goplus/gop/blob/main/doc/classfile.md): `yap` (a HTTP Web Framework), `yaptest` (a HTTP Test Framework) and `ydb` (a Go+ Database Framework).

The classfile `yap` has the file suffix `_yap.gox`. The classfile `yaptest` has the file suffix `_ytest.gox`. And the classfile `ydb` has the file suffix `_ydb.gox`.
The classfile `yap` has the file suffix `.yap`. The classfile `yaptest` has the file suffix `_ytest.gox`. And the classfile `ydb` has the file suffix `_ydb.gox`.

Before using `yap`, `yaptest` or `ydb`, you need to add `github.com/goplus/yap` to `go.mod`:

```sh
gop get github.com/goplus/yap@latest
```


### Router and Parameters

demo in Go ([hello.go](../demo/hello/hello.go)):
Expand All @@ -19,32 +20,33 @@ demo in Go ([hello.go](../demo/hello/hello.go)):
import "github.com/goplus/yap"

y := yap.New()
y.GET("/", func(ctx *yap.Context) {
ctx.TEXT(200, "text/html", `<html><body>Hello, <a href="/p/123">YAP</a>!</body></html>`)
})
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](../demo/classfile_hello/hello_yap.gox)):
demo in Go+ classfile ([main.yap](../demo/classfile_hello/main.yap)):

```go
get "/", ctx => {
ctx.html `<html><body>Hello, <a href="/p/123">YAP</a>!</body></html>`
}
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"
run "localhost:8080"
```


### Static files

Static files server demo in Go:
Expand Down

0 comments on commit 60b65cd

Please sign in to comment.