forked from nerdzeu/nerdz-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.go
55 lines (46 loc) · 1.9 KB
/
middleware.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
/*
Copyright (C) 2016 Paolo Galeone <nessuno@nerdz.eu>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package me
import (
"github.com/labstack/echo"
"github.com/nerdzeu/nerdz-api/rest/user"
)
// SetOther is the middleware that sets the context variable "other" to "me"
// therfore we can use the package user methods in the me package
func SetOther() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return echo.HandlerFunc(func(c echo.Context) error {
c.Set("other", c.Get("me"))
return next(c)
})
}
}
// SetPost is the middleware that wraps user.SetPost middlware, thus:
// checks if the required post, on the user board, exists. If it exists,
// set the "post" = *UserPost in the current context
func SetPost() echo.MiddlewareFunc {
return user.SetPost()
}
// SetComment is the middleware that wraps user.SetComment middlware, thus:
// checks if the required post, on the user board, exists. Then check if
// the required comment exists and it's associated to that profile.
// If everything is ok, set "comment" = *UserPostComment in the current context
func SetComment() echo.MiddlewareFunc {
return user.SetComment()
}
// SetPm is the middleware that check if the required pm exists.
// If it exists, set the "pm" = *Pm in the current context
func SetPm() echo.MiddlewareFunc {
return user.SetPm()
}