-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from xushiwei/blog
classfile demo
- Loading branch information
Showing
7 changed files
with
109 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ | |
<meta charset="utf-8"/> | ||
</head> | ||
<body> | ||
Article {{.ID}} | ||
Article {{.id}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import "github.com/goplus/yap" | ||
|
||
type hello_yap struct { | ||
yap.App | ||
} | ||
//line demo/classfile_hello/hello_yap.gox:1 | ||
func (this *hello_yap) MainEntry() { | ||
//line demo/classfile_hello/hello_yap.gox:1:1 | ||
this.Get("/p/:id", func(ctx *yap.Context) { | ||
//line demo/classfile_hello/hello_yap.gox:2:1 | ||
ctx.Json__1(map[string]string{"id": ctx.Param("id")}) | ||
}) | ||
//line demo/classfile_hello/hello_yap.gox:6:1 | ||
this.Handle("/", func(ctx *yap.Context) { | ||
//line demo/classfile_hello/hello_yap.gox:7:1 | ||
ctx.Html__1(`<html><body>Hello, <a href="/p/123">Yap</a>!</body></html>`) | ||
}) | ||
//line demo/classfile_hello/hello_yap.gox:10:1 | ||
this.Run__1(":8080") | ||
} | ||
func main() { | ||
yap.Gopt_App_Main(new(hello_yap)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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" |