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


Golang go-restful.Container類代碼示例

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


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

示例1: initOAuthAuthorizationServerMetadataRoute

// initOAuthAuthorizationServerMetadataRoute initializes an HTTP endpoint for OAuth 2.0 Authorization Server Metadata discovery
// https://tools.ietf.org/id/draft-ietf-oauth-discovery-04.html#rfc.section.2
// masterPublicURL should be internally and externally routable to allow all users to discover this information
func initOAuthAuthorizationServerMetadataRoute(apiContainer *genericmux.APIContainer, path, masterPublicURL string) {
	// Build OAuth metadata once
	metadata, err := json.MarshalIndent(discovery.Get(masterPublicURL, OpenShiftOAuthAuthorizeURL(masterPublicURL), OpenShiftOAuthTokenURL(masterPublicURL)), "", "  ")
	if err != nil {
		glog.Errorf("Unable to initialize OAuth authorization server metadata route: %v", err)
		return
	}

	secretContainer := restful.Container{
		ServeMux: apiContainer.SecretRoutes.(*http.ServeMux), // we know it's a *http.ServeMux. In kube 1.6, the type will actually be correct.
	}

	// Set up a service to return the OAuth metadata.
	ws := new(restful.WebService)
	ws.Path(path)
	ws.Doc("OAuth 2.0 Authorization Server Metadata")
	ws.Route(
		ws.GET("/").To(func(_ *restful.Request, resp *restful.Response) {
			writeJSON(resp, metadata)
		}).
			Doc("get the server's OAuth 2.0 Authorization Server Metadata").
			Operation("getOAuthAuthorizationServerMetadata").
			Produces(restful.MIME_JSON))

	secretContainer.Add(ws)
}
開發者ID:xgwang-zte,項目名稱:origin,代碼行數:29,代碼來源:master.go

示例2: Register

// Register adds the web service wrapped by the Service to the supplied
// container. If the supplied container is nil, then the default container is
// used, instead.
func (s *Service) Register(container *restful.Container) {
	if container == nil {
		container = restful.DefaultContainer
	}

	container.Add(s.WebService)
}
開發者ID:RamessesYin,項目名稱:deployment-manager,代碼行數:10,代碼來源:service.go

示例3: Register

// Register the mainApi on the specified endpoint.
func (a *Api) Register(container *restful.Container) {
	ws := new(restful.WebService)
	ws.Path("/api/v1/metric-export").
		Doc("Exports the latest point for all Heapster metrics").
		Produces(restful.MIME_JSON)
	ws.Route(ws.GET("").
		To(a.exportMetrics).
		Doc("export the latest data point for all metrics").
		Operation("exportMetrics").
		Writes([]*types.Timeseries{}))
	container.Add(ws)
	ws = new(restful.WebService)
	ws.Path("/api/v1/metric-export-schema").
		Doc("Schema for metrics exported by heapster").
		Produces(restful.MIME_JSON)
	ws.Route(ws.GET("").
		To(a.exportMetricsSchema).
		Doc("export the schema for all metrics").
		Operation("exportmetricsSchema").
		Writes(types.TimeseriesSchema{}))
	container.Add(ws)

	if a.metricSink != nil {
		a.RegisterModel(container)
	}

	if a.historicalSource != nil {
		a.RegisterHistorical(container)
	}
}
開發者ID:kubernetes,項目名稱:heapster,代碼行數:31,代碼來源:api.go

示例4: RegisterMetrics

