How to Get User IP

Hi~~

Would you please let me know how to get the user’s IP in the *.tmpl?
I want to know where the users comes from…
Is there an easy way, such as {{if .ContextUserIP == “192.168.0.1”}}

That’s not possible, I’m afraid. You’re welcome to make a pull request if you want us to include the request’s context into the context data so that you can use it from the template.

If you want to see the parameters that are available to you, you can always add a {{ printf "%#v" . }} to a template to see the whole context being passed. For reference, here’s what it looks like on latest master:

 map[string]interface {}{"PageIsDashboard":true, "IsAdmin":true, "SignedUserID":1, "NotificationUnreadCount":0, "SignedUser":(*models.User)(0xc42091fa00), "ShowFooterVersion":true, "ContextUser":(*models.User)(0xc42091fa00), "EnableOpenIDSignIn":true, "Title":"howl - Dashboard", "PageIsNews":true, "MaxShowRepoNum":15, "MirrorCount":0, "AllLangs":[]i18n.LangType{i18n.LangType{Lang:"en-US", Name:"English"}, i18n.LangType{Lang:"zh-CN", Name:"简体中文"}, i18n.LangType{Lang:"zh-HK", Name:"繁體中文(香港)"}, i18n.LangType{Lang:"zh-TW", Name:"繁體中文(台灣)"}, i18n.LangType{Lang:"de-DE", Name:"Deutsch"}, i18n.LangType{Lang:"fr-FR", Name:"français"}, i18n.LangType{Lang:"nl-NL", Name:"Nederlands"}, i18n.LangType{Lang:"lv-LV", Name:"latviešu"}, ...}, "Link":"", "EnableSwaggerEndpoint":true, "ShowFooterBranding":false, "Mirrors":[]*models.Repository{}, "Feeds":[]*models.Action{...}, "Captcha":(*captcha.Captcha)(0xc4206eab00), "IsSigned":true, "SignedUserName":"howl", "PageStartTime":time.Time{wall:0xbeaf533a99cceb14, ext:10165903164, loc:(*time.Location)(0x188af40)}, "CsrfTokenHtml":"<input type=\"hidden\" name=\"_csrf\" value=\"_TlJ3WJ6mBoc4zMWAdNIPbDXoWc6MTUyNDQxNTkwNzMxMDY4NzYyMg==\">", "Orgs":[]*models.User{(*models.User)(0xc420b5a200)}, "SearchLimit":15, "Tr":(func(string, string, ...interface {}) string)(0x846b30), "Lang":"en-US", "RestLangs":[]i18n.LangType{i18n.LangType{Lang:"zh-CN", Name:"简体中文"}, i18n.LangType{Lang:"zh-HK", Name:"繁體中文(香港)"}, ...}, "CsrfToken":"_TlJ3WJ6mBoc4zMWAdNIPbDXoWc6MTUyNDQxNTkwNzMxMDY4NzYyMg==", "ShowRegistrationButton":true, "TmplLoadTimes":(func() string)(0x7efde0), "i18n":i18n.Locale{Locale:i18n.Locale{Lang:"en-US"}}, "LangName":"English"}

Thanks for your kindly reply!