package resource import ( "github.com/veypi/OneBD/rest" "github.com/veypi/OneAuth/cfg" "github.com/veypi/OneAuth/models" ) var _ = Router.Post("/", createResource) type createOpts struct { AppID string `json:"app_id" parse:"path"` Name string `json:"name" parse:"json"` Des string `json:"des" parse:"json"` } func createResource(x *rest.X) (any, error) { // 解析参数 opts := &createOpts{} if err := x.Parse(opts); err != nil { return nil, err } // 创建资源对象 resource := &models.Resource{ AppID: opts.AppID, Name: opts.Name, Des: opts.Des, } // 保存到数据库 if err := cfg.DB().Create(resource).Error; err != nil { return nil, rest.NewError("failed to create resource").WithCode(500) } return resource, nil }