// RegisterMetrics registers the Metrics API endpoints.
// All endpoints that end with a {metric-name} also receive a start time query parameter.
// The start and end times should be specified as a string, formatted according to RFC 3339.
// These apis are experimental, so they may change or disappear in the future.
func (a *Api) RegisterMetrics(container *restful.Container) {
	ws := new(restful.WebService)
	ws.
		Path("/experimental/v2").
		Doc("Root endpoint of the stats model").
		Consumes("*/*").
		Produces(restful.MIME_JSON)

	ws.Route(ws.GET("/nodeMetrics/derived/").
		To(a.derivedNodeMetricsList).
		Filter(compressionFilter).
		Doc("Get a list of all available metrics for all nodes").
		Writes([]types.DerivedNodeMetrics{}).
		Operation("derivedNodeMetricsList"))

	ws.Route(ws.GET("/nodeMetrics/derived/{node-name}").
		To(a.derivedNodeMetrics).
		Filter(compressionFilter).
		Doc("Get a list of all raw metrics for a Node entity").
		Writes(types.DerivedNodeMetrics{}).
		Operation("derivedNodeMetrics").
		Param(ws.PathParameter("node-name", "The name of the node to look up").DataType("string")))

	container.Add(ws)
}
開發者ID:MohamedFAhmed,項目名稱:heapster,代碼行數:29,代碼來源:metrics_handlers.go

示例5: Register

func (a *Api) Register(container *restful.Container) {
	ws := new(restful.WebService)
	ws.Path("/apis/metrics/v1alpha1").
		Doc("Root endpoint of metrics API").
		Produces(restful.MIME_JSON)

	ws.Route(ws.GET("/nodes/").
		To(a.nodeMetricsList).
		Doc("Get a list of metrics for all available nodes.").
		Operation("nodeMetricsList"))

	ws.Route(ws.GET("/nodes/{node-name}/").
		To(a.nodeMetrics).
		Doc("Get a list of all available metrics for the specified node.").
		Operation("nodeMetrics").
		Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")))

	ws.Route(ws.GET("/namespaces/{namespace-name}/pods/").
		To(a.podMetricsList).
		Doc("Get a list of metrics for all available pods in the specified namespace.").
		Operation("podMetricsList").
		Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))).
		Param(ws.QueryParameter("labelSelector", "A selector to restrict the list of returned objects by their labels. Defaults to everything.").DataType("string"))

	ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/").
		To(a.podMetrics).
		Doc("Get metrics for the specified pod in the specified namespace.").
		Operation("podMetrics").
		Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
		Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")))

	container.Add(ws)
}
開發者ID:caesarxuchao,項目名稱:heapster,代碼行數:33,代碼來源:handlers.go

示例6: RegisterHistorical

// RegisterHistorical registers the Historical API endpoints.  It will register the same endpoints
// as those in the model API, plus endpoints for aggregation retrieval, and endpoints to retrieve pod
// metrics by using the pod id.
func (normalApi *Api) RegisterHistorical(container *restful.Container) {
	ws := new(restful.WebService)
	ws.Path("/api/v1/historical").
		Doc("Root endpoint of the historical access API").
		Consumes("*/*").
		Produces(restful.MIME_JSON)

	a := &HistoricalApi{normalApi}
	addClusterMetricsRoutes(a, ws)
	addAggregationRoutes(a, ws)

	// register the endpoint for fetching raw metrics based on pod id
	if a.isRunningInKubernetes() {
		// The /pod-id/{pod-id}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
		// some aggregations for a Pod entity of the historical API.
		ws.Route(ws.GET("/pod-id/{pod-id}/metrics/{metric-name:*}").
			To(metrics.InstrumentRouteFunc("podMetrics", a.podMetrics)).
			Doc("Export some pod-level metric aggregations").
			Operation("podAggregations").
			Param(ws.PathParameter("pod-id", "The UID of the pod to lookup").DataType("string")).
			Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
			Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
			Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
			Writes(types.MetricResult{}))

		// The /pod-id/{pod-id}/containers/{container-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
		// some aggregations for a Container entity of the historical API.
		ws.Route(ws.GET("/pod-id/{pod-id}/containers/{container-name}/metrics/{metric-name:*}").
			To(metrics.InstrumentRouteFunc("podContainerMetrics", a.podContainerMetrics)).
			Doc("Export some aggregations for a Pod Container").
			Operation("podContainerAggregations").
			Param(ws.PathParameter("pod-id", "The uid of the pod to use").DataType("string")).
			Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string")).
			Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
			Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
			Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
			Writes(types.MetricResult{}))

		// The /pod-id-list/{pod-id-list}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
		// metrics for a list of pod ids of the historical API.
		ws.Route(ws.GET("/pod-id-list/{pod-id-list}/metrics/{metric-name:*}").
			To(metrics.InstrumentRouteFunc("podListAggregations", a.podListMetrics)).
			Doc("Export an aggregation for all pods from the given list").
			Operation("podListAggregations").
			Param(ws.PathParameter("pod-id-list", "Comma separated list of pod UIDs to lookup").DataType("string")).
			Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
			Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
			Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
			Writes(types.MetricResultList{}))
	}

	container.Add(ws)
}
開發者ID:kubernetes,項目名稱:heapster,代碼行數:56,代碼來源:historical_handlers.go

