基于 Gin 的 Go (风格)轻量高效的前端组件化 web 框架,这是一项正在完善的工作
Ego 是一个用 Go 编写的全栈 Web 框架,轻量级和高效的前端组件解决方案
前端编译执行,不影响后端效率
项目地址: https://github.com/go-ego/ego
安装:
```
go get -u github.com/go-ego/ego
```
例子: https://github.com/go-ego/ego/tree/master/examples/ego
路由
```go
package main
import (
"github.com/go-ego/ego"
)
func main() {
router := ego.Classic()
ego.UseRenders()
router.GlobHTML("views/html/*")
parArr := [5]int{1, 2, 3, 4, 5}
router.EgoRouter("/head/", "head/head.html", ego.Map{
"head": "Test to load the HTML template",
"parArr": parArr,
})
router.Run(":3100")
}
```
icon.vgo
```html
<div class="icon">
<i class="iconfont {vclass}" {node}></i>
<p>{prpo}</p>
</div>
<style>
.header-left{
float:left;
}
.header-right{
float:right;
}
.iconfont {
position: relative;
font-size:24px
}
</style>
```
head.vgo
```
import (
"icons"
icon "icons/icon.vgo"
)
<div class="head">
<div>ego:{{.head}}</div>
<icon>
vclass={icon-share-to}
node={ id="slot1"}
prpo={node---1}
</icon>
<div>
{{range .parArr}}
<p>arr::: {{.}}</p>
{{end}}
</div>
</div>
```
效果图:
https://github.com/go-ego/ego/blob/master/img/head.png
另外写了一个Json预览和测试页面:
```Go
package main
import (
"github.com/go-ego/ego"
)
const httpUrl string = "http://127.0.0.1:3000"
func main() {
router := ego.Classic()
router.Static("/js", "./views/js")
router.Static("/src", "./views/src")
router.GlobHTML("views/html/*")
strUrl := httpUrl + "/test/hlist"
paramMap := ego.Map{
"lon": "10.1010101",
"lat": "20.202020",
"type": "1",
}
router.TestHtml(strUrl, paramMap)
router.Run(":3100")
}
```
效果图:
https://github.com/go-ego/ego/blob/master/img/test.png
有疑问加站长微信联系(非本文作者)