mirror of https://github.com/veypi/OneAuth.git
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.
27 lines
611 B
Go
27 lines
611 B
Go
package resource
|
|
|
|
import (
|
|
"github.com/veypi/OneBD/rest"
|
|
"github.com/veypi/OneAuth/cfg"
|
|
"github.com/veypi/OneAuth/models"
|
|
)
|
|
|
|
var _ = Router.Get("/:resource_id", getResource)
|
|
|
|
func getResource(x *rest.X) (any, error) {
|
|
// 获取路径参数
|
|
resourceID := x.Params.Get("resource_id")
|
|
if resourceID == "" {
|
|
return nil, rest.NewError("resource_id is required").WithCode(400)
|
|
}
|
|
|
|
// 查询数据库
|
|
resource := &models.Resource{}
|
|
err := cfg.DB().Where("id = ?", resourceID).First(resource).Error
|
|
if err != nil {
|
|
return nil, rest.NewError("resource not found").WithCode(404)
|
|
}
|
|
|
|
return resource, nil
|
|
}
|