示例7: register

func register(container *restful.Container) {
	restful.RegisterEntityAccessor(MIME_MSGPACK, NewEntityAccessorMsgPack())
	ws := new(restful.WebService)
	ws.
		Path("/test").
		Consumes(restful.MIME_JSON, MIME_MSGPACK).
		Produces(restful.MIME_JSON, MIME_MSGPACK)
	// route user api
	ws.Route(ws.POST("/msgpack").
		To(do).
		Reads(user{}).
		Writes(userResponse{}))
	container.Add(ws)
}
開發者ID:luxas,項目名稱:flannel,代碼行數:14,代碼來源:msgpack_entity_test.go

示例8: InstallProtectedAPI

func (c *MasterConfig) InstallProtectedAPI(container *restful.Container) ([]string, error) {
	// initialize OpenShift API
	storage := c.GetRestStorage()

	messages := []string{}
	legacyAPIVersions := []string{}
	currentAPIVersions := []string{}

	if configapi.HasOpenShiftAPILevel(c.Options, OpenShiftAPIV1) {
		if err := c.apiLegacyV1(storage).InstallREST(container); err != nil {
			glog.Fatalf("Unable to initialize v1 API: %v", err)
		}
		messages = append(messages, fmt.Sprintf("Started Origin API at %%s%s", OpenShiftAPIPrefixV1))
		currentAPIVersions = append(currentAPIVersions, OpenShiftAPIV1)
	}

	var root *restful.WebService
	for _, service := range container.RegisteredWebServices() {
		switch service.RootPath() {
		case "/":
			root = service
		case OpenShiftAPIPrefixV1:
			service.Doc("OpenShift REST API, version v1").ApiVersion("v1")
		}
	}

	if root == nil {
		root = new(restful.WebService)
		container.Add(root)
	}

	// The old API prefix must continue to return 200 (with an empty versions
	// list) for backwards compatibility, even though we won't service any other
	// requests through the route. Take care when considering whether to delete
	// this route.
	initAPIVersionRoute(root, LegacyOpenShiftAPIPrefix, legacyAPIVersions...)
	initAPIVersionRoute(root, OpenShiftAPIPrefix, currentAPIVersions...)

	initControllerRoutes(root, "/controllers", c.Options.Controllers != configapi.ControllersDisabled, c.ControllerPlug)
	initHealthCheckRoute(root, "/healthz")
	initReadinessCheckRoute(root, "/healthz/ready", c.ProjectAuthorizationCache.ReadyForAccess)
	initVersionRoute(container, "/version/openshift")

	// Set up OAuth metadata only if we are configured to use OAuth
	if c.Options.OAuthConfig != nil {
		initOAuthAuthorizationServerMetadataRoute(container, oauthMetadataEndpoint, c.Options.OAuthConfig.MasterPublicURL)
	}

	return messages, nil
}
開發者ID:jayunit100,項目名稱:origin,代碼行數:50,代碼來源:master.go

示例9: InstallProtectedAPI

