/
behind.go
45 lines (36 loc) · 1006 Bytes
/
behind.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
package gramework
import (
"net"
)
// Behind is an interface that allow you to parse provider-dependent
// headers in a compatible way.
//
// WARNING: this interface is currently in a WIP state and unfrozen.
// If you want to support your provider, please open an issue or PR
// at https://github.com/gramework/gramework.
// In that way we can ensure that you have always working implementation.
type Behind interface {
RemoteIP(ctx *Context) net.IP
RemoteAddr(ctx *Context) net.Addr
}
func (ctx *Context) RemoteIP() net.IP {
if ctx.App.behind != nil {
return ctx.App.behind.RemoteIP(ctx)
}
return ctx.RequestCtx.RemoteIP()
}
func (ctx *Context) RemoteAddr() net.Addr {
if ctx.App.behind != nil {
return ctx.App.behind.RemoteAddr(ctx)
}
return ctx.RequestCtx.RemoteAddr()
}
type internalBehindActivationHook interface {
OnAppActivation(*App)
}
func (app *App) Behind(u Behind) {
if hook, ok := u.(internalBehindActivationHook); ok {
hook.OnAppActivation(app)
}
app.behind = u
}