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