github.com/goplus/yap@v0.8.1/demo/blog_emb/blog.go (about)

     1  package main
     2  
     3  import (
     4  	"embed"
     5  	"io/fs"
     6  
     7  	"github.com/goplus/yap"
     8  )
     9  
    10  type article struct {
    11  	ID string
    12  }
    13  
    14  //go:embed yap
    15  var yapFS embed.FS
    16  
    17  func main() {
    18  	fsYap, _ := fs.Sub(yapFS, "yap")
    19  	y := yap.New(fsYap)
    20  
    21  	y.GET("/", func(ctx *yap.Context) {
    22  		ctx.TEXT(200, "text/html", `<html><body>Hello, <a href="/p/123">YAP</a>!</body></html>`)
    23  	})
    24  	y.GET("/p/:id", func(ctx *yap.Context) {
    25  		ctx.YAP(200, "article", article{
    26  			ID: ctx.Param("id"),
    27  		})
    28  	})
    29  
    30  	y.Run(":8080")
    31  }