-
Notifications
You must be signed in to change notification settings - Fork 12
/
user.go
34 lines (28 loc) · 854 Bytes
/
user.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
package makeless_go
import (
"github.com/gin-gonic/gin"
"github.com/makeless/makeless-go/http"
"github.com/makeless/makeless-go/model"
h "net/http"
"sync"
)
func (makeless *Makeless) user(http makeless_go_http.Http) error {
http.GetRouter().GetEngine().GET(
"/api/auth/user",
http.GetAuthenticator().GetMiddleware().MiddlewareFunc(),
func(c *gin.Context) {
userId := http.GetAuthenticator().GetAuthUserId(c)
var err error
var user = &makeless_go_model.User{
Model: makeless_go_model.Model{Id: userId},
RWMutex: new(sync.RWMutex),
}
if user, err = http.GetDatabase().GetUser(http.GetDatabase().GetConnection().WithContext(c), user); err != nil {
c.AbortWithStatusJSON(h.StatusInternalServerError, http.Response(err, nil))
return
}
c.JSON(h.StatusOK, http.Response(nil, user))
},
)
return nil
}