当前位置: 首页>>代码示例>>Golang>>正文


Golang Request.Referer方法代码示例

本文整理汇总了Golang中net/http.Request.Referer方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Referer方法的具体用法?Golang Request.Referer怎么用?Golang Request.Referer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net/http.Request的用法示例。


在下文中一共展示了Request.Referer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: send

func (s *loggingSender) send(ctx context.Context, r *http.Request, message string) {
	payload := map[string]interface{}{
		"eventTime":      time.Now().In(time.UTC).Format(time.RFC3339Nano),
		"message":        message,
		"serviceContext": s.serviceContext,
	}
	if r != nil {
		payload["context"] = map[string]interface{}{
			"httpRequest": map[string]interface{}{
				"method":    r.Method,
				"url":       r.Host + r.RequestURI,
				"userAgent": r.UserAgent(),
				"referrer":  r.Referer(),
				"remoteIp":  r.RemoteAddr,
			},
		}
	}
	e := logging.Entry{
		Severity: logging.Error,
		Payload:  payload,
	}
	err := s.logger.LogSync(ctx, e)
	if err != nil {
		log.Println("Error writing error report:", err, "report:", payload)
	}
}
开发者ID:trythings,项目名称:trythings,代码行数:26,代码来源:errors.go

示例2: EditTaskFunc

//EditTaskFunc is used to edit tasks, handles "/edit/" URL
func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		http.Redirect(w, r, "/", http.StatusBadRequest)
		return
	}

	id, err := strconv.Atoi(r.URL.Path[len("/edit/"):])
	if err != nil {
		log.Println(err)
		http.Redirect(w, r, "/", http.StatusBadRequest)
		return
	}
	redirectURL := utils.GetRedirectUrl(r.Referer())
	username := sessions.GetCurrentUserName(r)
	task, err := db.GetTaskByID(username, id)
	categories := db.GetCategories(username)
	task.Categories = categories
	task.Referer = redirectURL

	if err != nil {
		task.Message = "Error fetching Tasks"
	}
	editTemplate.Execute(w, task)

}
开发者ID:thewhitetulip,项目名称:Tasks,代码行数:26,代码来源:addViews.go

示例3: ServeHTTP

func (handler *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	logMsg := &RequestLog{actualResponseWriter: writer}
	logMsg.RequestHeaders = request.Header
	logMsg.Method = request.Method
	logMsg.Url = request.URL.String()
	logMsg.Host = request.Host
	logMsg.RemoteAddr = request.RemoteAddr
	logMsg.Referer = request.Referer()
	logMsg.UserAgent = request.UserAgent()
	handler.wrappedHandler.ServeHTTP(logMsg, request)
	// Get the resulting values
	if logMsg.ResponseCode == 0 {
		logMsg.ResponseCode = http.StatusOK
	}
	logMsg.ResponseHeaders = writer.Header()
	// Fire off the event to Forest Bus
	jsonMsg, err := json.Marshal(logMsg)
	if err == nil {
		sendErr := handler.msgBatcher.AsyncSendMessage(jsonMsg, nil, nil, handler.blockIfFull)
		if sendErr != nil {
			log.Printf("Warning: Error from AsyncSendMessage: %v\n", sendErr)
		}
	} else {
		log.Printf("Warning: Unable to marshal request information to JSON: %v\n", err)
	}
}
开发者ID:owlfish,项目名称:forestbus-server,代码行数:26,代码来源:handler.go

示例4: Handle

func Handle(w http.ResponseWriter, r *http.Request) {
	context := appengine.NewContext(r)

	now := time.Now()
	expire := now.AddDate(30, 0, 0)
	zcookie, _ := r.Cookie("z")
	if zcookie == nil {
		zcookie = &http.Cookie{}
		zcookie.Name = "z"
		zcookie.Value = make_hash("127.0.0.1", r.RemoteAddr, now.UnixNano())
		zcookie.Expires = expire
		zcookie.Path = "/"
		zcookie.Domain = config.DOMAIN
		http.SetCookie(w, zcookie)
	}
	context.Infof("%s", zcookie.Value)

	w.Header().Set("Content-type", "image/gif")
	w.Header().Set("Cache-control", "no-cache, must-revalidate")
	w.Header().Set("Expires", "Sat, 26 Jul 1997 05:00:00 GMT")

	fmt.Fprintf(w, "%s", GIF)

	channel.Send(context, "pi", zcookie.Value+"\n"+r.RemoteAddr+"\n"+r.Referer()+"\n"+r.FormValue("r")+"\n"+r.UserAgent())
}
开发者ID:hugozhu,项目名称:gae-rpi-webapp,代码行数:25,代码来源:counter.go

示例5: Login

