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


Golang Router.Headers方法代碼示例

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


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

示例1: registerRoutes

// registerRoutes registers HTTP route handlers
func (d *daemon) registerRoutes(router *mux.Router) {
	// Add REST routes
	s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()

	s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
	s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
	s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
	s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))
	s.HandleFunc("/plugin/svcProviderUpdate", makeHTTPHandler(master.ServiceProviderUpdateHandler))

	s = router.Methods("Get").Subrouter()
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetEndpointRESTEndpoint, "{id}"),
		get(false, d.endpoints))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetEndpointsRESTEndpoint),
		get(true, d.endpoints))
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetNetworkRESTEndpoint, "{id}"),
		get(false, d.networks))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetNetworksRESTEndpoint),
		get(true, d.networks))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetServiceRESTEndpoint, "{id}"),
		get(false, d.services))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetServicesRESTEndpoint),
		get(true, d.services))

}
開發者ID:karamsivia,項目名稱:netplugin,代碼行數:27,代碼來源:daemon.go

示例2: registerRoutes

// registerRoutes registers HTTP route handlers
func (d *daemon) registerRoutes(router *mux.Router) {
	// register web ui handlers
	d.registerWebuiHandler(router)

	// Add REST routes
	s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()

	s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
	s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
	s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
	s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))

	s = router.Methods("Get").Subrouter()
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetEndpointRESTEndpoint, "{id}"),
		get(false, d.endpoints))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetEndpointsRESTEndpoint),
		get(true, d.endpoints))
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetNetworkRESTEndpoint, "{id}"),
		get(false, d.networks))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetNetworksRESTEndpoint),
		get(true, d.networks))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)

	// See if we need to create the default tenant
	go objApi.CreateDefaultTenant()
}
開發者ID:vvb,項目名稱:netplugin,代碼行數:27,代碼來源:daemon.go

示例3: registerRoutes

// registerRoutes registers HTTP route handlers
func (d *MasterDaemon) registerRoutes(router *mux.Router) {
	// Add REST routes
	s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()

	s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
	s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
	s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
	s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))
	s.HandleFunc("/plugin/updateEndpoint", makeHTTPHandler(master.UpdateEndpointHandler))

	s = router.Methods("Get").Subrouter()

	// return netmaster version
	s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)
	// Print info about the cluster
	s.HandleFunc(fmt.Sprintf("/%s", master.GetInfoRESTEndpoint), func(w http.ResponseWriter, r *http.Request) {
		info, err := d.getMasterInfo()
		if err != nil {
			log.Errorf("Error getting master state. Err: %v", err)
			http.Error(w, "Error getting master state", http.StatusInternalServerError)
			return
		}

		// convert to json
		resp, err := json.Marshal(info)
		if err != nil {
			http.Error(w,
				core.Errorf("marshalling json failed. Error: %s", err).Error(),
				http.StatusInternalServerError)
			return
		}
		w.Write(resp)
	})

	// services REST endpoints
	// FIXME: we need to remove once service inspect is added
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetServiceRESTEndpoint, "{id}"),
		get(false, d.services))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetServicesRESTEndpoint),
		get(true, d.services))

	// Debug REST endpoint for inspecting ofnet state
	s.HandleFunc("/debug/ofnet", func(w http.ResponseWriter, r *http.Request) {
		ofnetMasterState, err := d.ofnetMaster.InspectState()
		if err != nil {
			log.Errorf("Error fetching ofnet state. Err: %v", err)
			http.Error(w, "Error fetching ofnet state", http.StatusInternalServerError)
			return
		}
		w.Write(ofnetMasterState)
	})

}
開發者ID:abhinandanpb,項目名稱:netplugin,代碼行數:54,代碼來源:daemon.go


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