func Router(session *mgo.Session) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, req *http.Request) { user_agent := new(ua.UserAgent) user_agent.Parse(req.Header.Get("User-Agent")) url := req.FormValue("url") engine_name, engine_version := user_agent.Engine() browser_name, browser_version := user_agent.Browser() url_document := &URL{ Date: time.Now(), Uri: url, Mobile: user_agent.Mobile(), Bot: user_agent.Bot(), Mozilla: user_agent.Mozilla(), Platform: user_agent.Platform(), Os: user_agent.OS(), EngineName: engine_name, EngineVersion: engine_version, BrowserName: browser_name, BrowserVersion: browser_version, } c := session.DB("goanywhere").C("urls") err := c.Insert(url_document) if err != nil { panic(err) } http.Redirect(w, req, url, http.StatusFound) } }
func ParseUserAgent(req *http.Request) *UserAgent { ua := new(user_agent.UserAgent) ua.Parse(req.UserAgent()) val := &UserAgent{ Header: req.UserAgent(), Bot: ua.Bot(), Mobile: ua.Mobile(), Platform: ua.Platform(), OS: ua.OS(), Make: req.UserAgent(), // TODO - fix the library } val.Browser, val.BrowserVersion = ua.Browser() return val }
func (this *RequestParser) Parse(req *http.Request) (r *Request, err error) { r = &Request{} r.Country, err = this.geo(req) ua := new(user_agent.UserAgent) ua.Parse(req.UserAgent()) r.Referrer = req.Referer() if r.Referrer == "" { r.Referrer = "DIRECT" } r.Bot = ua.Bot() r.Mobile = ua.Mobile() r.OS = ua.OS() r.Browser, r.Version = ua.Browser() return r, err }
func (this *RequestParser) Browser(req *http.Request) (bot bool, mobile bool, os string, browser string, version string) { ua := new(user_agent.UserAgent) ua.Parse(req.UserAgent()) browserName, browserVersion := ua.Browser() return ua.Bot(), ua.Mobile(), ua.OS(), browserName, browserVersion }