func Login(session sessions.Session, re render.Render, r *http.Request) {
	client_id := common.Config.OAuth2Client_ID

	letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

	b := make([]rune, 10)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	session.AddFlash(string(b), "state")

	redirectBack := r.URL.Query().Get("redirect_back")
	ref := r.Referer()

	if redirectBack == "true" && ref != "" {
		session.Set("redirect_to", ref)
	} else {
		session.Set("redirect_to", nil)
	}

	query := url.Values{}
	query.Set("client_id", client_id)
	query.Set("state", string(b))
	query.Set("scope", "repo")

	dest := url.URL{
		Scheme:   "https",
		Host:     "github.com",
		Path:     "/login/oauth/authorize",
		RawQuery: query.Encode(),
	}
	re.Redirect(dest.String())
}
开发者ID:SemQuery,项目名称:web,代码行数:33,代码来源:session.go

示例6: RedirectBack

func RedirectBack(w http.ResponseWriter, r *http.Request) {
	url := r.Referer()
	if url == "" {
		url = "/"
	}
	http.Redirect(w, r, url, http.StatusSeeOther)
}
开发者ID:FurqanSoftware,项目名称:papyrus,代码行数:7,代码来源:errors.go

示例7: loginPage

func loginPage(page *page, req *http.Request) {

	page.SetField("redirect", "/")
	page.SetField("success", false)

	switch req.Method {
	case "POST":
		page.SetField("redirect", req.FormValue("redirect"))
		if req.FormValue("password") != page.main.conf.Password() {
			page.AddMessage("Feil passord.")
		} else {
			err := page.main.auth.NewSession()
			if err != nil {
				page.Fatalf("Failed to create new session: %s", err.Error())
			}
			http.SetCookie(page, &http.Cookie{
				Name:     "session-id",
				Value:    page.main.auth.SessionID(),
				HttpOnly: true,
			})
			page.AddMessage("Innloggin vellykket.")
			page.SetField("success", true)
		}
	case "GET":
		referrer := req.URL.Query().Get("redirect")
		if referrer == "" {
			referrer = req.Referer()
		}
		if referrer != "" {
			page.SetField("redirect", referrer)
		}
	}

	page.ExecuteTemplate("login")
}
开发者ID:ivartj,项目名称:norske-irc-kanaler.com,代码行数:35,代码来源:login-page.go

示例8: UserLoginHandler

func UserLoginHandler(ctx context.Context, rw http.ResponseWriter, r *http.Request) {
	if !cas.IsAuthenticated(r) {
		// save the referrer
		sessionmw.Set(ctx, CASReferrer, r.Referer())

		// shut off rendering
		dataRenderer := data.FromContext(ctx)
		dataRenderer.Type = data.DataNoRender

		// and redirect
		cas.RedirectToLogin(rw, r)
	} else {
		// get the referrer
		referrer, has := sessionmw.Get(ctx, CASReferrer)
		sessionmw.Delete(ctx, CASReferrer)

		// shut off rendering
		dataRenderer := data.FromContext(ctx)
		dataRenderer.Type = data.DataNoRender

		// and redirect
		if !has {
			http.Redirect(rw, r, render.ConvertURL("/"), http.StatusTemporaryRedirect)
		} else {
			http.Redirect(rw, r, referrer.(string), http.StatusTemporaryRedirect)
		}
	}
}
开发者ID:robxu9,项目名称:kahinah,代码行数:28,代码来源:user.go

示例9: processForm

func (p *post) processForm(r *http.Request) error {
	p.Date = time.Now()
	p.Subject = "Message submitted through " + r.Referer()
	if r.Form.Get("email") != "" {
		p.Replyto = r.Form.Get("email")
	}
	for k, v := range r.Form {
		if k == "_replyto" {
			p.Replyto = v[0]
			continue
		}
		if k == "_next" {
			p.Next = v[0]
			continue
		}
		if k == "_subject" {
			p.Subject = v[0]
			continue
		}
		if k == "_cc" {
			p.CC = v
			continue
		}
		p.Content[k] = v
	}
	return nil
}
开发者ID:codemodus,项目名称:formlark,代码行数:27,代码来源:server_datatypes.go

示例10: LoginHandler

func LoginHandler(w http.ResponseWriter, r *http.Request) {

	ref := r.Referer()

	if ref == "" {
		ref = "localhost"
	}
	service := service.NewMembershipService()
	service.Init(ref)

	m := r.Method
	if m != "POST" {
		server.JsonErr(w, errors.New("must POST when logging in"))
	}

	dec := json.NewDecoder(r.Body)

	var reg models.Registration

	err := dec.Decode(reg)

	if err != nil {
		server.JsonErr(w, err)
		return
	}

	reg, err = service.Login(reg)

	if err != nil {
		server.JsonErr(w, err)
	}

	server.Json(w, reg)
	return
}
开发者ID:nrml,项目名称:membership-go,代码行数:35,代码来源:endpoints.go

