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


Golang runtime.NegotiatedSerializer類代碼示例

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


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

示例1: negotiateOutputSerializer

func negotiateOutputSerializer(req *http.Request, ns runtime.NegotiatedSerializer) (runtime.Serializer, string, error) {
	acceptHeader := req.Header.Get("Accept")
	supported := ns.SupportedMediaTypes()
	if len(acceptHeader) == 0 && len(supported) > 0 {
		acceptHeader = supported[0]
	}
	accept, ok := negotiate(acceptHeader, supported)
	if !ok {
		return nil, "", errNotAcceptable{supported}
	}

	pretty := isPrettyPrint(req)
	if _, ok := accept.Params["pretty"]; !ok && pretty {
		accept.Params["pretty"] = "1"
	}
	mediaType := accept.Type
	if len(accept.SubType) > 0 {
		mediaType += "/" + accept.SubType
	}
	if s, ok := ns.SerializerForMediaType(mediaType, accept.Params); ok {
		return s, mediaType, nil
	}

	return nil, "", errNotAcceptable{supported}
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:25,代碼來源:negotiate.go

示例2: AddSupportedResourcesWebService

// Adds a service to return the supported resources, E.g., a such web service
// will be registered at /apis/extensions/v1.
func AddSupportedResourcesWebService(s runtime.NegotiatedSerializer, ws *restful.WebService, groupVersion unversioned.GroupVersion, apiResources []unversioned.APIResource) {
	resourceHandler := SupportedResourcesHandler(s, groupVersion, apiResources)
	ws.Route(ws.GET("/").To(resourceHandler).
		Doc("get available resources").
		Operation("getAPIResources").
		Produces(s.SupportedMediaTypes()...).
		Consumes(s.SupportedMediaTypes()...))
}
開發者ID:rrati,項目名稱:origin,代碼行數:10,代碼來源:apiserver.go

示例3: mediaTypesForSerializer

// mediaTypesForSerializer returns a list of media and stream media types for the server.
func mediaTypesForSerializer(ns runtime.NegotiatedSerializer) (mediaTypes, streamMediaTypes []string) {
	for _, info := range ns.SupportedMediaTypes() {
		mediaTypes = append(mediaTypes, info.MediaType)
		if info.StreamSerializer != nil {
			// stream=watch is the existing mime-type parameter for watch
			streamMediaTypes = append(streamMediaTypes, info.MediaType+";stream=watch")
		}
	}
	return mediaTypes, streamMediaTypes
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:11,代碼來源:negotiate.go

示例4: negotiateOutputStreamSerializer

func negotiateOutputStreamSerializer(req *http.Request, ns runtime.NegotiatedSerializer) (runtime.StreamSerializerInfo, error) {
	supported := ns.SupportedMediaTypes()
	mediaType, params, err := negotiateOutput(req, supported)
	if err != nil {
		return runtime.StreamSerializerInfo{}, err
	}
	if s, ok := ns.StreamingSerializerForMediaType(mediaType, params); ok {
		return s, nil
	}
	return runtime.StreamSerializerInfo{}, errNotAcceptable{supported}
}
開發者ID:40a,項目名稱:bootkube,代碼行數:11,代碼來源:negotiate.go

示例5: negotiateOutputStreamSerializer

func negotiateOutputStreamSerializer(req *http.Request, ns runtime.NegotiatedSerializer) (runtime.Serializer, runtime.Framer, string, string, error) {
	supported := ns.SupportedMediaTypes()
	mediaType, params, err := negotiateOutput(req, supported)
	if err != nil {
		return nil, nil, "", "", err
	}
	if s, f, exactMediaType, ok := ns.StreamingSerializerForMediaType(mediaType, params); ok {
		return s, f, mediaType, exactMediaType, nil
	}
	return nil, nil, "", "", errNotAcceptable{supported}
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:11,代碼來源:negotiate.go

示例6: AddGroupWebService

// Adds a service to return the supported versions, preferred version, and name
// of a group. E.g., a such web service will be registered at /apis/extensions.
func AddGroupWebService(s runtime.NegotiatedSerializer, container *restful.Container, path string, group unversioned.APIGroup) {
	groupHandler := GroupHandler(s, group)
	ws := new(restful.WebService)
	ws.Path(path)
	ws.Doc("get information of a group")
	ws.Route(ws.GET("/").To(groupHandler).
		Doc("get information of a group").
		Operation("getAPIGroup").
		Produces(s.SupportedMediaTypes()...).
		Consumes(s.SupportedMediaTypes()...))
	container.Add(ws)
}
開發者ID:rrati,項目名稱:origin,代碼行數:14,代碼來源:apiserver.go

示例7: AddApisWebService

// Adds a service to return the supported api versions at /apis.
func AddApisWebService(s runtime.NegotiatedSerializer, container *restful.Container, apiPrefix string, f func() []unversioned.APIGroup) {
	rootAPIHandler := RootAPIHandler(s, f)
	ws := new(restful.WebService)
	ws.Path(apiPrefix)
	ws.Doc("get available API versions")
	ws.Route(ws.GET("/").To(rootAPIHandler).
		Doc("get available API versions").
		Operation("getAPIVersions").
		Produces(s.SupportedMediaTypes()...).
		Consumes(s.SupportedMediaTypes()...))
	container.Add(ws)
}
開發者ID:rrati,項目名稱:origin,代碼行數:13,代碼來源:apiserver.go

示例8: AddApiWebService

// Adds a service to return the supported api versions at the legacy /api.
func AddApiWebService(s runtime.NegotiatedSerializer, container *restful.Container, apiPrefix string, versions []string) {
	// TODO: InstallREST should register each version automatically

	versionHandler := APIVersionHandler(s, versions[:]...)
	ws := new(restful.WebService)
	ws.Path(apiPrefix)
	ws.Doc("get available API versions")
	ws.Route(ws.GET("/").To(versionHandler).
		Doc("get available API versions").
		Operation("getAPIVersions").
		Produces(s.SupportedMediaTypes()...).
		Consumes(s.SupportedMediaTypes()...))
	container.Add(ws)
}
開發者ID:rrati,項目名稱:origin,代碼行數:15,代碼來源:apiserver.go

示例9: AddSupportedResourcesWebService

// Adds a service to return the supported resources, E.g., a such web service
// will be registered at /apis/extensions/v1.
func AddSupportedResourcesWebService(s runtime.NegotiatedSerializer, ws *restful.WebService, groupVersion unversioned.GroupVersion, apiResources []unversioned.APIResource) {
	ss := s
	if keepUnversioned(groupVersion.Group) {
		// Because in release 1.1, /apis/extensions/v1beta1 returns response
		// with empty APIVersion, we use StripVersionNegotiatedSerializer to
		// keep the response backwards compatible.
		ss = StripVersionNegotiatedSerializer{s}
	}
	resourceHandler := SupportedResourcesHandler(ss, groupVersion, apiResources)
	ws.Route(ws.GET("/").To(resourceHandler).
		Doc("get available resources").
		Operation("getAPIResources").
		Produces(s.SupportedMediaTypes()...).
		Consumes(s.SupportedMediaTypes()...))
}
開發者ID:mataihang,項目名稱:kubernetes,代碼行數:17,代碼來源:apiserver.go

示例10: negotiateInputSerializer

func negotiateInputSerializer(req *http.Request, s runtime.NegotiatedSerializer) (runtime.SerializerInfo, error) {
	supported := s.SupportedMediaTypes()
	mediaType := req.Header.Get("Content-Type")
	if len(mediaType) == 0 {
		mediaType = supported[0]
	}
	mediaType, options, err := mime.ParseMediaType(mediaType)
	if err != nil {
		return runtime.SerializerInfo{}, errUnsupportedMediaType{supported}
	}
	out, ok := s.SerializerForMediaType(mediaType, options)
	if !ok {
		return runtime.SerializerInfo{}, errUnsupportedMediaType{supported}
	}
	return out, nil
}
開發者ID:40a,項目名稱:bootkube,代碼行數:16,代碼來源:negotiate.go

示例11: acceptedMediaTypesForEndpoint

// acceptedMediaTypesForEndpoint returns an array of structs that are used to efficiently check which
// allowed media types the server exposes.
func acceptedMediaTypesForEndpoint(ns runtime.NegotiatedSerializer) []acceptedMediaType {
	var acceptedMediaTypes []acceptedMediaType
	for _, info := range ns.SupportedMediaTypes() {
		segments := strings.SplitN(info.MediaType, "/", 2)
		if len(segments) == 1 {
			segments = append(segments, "*")
		}
		t := acceptedMediaType{
			Type:       segments[0],
			SubType:    segments[1],
			Serializer: info,
		}
		acceptedMediaTypes = append(acceptedMediaTypes, t)
	}
	return acceptedMediaTypes
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:18,代碼來源:negotiate.go

示例12: AddApisWebService

// Adds a service to return the supported api versions at /apis.
func AddApisWebService(s runtime.NegotiatedSerializer, container *restful.Container, apiPrefix string, f func(req *restful.Request) []unversioned.APIGroup) {
	// Because in release 1.1, /apis returns response with empty APIVersion, we
	// use StripVersionNegotiatedSerializer to keep the response backwards
	// compatible.
	ss := StripVersionNegotiatedSerializer{s}
	rootAPIHandler := RootAPIHandler(ss, f)
	ws := new(restful.WebService)
	ws.Path(apiPrefix)
	ws.Doc("get available API versions")
	ws.Route(ws.GET("/").To(rootAPIHandler).
		Doc("get available API versions").
		Operation("getAPIVersions").
		Produces(s.SupportedMediaTypes()...).
		Consumes(s.SupportedMediaTypes()...))
	container.Add(ws)
}
開發者ID:mataihang,項目名稱:kubernetes,代碼行數:17,代碼來源:apiserver.go

示例13: writeNegotiated

// writeNegotiated renders an object in the content type negotiated by the client
func writeNegotiated(s runtime.NegotiatedSerializer, gv unversioned.GroupVersion, w http.ResponseWriter, req *http.Request, statusCode int, object runtime.Object) {
	serializer, contentType, err := negotiateOutputSerializer(req, s)
	if err != nil {
		status := errToAPIStatus(err)
		writeRawJSON(int(status.Code), status, w)
		return
	}

	w.Header().Set("Content-Type", contentType)
	w.WriteHeader(statusCode)

	encoder := s.EncoderForVersion(serializer, gv)
	if err := encoder.EncodeToStream(object, w); err != nil {
		errorJSONFatal(err, encoder, w)
	}
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:17,代碼來源:apiserver.go

示例14: AddApiWebService

// Adds a service to return the supported api versions at the legacy /api.
func AddApiWebService(s runtime.NegotiatedSerializer, container *restful.Container, apiPrefix string, getAPIVersionsFunc func(req *restful.Request) *unversioned.APIVersions) {
	// TODO: InstallREST should register each version automatically

	// Because in release 1.1, /api returns response with empty APIVersion, we
	// use StripVersionNegotiatedSerializer to keep the response backwards
	// compatible.
	ss := StripVersionNegotiatedSerializer{s}
	versionHandler := APIVersionHandler(ss, getAPIVersionsFunc)
	ws := new(restful.WebService)
	ws.Path(apiPrefix)
	ws.Doc("get available API versions")
	ws.Route(ws.GET("/").To(versionHandler).
		Doc("get available API versions").
		Operation("getAPIVersions").
		Produces(s.SupportedMediaTypes()...).
		Consumes(s.SupportedMediaTypes()...))
	container.Add(ws)
}
開發者ID:mataihang,項目名稱:kubernetes,代碼行數:19,代碼來源:apiserver.go

示例15: AddGroupWebService

// Adds a service to return the supported versions, preferred version, and name
// of a group. E.g., a such web service will be registered at /apis/extensions.
func AddGroupWebService(s runtime.NegotiatedSerializer, container *restful.Container, path string, group unversioned.APIGroup) {
	ss := s
	if keepUnversioned(group.Name) {
		// Because in release 1.1, /apis/extensions returns response with empty
		// APIVersion, we use StripVersionNegotiatedSerializer to keep the
		// response backwards compatible.
		ss = StripVersionNegotiatedSerializer{s}
	}
	groupHandler := GroupHandler(ss, group)
	ws := new(restful.WebService)
	ws.Path(path)
	ws.Doc("get information of a group")
	ws.Route(ws.GET("/").To(groupHandler).
		Doc("get information of a group").
		Operation("getAPIGroup").
		Produces(s.SupportedMediaTypes()...).
		Consumes(s.SupportedMediaTypes()...))
	container.Add(ws)
}
開發者ID:mataihang,項目名稱:kubernetes,代碼行數:21,代碼來源:apiserver.go


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