當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Query.RemoteAddr方法代碼示例

本文整理匯總了Golang中tonika/http.Query.RemoteAddr方法的典型用法代碼示例。如果您正苦於以下問題:Golang Query.RemoteAddr方法的具體用法?Golang Query.RemoteAddr怎麽用?Golang Query.RemoteAddr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tonika/http.Query的用法示例。


在下文中一共展示了Query.RemoteAddr方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: serve

func serve(q *http.Query) {
	req := q.GetRequest()
	if req.Body != nil {
		req.Body.Close()
	}
	resp := process(req, q.RemoteAddr())
	asc := q.Hijack()
	asc.Write(req, resp)
	conn, _, _ := asc.Close()
	if conn != nil {
		conn.Close()
	}
}
開發者ID:fedgrant,項目名稱:tonika,代碼行數:13,代碼來源:daemon.go

示例2: serve

func (s *Server) serve(q *http.Query) {
	q.Continue()
	req := q.GetRequest()
	if req.Body != nil {
		req.Body.Close()
	}
	s.log(req, q.RemoteAddr())

	// Path cleanup
	path := path.Clean(req.URL.Path)
	if path == "" {
		path = "/"
	}

	// Host analysis
	hostport := strings.Split(req.Host, ":", 2)
	if len(hostport) == 0 {
		q.Write(newRespBadRequest())
		return
	}
	hostparts := misc.ReverseHost(strings.Split(hostport[0], ".", -1))

	// http://5ttt.org, http://www.5ttt.org
	if len(hostparts) < 3 || hostparts[2] == "www" {
		if path == "/" {
			path = "/index.html"
		}

		if isIndex(path) {
			s.lk.Lock()
			s.stats.Views++
			s.lk.Unlock()
		}

		var resp *http.Response
		if isIndex(path) {
			resp = s.replyIndex()
		} else {
			resp = s.replyStatic(path)
		}

		if isDownload(path) && resp.Body != nil {
			resp.Body = http.NewRunOnClose(resp.Body, func() {
				// TODO: This also counts incomplete downloads, but for now
				// it's fine.
				s.lk.Lock()
				s.stats.Downloads++
				s.lk.Unlock()
			})
		}
		q.Write(resp)
		return
	}

	// Remove 5ttt.org from host
	hostparts = hostparts[2:]

	// http://*.a.5ttt.org/*
	if hostparts[0] == "a" {
		q.Write(s.replyStatic("/tadmin.html")) // Trying to access a Tonika Admin
		return
	}

	// http://*.[id].5ttt.org
	if _, err := sys.ParseId(hostparts[0]); err == nil {
		q.Write(s.replyStatic("/turl.html")) // Trying to access a Tonika URL
		return
	}

	// Otherwise
	q.Write(newRespNotFound())
}
開發者ID:fedgrant,項目名稱:tonika,代碼行數:72,代碼來源:server.go


注:本文中的tonika/http.Query.RemoteAddr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。