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


Golang models.MakeContext函數代碼示例

本文整理匯總了Golang中github.com/microcosm-cc/microcosm/models.MakeContext函數的典型用法代碼示例。如果您正苦於以下問題:Golang MakeContext函數的具體用法?Golang MakeContext怎麽用?Golang MakeContext使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: AttributeHandler

// AttributeHandler is a web handler
func AttributeHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	ctl := AttributeController{}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE"})
		return
	case "GET":
		ctl.Read(c)
	case "HEAD":
		ctl.Read(c)
	case "PUT":
		ctl.Update(c)
	case "DELETE":
		ctl.Delete(c)
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
開發者ID:riseofthetigers,項目名稱:microcosm,代碼行數:27,代碼來源:attribute.go

示例2: V1Handler

// V1Handler is a web handler
func V1Handler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET"})
		return
	case "GET":
		c.RespondWithData(
			h.LinkArrayType{Links: []h.LinkType{
				h.GetLink("activity", "", h.ItemTypeActivity, 0),
				h.GetLink("auth", "", h.ItemTypeAuth, 0),
				h.GetLink("comment", "", h.ItemTypeComment, 0),
				h.GetLink("conversation", "", h.ItemTypeConversation, 0),
				h.GetLink("event", "", h.ItemTypeEvent, 0),
				h.GetLink("microcosm", "", h.ItemTypeMicrocosm, 0),
				h.GetLink("poll", "", h.ItemTypePoll, 0),
				h.GetLink("profile", "", h.ItemTypeProfile, 0),
				h.LinkType{Rel: "site", Href: "/api/v1/site"},
				h.GetLink("update", "", h.ItemTypeUpdate, 0),
				h.GetLink("watcher", "", h.ItemTypeWatcher, 0),
				h.GetLink("whoami", "", h.ItemTypeWhoAmI, 0),
			}},
		)
		return
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
開發者ID:riseofthetigers,項目名稱:microcosm,代碼行數:35,代碼來源:default.go

示例3: GeoCodeHandler

// GeoCodeHandler is a web handler
func GeoCodeHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	if c.Request.Method != "GET" {
		c.RespondWithNotImplemented()
		return
	}

	ctl := GeoCodeController{}
	ctl.Read(c)
}
開發者ID:riseofthetigers,項目名稱:microcosm,代碼行數:16,代碼來源:geocode.go

示例4: MenuHandler

// MenuHandler is a web handler
func MenuHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	var siteID int64

	if id, exists := c.RouteVars["site_id"]; exists {
		siteID, err = strconv.ParseInt(id, 10, 64)
		if err != nil {
			c.RespondWithErrorMessage(
				fmt.Sprintf("The supplied site_id ('%s') is not a number.", id),
				http.StatusBadRequest,
			)
			return
		}
	}

	if siteID == 0 {
		siteID = c.Site.ID
	}

	ctl := MenuController{}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE"})
		return
	case "GET":
		ctl.Read(c, siteID)
	case "HEAD":
		ctl.Read(c, siteID)
	case "PUT":
		ctl.Update(c, siteID)
	case "DELETE":
		ctl.Delete(c, siteID)
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
開發者ID:riseofthetigers,項目名稱:microcosm,代碼行數:44,代碼來源:menu.go

示例5: FilesHandler

// FilesHandler is a web handler
func FilesHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
	}

	ctl := FilesController{}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "POST"})
		return
	case "POST":
		ctl.Create(c)
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
開發者ID:riseofthetigers,項目名稱:microcosm,代碼行數:20,代碼來源:files.go

示例6: TrendingHandler

// TrendingHandler is a web handler
func TrendingHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}
	ctl := TrendingController{}
	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET", "HEAD"})
		return
	case "GET":
		ctl.ReadMany(c)
	case "HEAD":
		ctl.ReadMany(c)
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
開發者ID:riseofthetigers,項目名稱:microcosm,代碼行數:21,代碼來源:trending.go

示例7: APIHandler

// APIHandler is a web handler
func APIHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET"})
		return
	case "GET":
		c.RespondWithData(
			h.LinkArrayType{Links: []h.LinkType{
				h.LinkType{Rel: "v1", Href: "/api/v1"},
			}},
		)
		return
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
開發者ID:riseofthetigers,項目名稱:microcosm,代碼行數:24,代碼來源:default.go

示例8: LegalsHandler

// LegalsHandler is a web handler
func LegalsHandler(w http.ResponseWriter, r *http.Request) {
	c, status, err := models.MakeContext(r, w)
	if err != nil {
		c.RespondWithErrorDetail(err, status)
		return
	}

	switch c.GetHTTPMethod() {
	case "OPTIONS":
		c.RespondWithOptions([]string{"OPTIONS", "GET"})
		return
	case "GET":
		if c.IsRootSite() {
			// Root site
			c.RespondWithData(
				h.LinkArrayType{Links: []h.LinkType{
					h.LinkType{Rel: "api", Href: "/api/v1/legal/service"},
				}},
			)
			return
		}

		// A customer site
		c.RespondWithData(
			h.LinkArrayType{Links: []h.LinkType{
				h.LinkType{Rel: "cookies", Href: "/api/v1/legal/cookies"},
				h.LinkType{Rel: "privacy", Href: "/api/v1/legal/privacy"},
				h.LinkType{Rel: "terms", Href: "/api/v1/legal/terms"},
			}},
		)
		return
	default:
		c.RespondWithStatus(http.StatusMethodNotAllowed)
		return
	}
}
開發者ID:riseofthetigers,項目名稱:microcosm,代碼行數:37,代碼來源:legal.go


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