本文整理匯總了Golang中github.com/emicklei/go-restful.Request類的典型用法代碼示例。如果您正苦於以下問題:Golang Request類的具體用法?Golang Request怎麽用?Golang Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Request類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: nodeMetricsList
func (a *Api) nodeMetricsList(request *restful.Request, response *restful.Response) {
selector := request.QueryParameter("labelSelector")
labelSelector, err := labels.Parse(selector)
if err != nil {
errMsg := fmt.Errorf("Error while parsing selector %v: %v", selector, err)
glog.Error(errMsg)
response.WriteError(http.StatusBadRequest, errMsg)
return
}
nodes, err := a.nodeLister.NodeCondition(func(node *kube_api.Node) bool {
if labelSelector.Empty() {
return true
}
return labelSelector.Matches(labels.Set(node.Labels))
}).List()
if err != nil {
errMsg := fmt.Errorf("Error while listing nodes: %v", err)
glog.Error(errMsg)
response.WriteError(http.StatusInternalServerError, errMsg)
return
}
res := v1alpha1.NodeMetricsList{}
for _, node := range nodes {
if m := a.getNodeMetrics(node.Name); m != nil {
res.Items = append(res.Items, *m)
}
}
response.WriteEntity(&res)
}
示例3: 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)
}
示例4: availableNamespaceMetrics
// availableNamespaceMetrics returns a list of available namespace metric names.
func (a *HistoricalApi) availableNamespaceMetrics(request *restful.Request, response *restful.Response) {
key := core.HistoricalKey{
ObjectType: core.MetricSetTypeNamespace,
NamespaceName: request.PathParameter("namespace-name"),
}
a.processMetricNamesRequest(key, response)
}
示例5: serveAttach
func (s *server) serveAttach(req *restful.Request, resp *restful.Response) {
token := req.PathParameter("token")
cachedRequest, ok := s.cache.Consume(token)
if !ok {
http.NotFound(resp.ResponseWriter, req.Request)
return
}
attach, ok := cachedRequest.(*runtimeapi.AttachRequest)
if !ok {
http.NotFound(resp.ResponseWriter, req.Request)
return
}
streamOpts := &remotecommand.Options{
Stdin: attach.GetStdin(),
Stdout: true,
Stderr: !attach.GetTty(),
TTY: attach.GetTty(),
}
remotecommand.ServeAttach(
resp.ResponseWriter,
req.Request,
s.runtime,
"", // unused: podName
"", // unusued: podUID
attach.GetContainerId(),
streamOpts,
s.config.StreamIdleTimeout,
s.config.StreamCreationTimeout,
s.config.SupportedProtocols)
}
示例6: podMetricsInNamespaceList
func podMetricsInNamespaceList(a *Api, request *restful.Request, response *restful.Response, namespace string) {
selector := request.QueryParameter("labelSelector")
labelSelector, err := labels.Parse(selector)
if err != nil {
errMsg := fmt.Errorf("Error while parsing selector %v: %v", selector, err)
glog.Error(errMsg)
response.WriteError(http.StatusBadRequest, errMsg)
return
}
pods, err := a.podLister.Pods(namespace).List(labelSelector)
if err != nil {
errMsg := fmt.Errorf("Error while listing pods for selector %v: %v", selector, err)
glog.Error(errMsg)
response.WriteError(http.StatusInternalServerError, errMsg)
return
}
res := v1alpha1.PodMetricsList{}
for _, pod := range pods.Items {
if m := a.getPodMetrics(&pod); m != nil {
res.Items = append(res.Items, *m)
} else {
glog.Infof("No metrics for pod %s/%s", pod.Namespace, pod.Name)
}
}
response.WriteEntity(&res)
}
示例7: namespaceAggregations
// namespaceAggregations returns a metric timeseries for a metric of the Namespace entity.
func (a *HistoricalApi) namespaceAggregations(request *restful.Request, response *restful.Response) {
key := core.HistoricalKey{
ObjectType: core.MetricSetTypeNamespace,
NamespaceName: request.PathParameter("namespace-name"),
}
a.processAggregationRequest(key, request, response)
}
示例8: nodeMetrics
// nodeMetrics returns a metric timeseries for a metric of the Node entity.
func (a *HistoricalApi) nodeMetrics(request *restful.Request, response *restful.Response) {
key := core.HistoricalKey{
ObjectType: core.MetricSetTypeNode,
NodeName: request.PathParameter("node-name"),
}
a.processMetricRequest(key, request, response)
}
示例9: 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,
})
}
示例10: processMetricRequest
// processMetricRequest retrieves a metric for the object at the requested key.
func (a *HistoricalApi) processMetricRequest(key core.HistoricalKey, request *restful.Request, response *restful.Response) {
start, end, err := getStartEndTimeHistorical(request)
if err != nil {
response.WriteError(http.StatusBadRequest, err)
return
}
labels, err := getLabels(request)
if err != nil {
response.WriteError(http.StatusBadRequest, err)
return
}
metricName := request.PathParameter("metric-name")
convertedMetricName := convertMetricName(metricName)
var metrics map[core.HistoricalKey][]core.TimestampedMetricValue
if labels != nil {
metrics, err = a.historicalSource.GetLabeledMetric(convertedMetricName, labels, []core.HistoricalKey{key}, start, end)
} else {
metrics, err = a.historicalSource.GetMetric(convertedMetricName, []core.HistoricalKey{key}, start, end)
}
if err != nil {
response.WriteError(http.StatusInternalServerError, err)
return
}
converted := exportTimestampedMetricValue(metrics[key])
response.WriteEntity(converted)
}
示例11: parseMetricRequest
// parseMetricRequest returns a MetricRequest from the metric-related query and path parameters of the request.
func parseMetricRequest(request *restful.Request, response *restful.Response) model_api.MetricRequest {
return model_api.MetricRequest{
MetricName: request.PathParameter("metric-name"),
Start: parseRequestParam("start", request, response),
End: parseRequestParam("end", request, response),
}
}
示例12: freeContainerMetrics
// freeContainerMetrics returns a metric timeseries for a metric of the Container entity.
// freeContainerMetrics addresses only free containers, by using the node-name/container-name path.
func (a *Api) freeContainerMetrics(request *restful.Request, response *restful.Response) {
a.processMetricRequest(
core.NodeContainerKey(request.PathParameter("node-name"),
request.PathParameter("container-name"),
),
request, response)
}
示例13: 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)
}
}
示例14: nodePods
// nodePods returns a list of all the available API paths that are available for a node.
func (a *Api) nodePods(request *restful.Request, response *restful.Response) {
model := a.manager.GetModel()
if model == nil {
response.WriteError(400, errModelNotActivated)
}
node := request.PathParameter("node-name")
response.WriteEntity(makeExternalEntityList(model.GetNodePods(node)))
}
示例15: allPods
// allPods returns a list of all the available pods in the cluster.
func (a *Api) allPods(request *restful.Request, response *restful.Response) {
cluster := a.manager.GetCluster()
if cluster == nil {
response.WriteError(400, errModelNotActivated)
}
namespace := request.PathParameter("namespace-name")
response.WriteEntity(cluster.GetPods(namespace))
}