Add hostname template action

This adds the ability to display the remote hostname
of the visitors IP with template actions.
This commit is contained in:
Jannick Fahlbusch 2017-04-18 23:14:40 +02:00
parent 729e4f0239
commit 92af3ee4d8
No known key found for this signature in database
GPG key ID: B6F3B49B350D87BD
2 changed files with 43 additions and 0 deletions

View file

@ -63,6 +63,18 @@ func (c Context) Header(name string) string {
return c.Req.Header.Get(name)
}
// Hostname gets the (remote) hostname of the client making the request.
func (c Context) Hostname() string {
ip := c.IP()
hostnameList, err := net.LookupAddr(ip)
if err != nil || len(hostnameList) == 0 {
return c.Req.RemoteAddr
}
return hostnameList[0]
}
// Env gets a map of the environment variables.
func (c Context) Env() map[string]string {
osEnv := os.Environ()