Skip to content
/ yap Public
forked from goplus/yap

Yet Another Go/Go+ HTTP Web Framework

License

Notifications You must be signed in to change notification settings

wu-jj/yap

 
 

Repository files navigation

yap - Yet Another Go/Go+ HTTP Web Framework

Build Status Go Report Card GitHub release Coverage Status GoDoc

Router and Parameters

demo in Go (hello.go):

import "github.com/goplus/yap"

y := yap.New()
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):

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"

Static files

Static files server demo in Go:

y := yap.New(os.DirFS("."))
y.Static("/foo", y.FS("public"))
y.Static("/") // means: y.Static("/", y.FS("static"))
y.Run(":8888")

Static files server demo in Go+ classfile (staticfile_yap.gox):

static "/foo", FS("public")
static "/"
run ":8888"

Static files server also can use a http.FileSystem instead of fs.FS object (See yapserve for details):

import "github.com/qiniu/x/http/fs"

static "/", fs.http("https://goplus.org"), false // false means not allow to redirect
run ":8888"

YAP Template

demo in Go (blog.go, article_yap.html):

import (
	"os"

	"github.com/goplus/yap"
)

y := yap.New(os.DirFS("."))

y.GET("/p/:id", func(ctx *yap.Context) {
	ctx.YAP(200, "article", yap.H{
		"id": ctx.Param("id"),
	})
})

y.Run(":8080")

demo in Go+ classfile (blog_yap.gox, article_yap.html):

get "/p/:id", ctx => {
	ctx.yap "article", {
		"id": ctx.param("id"),
	}
}

run ":8080"

About

Yet Another Go/Go+ HTTP Web Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%