func (c *MasterConfig) InstallProtectedAPI(container *restful.Container) []string {
	// initialize OpenShift API
	storage := c.GetRestStorage()

	messages := []string{}
	legacyAPIVersions := []string{}
	currentAPIVersions := []string{}

	if configapi.HasOpenShiftAPILevel(c.Options, OpenShiftAPIV1Beta3) {
		if err := c.api_v1beta3(storage).InstallREST(container); err != nil {
			glog.Fatalf("Unable to initialize v1beta3 API: %v", err)
		}
		messages = append(messages, fmt.Sprintf("Started Origin API at %%s%s", OpenShiftAPIPrefixV1Beta3))
		legacyAPIVersions = append(legacyAPIVersions, OpenShiftAPIV1Beta3)
	}

	if configapi.HasOpenShiftAPILevel(c.Options, OpenShiftAPIV1) {
		if err := c.api_v1(storage).InstallREST(container); err != nil {
			glog.Fatalf("Unable to initialize v1 API: %v", err)
		}
		messages = append(messages, fmt.Sprintf("Started Origin API at %%s%s", OpenShiftAPIPrefixV1))
		currentAPIVersions = append(currentAPIVersions, OpenShiftAPIV1)
	}

	var root *restful.WebService
	for _, service := range container.RegisteredWebServices() {
		switch service.RootPath() {
		case "/":
			root = service
		case OpenShiftAPIPrefixV1Beta3:
			service.Doc("OpenShift REST API, version v1beta3").ApiVersion("v1beta3")
		case OpenShiftAPIPrefixV1:
			service.Doc("OpenShift REST API, version v1").ApiVersion("v1")
		}
	}

	if root == nil {
		root = new(restful.WebService)
		container.Add(root)
	}

	initAPIVersionRoute(root, LegacyOpenShiftAPIPrefix, legacyAPIVersions...)
	initAPIVersionRoute(root, OpenShiftAPIPrefix, currentAPIVersions...)

	initControllerRoutes(root, "/controllers", c.Options.Controllers != configapi.ControllersDisabled, c.ControllerPlug)
	initHealthCheckRoute(root, "/healthz")
	initReadinessCheckRoute(root, "/healthz/ready", c.ProjectAuthorizationCache.ReadyForAccess)

	return messages
}
開發者ID:ncantor,項目名稱:origin,代碼行數:50,代碼來源:master.go

示例10: initVersionRoute

// initReadinessCheckRoute initializes an HTTP endpoint for readiness checking
func initVersionRoute(container *restful.Container, path string) {
	// Set up a service to return the git code version.
	versionWS := new(restful.WebService)
	versionWS.Path(path)
	versionWS.Doc("git code version from which this is built")
	versionWS.Route(
		versionWS.GET("/").To(handleVersion).
			Doc("get the code version").
			Operation("getCodeVersion").
			Produces(restful.MIME_JSON).
			Consumes(restful.MIME_JSON))

	container.Add(versionWS)
}
開發者ID:pecameron,項目名稱:origin,代碼行數:15,代碼來源:master.go

示例11: RegisterModel

// RegisterModel registers the Model API endpoints.
// All endpoints that end with a {metric-name} also receive a start time query parameter.
// The start and end times should be specified as a string, formatted according to RFC 3339.
func (a *Api) RegisterModel(container *restful.Container) {
	ws := new(restful.WebService)
	ws.Path("/api/v1/model").
		Doc("Root endpoint of the stats model").
		Consumes("*/*").
		Produces(restful.MIME_JSON)

	addClusterMetricsRoutes(a, ws)

	ws.Route(ws.GET("/debug/allkeys").
		To(metrics.InstrumentRouteFunc("debugAllKeys", a.allKeys)).
		Doc("Get keys of all metric sets available").
		Operation("debugAllKeys"))
	container.Add(ws)
}
開發者ID:kubernetes,項目名稱:heapster,代碼行數:18,代碼來源:model_handlers.go

示例12: InstallAPI

