Skip to content

v1.2.5

Compare
Choose a tag to compare
@xushiwei xushiwei released this 09 Mar 15:05
· 90 commits to v1.2 since this release
f6596aa

highlights:

  • operator ${name}: You can customize the semantics of ${name}. For example, in .gsh classfile, ${name} means os.Getenv("<name>"), and in .yap classfile, ${name} means ctx.Param("<name>").
  • The web framework YAP released v0.8.0. It introduces YAP classfile v2 which is particularly simple and easy to use. See blow for details.

features:

  • classfile: generate gameClass.Main() (#1814)
  • classfile: this.Sprite.Main(...) or this.Game.MainEntry(...) (#1794)
  • classfile: this.Classfname() (#1794 #1797)
  • classfile: gsh exec (#1757)
  • cl: ${name} - operator Gop_Env (#1776 #1806 #1810)
  • cl: binaryOp ->, <> (#1763 #1764 #1766)
  • cl: compileCompositeLit: support type-inter for map (#1756)
  • cl: rec.Scope - record types scope (#1759 #1767 #1772 #1774)
  • cl: types record check selection/index expr is addressable (#1785 #1788)
  • cl: don't define GopPackage for main package (#1796)
  • cl: astFnClassfname, astEmptyEntrypoint (#1811 #1812)
  • format interface{}: rm newline (#1761 #1769 #1791)
  • x/typesutil: add conf.IgnoreFuncBodies (#1783)
  • x/typesutil: add conf.UpdateGoTypesOverload (#1793)
  • qiniu/x/stringutil (#1777 #1778 #1779)

ci/cd tools:

  • check goreleaser file lists (#1802)
  • ci: compatible with version difference of patch release (#1804 #1808)

changes:

  • rename github.com/goplus/gox => github.com/goplus/gogen (#1798)
  • cl: inMainPkg (#1789)
  • cl: isGoxTestFile (#1790)
  • cl: for..range body use vblock for new scope (#1760)
  • cl: gogen new api case/typeCase/commCase (#1762)
  • cl: commentStmt: fix ast.GenDecl pos (#1768)
  • cl: commentStmt: skip noPos (#1794)
  • cl: TestErrStringLit (#1799)
  • parser: fix StringLit extra check (#1782)
  • ast: walk add *IndexListExpr (#1773)
  • ast: fix forPhrase.end (#1775)
  • x/typesutil: check for need goinfo (#1784)
  • x/typesutil: TestTypeAndValue, TestConvErr (#1800)
  • mod: github.com/goplus/c2go v0.7.25
  • mod: github.com/goplus/gogen v1.15.1
  • mod: github.com/goplus/mod v0.13.9
  • mod: github.com/qiniu/x v1.13.9
  • mod: golang.org/x/tools v0.19.0

YAP released v0.8.0. It introducesYAP classfile v2 which is particularly simple and easy to use. Let’s compare YAP in Go, YAP classfile v1 and YAP classfile v2.

Router and Parameters

demo in Go (hello.go):

import "github.com/goplus/yap"

func main() {
	y := yap.New()
	y.GET("/", func(ctx *yap.Context) {
		ctx.TEXT(200, "text/html", `<html><body>Hello, YAP!</body></html>`)
	})
	y.GET("/p/:id", func(ctx *yap.Context) {
		ctx.JSON(200, yap.H{
			"id": ctx.Param("id"),
		})
	})
	y.Run("localhost:8080")
}

demo in YAP classfile v1 (main.yap):

get "/", ctx => {
	ctx.html `<html><body>Hello, YAP!</body></html>`
}
get "/p/:id", ctx => {
	ctx.json {
		"id": ctx.param("id"),
	}
}

run "localhost:8080"

demo in YAP classfile v2 (get.yap, get_p_#id.yap):

html `<html><body>Hello, YAP!</body></html>`
json {
	"id": ${id},
}

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 YAP classfile v1 (main.yap, article_yap.html):

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

run ":8888"

demo in YAP classfile v2 (get_p_#id.yap, article_yap.html):

yap "article", {
	"id": ${id},
}

See yap: Yet Another HTTP Web Framework for more details.