You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/api/app/resource/get.go

27 lines
607 B
Go

package resource
import (
"github.com/vyes-ai/vigo"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/models"
)
var _ = Router.Get("/:resource_id", getResource)
func getResource(x *vigo.X) (any, error) {
// 获取路径参数
resourceID := x.Params.Get("resource_id")
if resourceID == "" {
return nil, vigo.NewError("resource_id is required").WithCode(400)
}
// 查询数据库
resource := &models.Resource{}
err := cfg.DB().Where("id = ?", resourceID).First(resource).Error
if err != nil {
return nil, vigo.NewError("resource not found").WithCode(404)
}
return resource, nil
}