本文整理汇总了Golang中github.com/emicklei/go-restful.Response类的典型用法代码示例。如果您正苦于以下问题:Golang Response类的具体用法?Golang Response怎么用?Golang Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: allNamespaces
// allNamespaces returns a list of all the available namespaces in the cluster.
func (a *Api) allNamespaces(request *restful.Request, response *restful.Response) {
cluster := a.manager.GetCluster()
if cluster == nil {
response.WriteError(400, errModelNotActivated)
}
response.WriteEntity(cluster.GetNamespaces())
}
示例2: namespaceList
// namespaceList lists all namespaces for which we have metrics
func (a *HistoricalApi) namespaceList(request *restful.Request, response *restful.Response) {
if resp, err := a.historicalSource.GetNamespaces(); err != nil {
response.WriteError(http.StatusInternalServerError, err)
} else {
response.WriteEntity(resp)
}
}
示例3: getPortForward
// getPortForward handles a new restful port forward request. It determines the
// pod name and uid and then calls ServePortForward.
func (s *Server) getPortForward(request *restful.Request, response *restful.Response) {
params := getRequestParams(request)
pod, ok := s.host.GetPodByName(params.podNamespace, params.podName)
if !ok {
response.WriteError(http.StatusNotFound, fmt.Errorf("pod does not exist"))
return
}
if len(params.podUID) > 0 && pod.UID != params.podUID {
response.WriteError(http.StatusNotFound, fmt.Errorf("pod not found"))
return
}
redirect, err := s.host.GetPortForward(pod.Name, pod.Namespace, pod.UID)
if err != nil {
streaming.WriteError(err, response.ResponseWriter)
return
}
if redirect != nil {
http.Redirect(response.ResponseWriter, request.Request, redirect.String(), http.StatusFound)
return
}
portforward.ServePortForward(response.ResponseWriter,
request.Request,
s.host,
kubecontainer.GetPodFullName(pod),
params.podUID,
s.host.StreamingConnectionIdleTimeout(),
remotecommand.DefaultStreamCreationTimeout)
}
示例4: processMetricNamesRequest
// processMetricNamesRequest retrieves the available metrics for the object at the specified key.
func (a *HistoricalApi) processMetricNamesRequest(key core.HistoricalKey, response *restful.Response) {
if resp, err := a.historicalSource.GetMetricNames(key); err != nil {
response.WriteError(http.StatusInternalServerError, err)
} else {
response.WriteEntity(resp)
}
}
示例5: namespacePodList
// namespacePodList lists all pods for which we have metrics in a particular namespace
func (a *HistoricalApi) namespacePodList(request *restful.Request, response *restful.Response) {
if resp, err := a.historicalSource.GetPodsFromNamespace(request.PathParameter("namespace-name")); err != nil {
response.WriteError(http.StatusInternalServerError, err)
} else {
response.WriteEntity(resp)
}
}
示例6: getSinks
func (a *Api) getSinks(req *restful.Request, resp *restful.Response) {
sinkUris := a.manager.SinkUris()
if sinkUris == nil {
sinkUris = make(manager.Uris, 0)
}
resp.WriteEntity(sinkUris)
}
示例7: getExec
// getExec handles requests to run a command inside a container.
func (s *Server) getExec(request *restful.Request, response *restful.Response) {
params := getRequestParams(request)
pod, ok := s.host.GetPodByName(params.podNamespace, params.podName)
if !ok {
response.WriteError(http.StatusNotFound, fmt.Errorf("pod does not exist"))
return
}
podFullName := kubecontainer.GetPodFullName(pod)
redirect, err := s.host.GetExec(podFullName, params.podUID, params.containerName, params.cmd, params.streamOpts)
if err != nil {
response.WriteError(streaming.HTTPStatus(err), err)
return
}
if redirect != nil {
http.Redirect(response.ResponseWriter, request.Request, redirect.String(), http.StatusFound)
return
}
remotecommand.ServeExec(response.ResponseWriter,
request.Request,
s.host,
podFullName,
params.podUID,
params.containerName,
s.host.StreamingConnectionIdleTimeout(),
remotecommand.DefaultStreamCreationTimeout,
remotecommand.SupportedStreamingProtocols)
}
示例8: nodeSystemContainerList
// nodeSystemContainerList lists all system containers on a node for which we have metrics
func (a *HistoricalApi) nodeSystemContainerList(request *restful.Request, response *restful.Response) {
if resp, err := a.historicalSource.GetSystemContainersFromNode(request.PathParameter("node-name")); err != nil {
response.WriteError(http.StatusInternalServerError, err)
} else {
response.WriteEntity(resp)
}
}
示例9: podContainerMetrics
// podContainerMetrics returns a metric timeseries for a metric of the Container entity.
// freeContainerMetrics addresses only pod containers, by using the namespace-name/pod-name/container-name path.
func (a *Api) podContainerMetrics(request *restful.Request, response *restful.Response) {
cluster := a.manager.GetCluster()
// Get namespace name
namespace := request.PathParameter("namespace-name")
// Get pod name
pod := request.PathParameter("pod-name")
// Get container name
container := request.PathParameter("container-name")
// Get metric name
metric_name := request.PathParameter("metric-name")
// Get start time, parse as time.Time
req_stamp := parseRequestStartParam(request, response)
timeseries, new_stamp, err := cluster.GetPodContainerMetric(namespace, pod, container, metric_name, req_stamp)
if err != nil {
response.WriteError(http.StatusInternalServerError, err)
glog.Errorf("unable to get cluster metric: %s", err)
return
}
response.WriteEntity(exportTimeseries(timeseries, new_stamp))
}
示例10: handleDeployFromFile
// Handles deploy from file API call.
func (apiHandler *ApiHandler) handleDeployFromFile(request *restful.Request, response *restful.Response) {
deploymentSpec := new(AppDeploymentFromFileSpec)
if err := request.ReadEntity(deploymentSpec); err != nil {
handleInternalError(response, err)
return
}
isDeployed, err := DeployAppFromFile(
deploymentSpec, CreateObjectFromInfoFn, apiHandler.clientConfig)
if !isDeployed {
handleInternalError(response, err)
return
}
errorMessage := ""
if err != nil {
errorMessage = err.Error()
}
response.WriteHeaderAndEntity(http.StatusCreated, AppDeploymentFromFileResponse{
Name: deploymentSpec.Name,
Content: deploymentSpec.Content,
Error: errorMessage,
})
}
示例11: serveAttach
func (s *server) serveAttach(req *restful.Request, resp *restful.Response) {
containerID := req.PathParameter("containerID")
if containerID == "" {
resp.WriteError(http.StatusBadRequest, errors.New("missing required containerID path parameter"))
return
}
streamOpts, err := remotecommand.NewOptions(req.Request)
if err != nil {
resp.WriteError(http.StatusBadRequest, err)
return
}
remotecommand.ServeAttach(
resp.ResponseWriter,
req.Request,
s.runtime,
"", // unused: podName
"", // unusued: podUID
containerID,
streamOpts,
s.config.StreamIdleTimeout,
s.config.StreamCreationTimeout,
s.config.SupportedProtocols)
}
示例12: containerPaths
// containerPaths returns a list of all the available API paths that are available for a container.
func (a *Api) containerPaths(request *restful.Request, response *restful.Response) {
entities := []string{
"metrics/",
"stats/",
}
response.WriteEntity(entities)
}
示例13: exportMetricsSchema
func (a *Api) exportMetricsSchema(request *restful.Request, response *restful.Response) {
result := TimeseriesSchema{}
for _, label := range sinksApi.CommonLabels() {
result.CommonLabels = append(result.CommonLabels, LabelDescriptor{
Key: label.Key,
Description: label.Description,
})
}
for _, label := range sinksApi.PodLabels() {
result.PodLabels = append(result.PodLabels, LabelDescriptor{
Key: label.Key,
Description: label.Description,
})
}
for _, metric := range sinksApi.SupportedStatMetrics() {
md := MetricDescriptor{
Name: metric.Name,
Description: metric.Description,
Type: metric.Type.String(),
ValueType: metric.ValueType.String(),
Units: metric.Units.String(),
}
for _, label := range metric.Labels {
md.Labels = append(md.Labels, LabelDescriptor{
Key: label.Key,
Description: label.Description,
})
}
result.Metrics = append(result.Metrics, md)
}
response.WriteEntity(result)
}
示例14: nodePaths
// nodePaths returns a list of all the available API paths that are available for a node.
func (a *Api) nodePaths(request *restful.Request, response *restful.Response) {
entities := []string{
"freecontainers/",
"metrics/",
}
response.WriteEntity(entities)
}
示例15: namespacePaths
// namespacePaths returns a list of all the available API paths that are available for a namespace.
func (a *Api) namespacePaths(request *restful.Request, response *restful.Response) {
entities := []string{
"pods/",
"metrics/",
}
response.WriteEntity(entities)
}