Skip to content

Commit

Permalink
yap doc
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jan 8, 2024
1 parent 2cd203d commit 2acf4f7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# vendor/

# Go workspace file
go.work
go.work*
76 changes: 36 additions & 40 deletions classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ const (
GopPackage = true
)

type Apper interface {
initApp()
}

type App struct {
*Engine
}
Expand Down Expand Up @@ -85,7 +81,7 @@ func (p App) Run__1(addr string, mws ...func(h http.Handler) http.Handler) {
}

// Gopt_App_Main is required by Go+ compiler as the entry of a YAP project.
func Gopt_App_Main(app Apper) {
func Gopt_App_Main(app interface{ initApp() }) {
app.initApp()
app.(interface{ MainEntry() }).MainEntry()
}
Expand All @@ -96,82 +92,82 @@ const (
mimeBinary = "application/octet-stream"
)

func (p *Context) Text__0(code int, mime string, text string) {
func (p *Context) Text__0(text string) {
p.TEXT(200, mimeText, text)
}

func (p *Context) Text__1(text []byte) {
p.DATA(200, mimeText, text)
}

func (p *Context) Text__2(code int, mime string, text string) {
p.TEXT(code, mime, text)
}

func (p *Context) Text__1(code int, text string) {
func (p *Context) Text__3(code int, text string) {
p.TEXT(code, mimeText, text)
}

func (p *Context) Text__2(text string) {
p.TEXT(200, mimeText, text)
func (p *Context) Text__4(code int, text []byte) {
p.DATA(code, mimeText, text)
}

func (p *Context) Text__3(code int, text []byte) {
p.DATA(code, mimeText, text)
func (p *Context) Binary__0(data []byte) {
p.DATA(200, mimeBinary, data)
}

func (p *Context) Text__4(text []byte) {
p.DATA(200, mimeText, text)
func (p *Context) Binary__1(data string) {
p.TEXT(200, mimeBinary, data)
}

func (p *Context) Binary__0(code int, mime string, data []byte) {
func (p *Context) Binary__2(code int, mime string, data []byte) {
p.DATA(code, mime, data)
}

func (p *Context) Binary__1(code int, data []byte) {
func (p *Context) Binary__3(code int, data []byte) {
p.DATA(code, mimeBinary, data)
}

func (p *Context) Binary__2(data []byte) {
p.DATA(200, mimeBinary, data)
}

func (p *Context) Binary__3(code int, data string) {
func (p *Context) Binary__4(code int, data string) {
p.TEXT(code, mimeBinary, data)
}

func (p *Context) Binary__4(data string) {
p.TEXT(200, mimeBinary, data)
func (p *Context) Html__0(text string) {
p.TEXT(200, mimeHtml, text)
}

func (p *Context) Html__0(code int, text string) {
p.TEXT(code, mimeHtml, text)
func (p *Context) Html__1(text []byte) {
p.DATA(200, mimeHtml, text)
}

func (p *Context) Html__1(text string) {
p.TEXT(200, mimeHtml, text)
func (p *Context) Html__2(code int, text string) {
p.TEXT(code, mimeHtml, text)
}

func (p *Context) Html__2(code int, text []byte) {
func (p *Context) Html__3(code int, text []byte) {
p.DATA(code, mimeHtml, text)
}

func (p *Context) Html__3(text []byte) {
p.DATA(200, mimeHtml, text)
func (p *Context) Json__0(data interface{}) {
p.JSON(200, data)
}

func (p *Context) Json__0(code int, data interface{}) {
func (p *Context) Json__1(code int, data interface{}) {
p.JSON(code, data)
}

func (p *Context) Json__1(data interface{}) {
p.JSON(200, data)
func (p *Context) PrettyJson__0(data interface{}) {
p.PrettyJSON(200, data)
}

func (p *Context) PrettyJson__0(code int, data interface{}) {
func (p *Context) PrettyJson__1(code int, data interface{}) {
p.PrettyJSON(code, data)
}

func (p *Context) PrettyJson__1(data interface{}) {
p.PrettyJSON(200, data)
func (p *Context) Yap__0(yapFile string, data interface{}) {
p.YAP(200, yapFile, data)
}

func (p *Context) Yap__0(code int, yapFile string, data interface{}) {
func (p *Context) Yap__1(code int, yapFile string, data interface{}) {
p.YAP(code, yapFile, data)
}

func (p *Context) Yap__1(yapFile string, data interface{}) {
p.YAP(200, yapFile, data)
}
10 changes: 10 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func acceptNext(accept string) (item, left string) {
return
}

// TEXT replies the HTTP request with code as status,
// mime as Content-Type and text as response body.
func (p *Context) TEXT(code int, mime string, text string) {
w := p.ResponseWriter
h := w.Header()
Expand All @@ -97,6 +99,8 @@ func (p *Context) TEXT(code int, mime string, text string) {
io.WriteString(w, text)
}

// DATA replies the HTTP request with code as status,
// mime as Content-Type and data as response body.
func (p *Context) DATA(code int, mime string, data []byte) {
w := p.ResponseWriter
h := w.Header()
Expand All @@ -106,6 +110,8 @@ func (p *Context) DATA(code int, mime string, data []byte) {
w.Write(data)
}

// PrettyJSON converts any interface to JSON (in pretty mode).
// It also sets the Content-Type as "application/json".
func (p *Context) PrettyJSON(code int, data interface{}) {
msg, err := json.MarshalIndent(data, "", " ")
if err != nil {
Expand All @@ -114,6 +120,8 @@ func (p *Context) PrettyJSON(code int, data interface{}) {
p.DATA(code, "application/json", msg)
}

// JSON converts any interface to JSON.
// It also sets the Content-Type as "application/json".
func (p *Context) JSON(code int, data interface{}) {
msg, err := json.Marshal(data)
if err != nil {
Expand All @@ -122,6 +130,8 @@ func (p *Context) JSON(code int, data interface{}) {
p.DATA(code, "application/json", msg)
}

// YAP uses a YAP template to convert any interface to HTML.
// It also sets the Content-Type as "text/html".
func (p *Context) YAP(code int, yapFile string, data interface{}) {
w := p.ResponseWriter
t, err := p.engine.templ(yapFile)
Expand Down
2 changes: 1 addition & 1 deletion demo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ go 1.18

require github.com/goplus/yap v0.6.0 //gop:class

replace github.com/goplus/yap => ../
// replace github.com/goplus/yap => ../

0 comments on commit 2acf4f7

Please sign in to comment.