Closed zhihuba closed 9 hours ago
github.com/quarkcloudio/quark-go/v2/pkg/ 引入v2 版本的
github.com/quarkcloudio/quark-go/v3/pkg
github.com/quarkcms/quark-go/pkg/app
相关代码 provider.go
package service import ( "github.com/quarkcloudio/quark-go/v2/pkg/app/admin/service/dashboards" "github.com/quarkcloudio/quark-go/v2/pkg/app/admin/service/layouts" "github.com/quarkcloudio/quark-go/v2/pkg/app/admin/service/logins" "github.com/quarkcloudio/quark-go/v2/pkg/app/admin/service/resources" "web_app/app/admin/service/resource" ) // 注册服务 var Providers = []interface{}{ &logins.Index{}, &layouts.Index{}, &dashboards.Index{}, &resources.User{}, &resources.Admin{}, &resources.Role{}, &resources.Permission{}, &resources.Menu{}, &resources.ActionLog{}, &resources.Config{}, &resources.File{}, &resources.Picture{}, &resources.WebConfig{}, &resources.Account{}, &resource.DataManager{}, }
resource/DataManager.go
package resource import ( "github.com/quarkcloudio/quark-go/v2/pkg/app/admin/component/form/rule" "github.com/quarkcloudio/quark-go/v2/pkg/app/admin/service/actions" "github.com/quarkcloudio/quark-go/v2/pkg/app/admin/template/resource" "github.com/quarkcloudio/quark-go/v2/pkg/builder" "gorm.io/gorm" "web_app/app/admin/service/search/mg_domain" "web_app/app/model" ) //数据管理页面 type DataManager struct { resource.Template } // 初始化 func (p *DataManager) Init(ctx *builder.Context) interface{} { //标题 p.Title = "根域名管理" //展示页面的标题 //模型 p.Model = &model.DataMgDomain{} //分页 p.PerPage = 10 return p } // 只查询Domain类型 func (p *DataManager) Query(ctx *builder.Context, query *gorm.DB) *gorm.DB { return query.Where("domina IS NOT NULL") } // Fields 用于新增数据表单 func (p *DataManager) Fields(ctx *builder.Context) []interface{} { field := &resource.Field{} return []interface{}{ field.Editor("Domain", "域名列表").OnlyOnForms(). SetRules([]*rule.Rule{ rule.Required(true, "域名不能为空"), }), } } // Searches 搜索方法 func (p *DataManager) Searches(ctx *builder.Context) []interface{} { return []interface{}{ mg_domain.Input("domain", "Domain"), mg_domain.DatetimeRange("addTime", "创建时间"), } } // 行为 func (p *DataManager) Actions(ctx *builder.Context) []interface{} { return []interface{}{ actions.CreateLink(), actions.BatchDelete(), actions.BatchDisable(), actions.BatchEnable(), actions.EditLink(), actions.Delete(), actions.FormSubmit(), actions.FormReset(), actions.FormBack(), actions.FormExtraBack(), } }
model/data_domain.go
package model import ( "github.com/quarkcloudio/quark-go/v2/pkg/app/admin/model" "github.com/quarkcloudio/quark-go/v2/pkg/dal/db" "time" ) // 定义根域名数据 type DataMgDomain struct { ID int `gorm:"primaryKey;autoIncrement;comment:主键ID"` // 主键,自增 Domain string `gorm:"type:varchar(255);unique;not null;comment:唯一的不为空字段"` // 唯一且不为空的字符串字段 Tdl string `gorm:"type:varchar(255);not null;comment:顶级域名"` // 不为空的字符串字段 AddTime time.Time `gorm:"not null;comment:添加时间"` // 不为空的时间字段 ErrorCount int `gorm:"default:0;comment:错误次数"` } // Seeder func (m *DataMgDomain) Seeder() { // 如果菜单已存在,不执行Seeder操作 if (&model.Menu{}).IsExist(1000) { return } // 创建菜单 menuSeeders := []*model.Menu{ {Id: 1000, Name: "数据管理", GuardName: "admin", Icon: "icon-read", Type: 1, Pid: 0, Sort: 0, Path: "/data_mg_domain", Show: 1, IsEngine: 0, IsLink: 0, Status: 1}, {Id: 1001, Name: "根域名管理", GuardName: "admin", Icon: "", Type: 2, Pid: 1000, Sort: 0, Path: "/api/admin/data_mg_domain/index", Show: 1, IsEngine: 1, IsLink: 0, Status: 1}, } db.Client.Create(&menuSeeders) // 创建默认内容 seeders := []DataMgDomain{ {Domain: "www.baidu.com", Tdl: "com", AddTime: time.Now(), ErrorCount: 0}, {Domain: "www.google.com", Tdl: "com", AddTime: time.Now(), ErrorCount: 0}, {Domain: "www.bing.com", Tdl: "com", AddTime: time.Now(), ErrorCount: 0}, } db.Client.Create(&seeders) }
部分日志
[GIN-debug] GET /api/admin/login/:resource/index --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] POST /api/admin/login/:resource/handle --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func4 (4 handlers) [GIN-debug] GET /api/admin/login/:resource/captchaId --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/login/:resource/captcha/:id --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/logout/:resource/handle --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/layout/:resource/index --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/dashboard/:resource/index --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/:resource/index --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/:resource/editable --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] POST /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] PUT /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] PATCH /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] HEAD /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] OPTIONS /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] DELETE /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] CONNECT /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] TRACE /api/admin/:resource/action/:uriKey --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] GET /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] POST /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] PUT /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] PATCH /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] HEAD /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] OPTIONS /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] DELETE /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] CONNECT /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] TRACE /api/admin/:resource/action/:uriKey/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func8 (4 handlers) [GIN-debug] GET /api/admin/:resource/create --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] POST /api/admin/:resource/store --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func4 (4 handlers) [GIN-debug] GET /api/admin/:resource/edit --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/:resource/edit/values --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] POST /api/admin/:resource/save --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func4 (4 handlers) [GIN-debug] GET /api/admin/:resource/detail --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/:resource/export --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] POST /api/admin/:resource/import --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func4 (4 handlers) [GIN-debug] GET /api/admin/:resource/import/template --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/:resource/setting/form --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] GET /api/admin/:resource/:uriKey/form --> github.com/quarkcloudio/quark-go/v2/pkg/adapter/ginadapter.Adapter.func1 (4 handlers) [GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value. Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details. [GIN-debug] Listening and serving HTTP on :3001 [GIN] 2024/11/07 - 01:59:11 | 200 | 9.46ms | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index" [GIN] 2024/11/07 - 01:59:11 | 200 | 0s | 127.0.0.1 | GET "/api/admin/data_mg_domain/index"
抱歉,v3的文档还未更新
文档重新更新了一下
举例说明
https://quarkcloud.io/quark-go/resources.html 在官方文档中引入包如下
在quark-smart 示例中又引入v3
在 issues 实例项目中又引入其他的 https://github.com/quarkcloudio/quark-cron/blob/main/model/job.go
所以我到底要用那个?他们有什么区别。最主要是我按照文档创建了一个菜单页面。当我访问的时候会一直请求
相关代码 provider.go
resource/DataManager.go
model/data_domain.go
部分日志