func (c *ProxyConfig) InstallAPI(container *restful.Container) ([]string, error) {
	kubeAddr, err := url.Parse(c.ClientConfig.Host)
	if err != nil {
		return nil, err
	}

	proxy, err := httpproxy.NewUpgradeAwareSingleHostReverseProxy(c.ClientConfig, kubeAddr)
	if err != nil {
		return nil, fmt.Errorf("Unable to initialize the Kubernetes proxy: %v", err)
	}

	container.Handle("/api/", proxy)

	return []string{
		"Started Kubernetes proxy at %s/api/",
	}, nil
}
開發者ID:richm,項目名稱:origin,代碼行數:17,代碼來源:proxy.go

示例13: initOAuthAuthorizationServerMetadataRoute

// initOAuthAuthorizationServerMetadataRoute initializes an HTTP endpoint for OAuth 2.0 Authorization Server Metadata discovery
// https://tools.ietf.org/id/draft-ietf-oauth-discovery-04.html#rfc.section.2
// masterPublicURL should be internally and externally routable to allow all users to discover this information
func initOAuthAuthorizationServerMetadataRoute(container *restful.Container, path, masterPublicURL string) {
	// Build OAuth metadata once
	metadata, err := json.MarshalIndent(discovery.Get(masterPublicURL, OpenShiftOAuthAuthorizeURL(masterPublicURL), OpenShiftOAuthTokenURL(masterPublicURL)), "", "  ")
	if err != nil {
		glog.Errorf("Unable to initialize OAuth authorization server metadata route: %v", err)
		return
	}

	// Set up a service to return the OAuth metadata.
	oauthWS := new(restful.WebService)
	oauthWS.Path(path)
	oauthWS.Doc("OAuth 2.0 Authorization Server Metadata")
	oauthWS.Route(
		oauthWS.GET("/").To(func(_ *restful.Request, resp *restful.Response) {
			writeJSON(resp, metadata)
		}).
			Doc("get the server's OAuth 2.0 Authorization Server Metadata").
			Operation("getOAuthAuthorizationServerMetadata").
			Produces(restful.MIME_JSON))

	container.Add(oauthWS)
}
開發者ID:jayunit100,項目名稱:origin,代碼行數:25,代碼來源:master.go

示例14: initVersionRoute

// initVersionRoute initializes an HTTP endpoint for the server's version information.
func initVersionRoute(container *restful.Container, path string) {
	// Build version info once
	versionInfo, err := json.MarshalIndent(version.Get(), "", "  ")
	if err != nil {
		glog.Errorf("Unable to initialize version route: %v", err)
		return
	}

	// Set up a service to return the git code version.
	versionWS := new(restful.WebService)
	versionWS.Path(path)
	versionWS.Doc("git code version from which this is built")
	versionWS.Route(
		versionWS.GET("/").To(func(_ *restful.Request, resp *restful.Response) {
			writeJSON(resp, versionInfo)
		}).
			Doc("get the code version").
			Operation("getCodeVersion").
			Produces(restful.MIME_JSON))

	container.Add(versionWS)
}
開發者ID:jayunit100,項目名稱:origin,代碼行數:23,代碼來源:master.go

示例15: Register

// Register the Api on the specified endpoint.
func (a *Api) Register(container *restful.Container) {
	ws := new(restful.WebService)
	ws.
		Path("/api/v1/metric-export").
		Doc("Exports the latest point for all Heapster metrics").
		Produces(restful.MIME_JSON)
	ws.Route(ws.GET("").
		Filter(compressionFilter).
		To(a.exportMetrics).
		Doc("export the latest data point for all metrics").
		Operation("exportMetrics").
		Writes([]*Timeseries{}))
	container.Add(ws)
	ws = new(restful.WebService)
	ws.Path("/api/v1/metric-export-schema").
		Doc("Schema for metrics exported by heapster").
		Produces(restful.MIME_JSON)
	ws.Route(ws.GET("").
		To(a.exportMetricsSchema).
		Doc("export the schema for all metrics").
		Operation("exportmetricsSchema").
		Writes(TimeseriesSchema{}))
	container.Add(ws)
}
開發者ID:mikedanese,項目名稱:heapster,代碼行數:25,代碼來源:api.go


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