-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitem.go
57 lines (43 loc) · 904 Bytes
/
item.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package cosy
import (
"github.com/uozi-tech/cosy/model"
"net/http"
)
func (c *Ctx[T]) Get() {
if c.abort {
return
}
c.ID = c.GetParamID()
if c.beforeExecuteHook() {
return
}
data := new(T)
db := model.UseDB()
db = c.applyGormScopes(db)
if c.table != "" {
db = db.Table(c.table)
}
c.handleTable()
db = c.resolvePreload(db)
db = c.resolveJoins(db)
// scan into custom struct
if c.scan != nil {
c.JSON(http.StatusOK, c.scan(db))
return
}
err := db.First(&data, c.ID).Error
if err != nil {
errHandler(c.Context, err)
return
}
if c.executedHook() {
return
}
// no transformer
if c.transformer == nil {
c.JSON(http.StatusOK, data)
return
}
// use transformer
c.JSON(http.StatusOK, c.transformer(data))
}