https://github.com/iotames/glayui
LayUI的Go语言封装,作为组件库和简易的Web框架,开箱即用。
https://github.com/iotames/glayui
Last synced: 6 months ago
JSON representation
LayUI的Go语言封装,作为组件库和简易的Web框架,开箱即用。
- Host: GitHub
- URL: https://github.com/iotames/glayui
- Owner: iotames
- Created: 2023-10-23T09:45:15.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-08T09:26:54.000Z (over 2 years ago)
- Last Synced: 2024-06-21T20:08:04.654Z (about 2 years ago)
- Language: HTML
- Size: 887 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 快速开始
```
# 新建项目文件夹并进入
mkdir myproject
cd myproject/
# 下载glayui资源包,路径为 ./glayui/resource
git clone https://github.com/iotames/glayui.git
# 启用 workspace(>= go1.18) 模式,添加glayui目录
go work init glayui
#
```
编辑入口文件 `main.go`:
```
package main
import (
"fmt"
"io"
"github.com/iotames/glayui/component"
"github.com/iotames/glayui/gtpl"
"github.com/iotames/glayui/web"
)
func main() {
tpl := gtpl.GetTpl()
tpl.SetResourceDirPath("glayui/resource")
s := web.NewEasyServer(":1598")
s.AddHandler("POST", "/login", func(ctx web.Context) {
postdata, _ := io.ReadAll(ctx.Request.Body)
fmt.Printf("---postdata(%s)---\n", string(postdata))
ctx.Writer.Header().Set("Content-Type", "application/json")
ctx.Writer.Write([]byte(`{"msg":"登录成功","status":200}`))
})
s.AddHandler("POST", "/sendsms", func(ctx web.Context) {
postdata, _ := io.ReadAll(ctx.Request.Body)
fmt.Printf("---postdata(%s)---\n", string(postdata))
ctx.Writer.Header().Set("Content-Type", "application/json")
ctx.Writer.Write([]byte(`{"msg":"发送成功","status":200}`))
})
s.AddHandler("GET", "/login", func(ctx web.Context) {
fm := ctx.NewForm().SetTitle("用户登录").SetSubmitButton(component.Button{Text: "登录"})
fm.SetSubmitUrl("/login")
fm.AddFormItem(component.NewMobileInputItemForSendMsg("cellphone", "手机号", "/sendsms"))
fm.AddFormItem(component.NewTextInputItem("smscode", "验证码"))
fm.Exec(ctx.Writer)
})
// 访问 http://127.0.0.1:1598/login
s.ListenAndServe()
}
```