示例11: Log

// Log is show viwer log.
func Log(req *http.Request) {
	var userIP string
	if userIP = req.Header.Get("X-FORWARDED-FOR"); userIP == "" {
		userIP = req.RemoteAddr
	}
	log.Println(req.URL, userIP, req.UserAgent(), req.Form, req.Referer())
}
开发者ID:668Jerry,项目名称:gogrs,代码行数:8,代码来源:main.go

示例12: logInternal

func (c *Client) logInternal(ctx context.Context, r *http.Request, isPanic bool, msg string) {
	payload := map[string]interface{}{
		"eventTime": time.Now().In(time.UTC).Format(time.RFC3339Nano),
	}
	// limit the stack trace to 16k.
	var buf [16384]byte
	stack := buf[0:runtime.Stack(buf[:], false)]
	payload["message"] = msg + "\n" + chopStack(stack, isPanic)
	if r != nil {
		payload["context"] = map[string]interface{}{
			"httpRequest": map[string]interface{}{
				"method":    r.Method,
				"url":       r.Host + r.RequestURI,
				"userAgent": r.UserAgent(),
				"referrer":  r.Referer(),
				"remoteIp":  r.RemoteAddr,
			},
		}
	}
	if c == nil {
		log.Println("Error report used nil client:", payload)
		return
	}
	payload["serviceContext"] = c.serviceContext
	e := logging.Entry{
		Level:   logging.Error,
		Payload: payload,
	}
	err := c.loggingClient.LogSync(e)
	if err != nil {
		log.Println("Error writing error report:", err, "report:", payload)
	}
}
开发者ID:trythings,项目名称:trythings,代码行数:33,代码来源:errors.go

示例13: NewContext

func NewContext(req *http.Request) (*Context, error) {
	sess, err := store.Get(req, Settings.Session.Name)
	sess.Options.Domain = Settings.Session.Domain
	sess.Options.HttpOnly = true
	var (
		lastUid string
		user    *User
	)
	if v, ok := sess.Values[kLastUid]; ok {
		lastUid = v.(string)
	}
	if v, ok := sess.Values[kUserOL]; ok {
		user = v.(*User)
	}
	referer := req.FormValue("referer")
	if referer == "" {
		referer = req.Referer()
	}
	ctx := &Context{
		Vars:    mux.Vars(req),
		Session: sess,
		ResUrl:  Settings.ResUrl,
		Referer: referer,
		Version: VERSION,
		LastUid: lastUid,
		User:    user,
	}
	if err != nil {
		log.Printf("new context error: %s", err)
		return ctx, err
	}

	return ctx, err
}
开发者ID:gooops,项目名称:staffio,代码行数:34,代码来源:context.go

示例14: NewContext

func NewContext(app *App, res http.ResponseWriter, req *http.Request) *Context {
	c := new(Context)
	c.app = app
	c.IsSend = false
	c.IsEnd = false

	c.Request = req
	c.Url = req.URL.Path
	c.RequestUrl = req.RequestURI
	c.Method = req.Method
	c.Host = req.Host
	c.Ip = strings.Split(req.RemoteAddr, ":")[0]
	c.IsAjax = req.Header.Get("X-Requested-With") == "XMLHttpRequest"
	c.IsSSH = req.TLS == nil
	c.UserAgent = req.UserAgent()
	c.Referer = req.Referer()

	c.eventsFunc = make(map[string][]reflect.Value)

	c.BaseUrl = "://" + c.Host + "/"
	if c.IsSSH {
		c.BaseUrl = "https" + c.BaseUrl
	} else {
		c.BaseUrl = "http" + c.BaseUrl
	}

	c.Response = res
	c.Status = 200
	c.Header = make(map[string]string)
	c.Header["Content-Type"] = "text/html;charset=UTF-8"

	req.ParseForm()
	return c
}
开发者ID:vckai,项目名称:GoAnswer,代码行数:34,代码来源:context.go

示例15: assetView

// assetView handles the requested assets.
//  request      /doc/gopher/pkg.png
//  referer      http://localhost:8000/?view=https://golang.org/pkg/
//  returns      https://golang.org/doc/gopher/pkg.png
func assetView(r *http.Request) (v string) {
	referer := r.Referer()

	if referer == "" {
		return
	}

	refererURL, err := url.Parse(referer)
	if err != nil {
		return
	}

	if refererURL.Host != r.Host {
		return
	}

	view := refererURL.Query().Get("view")
	if view == "" {
		return
	}

	baseView, err := url.Parse(view)
	if err != nil {
		return
	}

	nextView, err := baseView.Parse(r.URL.Path)
	if err != nil {
		return
	}

	v = nextView.String()
	return
}
开发者ID:schorlet,项目名称:cdc,代码行数:38,代码来源:main.go


注:本文中的net/http.Request.Referer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。