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


Golang restclient.RequestGet函數代碼示例

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


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

示例1: GetAllReplicationControllerName

func GetAllReplicationControllerName(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string) (returnedNameSlice []string, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetAllReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedNameSlice = nil
			returnedError = err.(error)
		}
	}()

	url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/"

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	jsonMap, err := restclient.RequestGet(url, headerMap, true)
	if err != nil {
		log.Error(err)
		return nil, err
	} else {
		nameSlice := make([]string, 0)
		for _, item := range jsonMap.(map[string]interface{})["items"].([]interface{}) {
			name, ok := item.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
			if ok {
				nameSlice = append(nameSlice, name)
			}
		}
		return nameSlice, nil
	}
}
開發者ID:cloudawan,項目名稱:cloudone_analysis,代碼行數:30,代碼來源:replication_controller.go

示例2: Get

// @Title get
// @Description get container log in the pod
// @Param namespace path string true "The name of namespace"
// @Param pod path string true "The name of pod"
// @Success 200 {string} {}
// @Failure 404 error reason
// @router /podlog/:namespace/:pod [get]
func (c *PodLogController) Get() {
	namespace := c.GetString(":namespace")
	pod := c.GetString(":pod")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/podlogs/" + namespace + "/" + pod

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	result, err := restclient.RequestGet(url, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	jsonMap, _ := result.(map[string]interface{})

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["logJsonMap"] = jsonMap
		c.ServeJSON()
	}
}
開發者ID:cloudawan,項目名稱:cloudone_gui,代碼行數:41,代碼來源:pod_log.go

示例3: GetAllNamespaceName

func GetAllNamespaceName(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedNameSlice []string, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetAllNamespaceName Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedNameSlice = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/", headerMap, true)
	if err != nil {
		log.Error("Fail to get all namespace name with endpoint: %s, token: %s, error: %s", kubeApiServerEndPoint, kubeApiServerToken, err.Error())
		return nil, err
	}
	jsonMap, _ := result.(map[string]interface{})

	nameSlice := make([]string, 0)
	for _, data := range jsonMap["items"].([]interface{}) {
		name, ok := data.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
		if ok {
			statusJsonMap, _ := data.(map[string]interface{})["status"].(map[string]interface{})
			phase, _ := statusJsonMap["phase"].(string)
			if phase == "Active" {
				nameSlice = append(nameSlice, name)
			}
		}

	}

	return nameSlice, nil
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:35,代碼來源:namespace.go

示例4: GetAllEvent

func GetAllEvent(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedEventSlice []map[string]interface{}, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetAllEvent Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedEventSlice = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	jsonMap, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/events/", headerMap, true)
	if err != nil {
		log.Error("Fail to get all event with endpoint: %s, token: %s, error: %s", kubeApiServerEndPoint, kubeApiServerToken, err.Error())
		return nil, err
	}

	eventSlice := make([]map[string]interface{}, 0)
	for _, data := range jsonMap.(map[string]interface{})["items"].([]interface{}) {
		value, ok := data.(map[string]interface{})
		if ok {
			eventSlice = append(eventSlice, value)
		}
	}

	return eventSlice, nil
}
開發者ID:cloudawan,項目名稱:cloudone_analysis,代碼行數:29,代碼來源:event.go

示例5: UpdateReplicationControllerSize

func UpdateReplicationControllerSize(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, size int) (returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("UpdateReplicationControllerSize Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName + "/"
	result, err := restclient.RequestGet(url, headerMap, true)
	jsonMap, _ := result.(map[string]interface{})
	if err != nil {
		log.Error("Get replication controller information failure where size: %d, endpoint: %s, token: %s, namespace: %s, replicationControllerName: %s, err: %s", size, kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
		return err
	} else {
		jsonMap["spec"].(map[string]interface{})["replicas"] = float64(size)
		_, err := restclient.RequestPut(url, jsonMap, headerMap, true)

		if err != nil {
			return err
		} else {
			return nil
		}
	}
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:29,代碼來源:replication_controller.go

示例6: GetAllImageTag

func (privateRegistry *PrivateRegistry) GetAllImageTag(repositoryName string) ([]string, error) {
	result, err := restclient.RequestGet(privateRegistry.getPrivateRegistryEndpoint()+"/v2/"+repositoryName+"/tags/list", nil, false)
	if err != nil {
		log.Error("Fail to get all image tags with repository %s and private registry: %v, error: %s", repositoryName, privateRegistry, err)
		return nil, err
	}

	jsonMap, _ := result.(map[string]interface{})
	tagJsonSlice, _ := jsonMap["tags"].([]interface{})
	tagSlice := make([]string, 0)
	for _, tagJsonInterface := range tagJsonSlice {
		if tag, ok := tagJsonInterface.(string); ok {
			request, err := http.NewRequest("GET", privateRegistry.getPrivateRegistryEndpoint()+"/v2/"+repositoryName+"/manifests/"+tag, nil)
			if err != nil {
				log.Error(err)
				return nil, err
			}

			// For registry version 2.3 and later
			request.Header.Add("Accept", "application/vnd.docker.distribution.manifest.v2+json")
			response, err := restclient.GetInsecureHTTPSClient().Do(request)
			if err != nil {
				log.Error(err)
				return nil, err
			}
			digest := response.Header.Get("Docker-Content-Digest")

			if len(digest) > 0 {
				tagSlice = append(tagSlice, tag)
			}
		}
	}

	return tagSlice, nil
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:35,代碼來源:private.go

示例7: ResizeReplicationController

func ResizeReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, delta int, maximumSize int, minimumSize int) (resized bool, size int, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("ResizeReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			resized = false
			size = -1
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName + "/"
	result, err := restclient.RequestGet(url, headerMap, true)
	jsonMap, _ := result.(map[string]interface{})
	if err != nil {
		log.Error("Get replication controller information failure where delta: %d, endpoint: %s, token: %s, namespace: %s, replicationControllerName: %s, err: %s", delta, kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
		return false, -1, err
	} else {
		replicas, _ := jsonparse.ConvertToInt64(jsonMap["spec"].(map[string]interface{})["replicas"])
		currentSize := int(replicas)
		newSize := currentSize + delta
		if newSize < minimumSize {
			newSize = minimumSize
		}
		if newSize > maximumSize {
			newSize = maximumSize
		}

		if newSize == currentSize {
			return false, currentSize, nil
		}

		jsonMap["spec"].(map[string]interface{})["replicas"] = float64(newSize)
		result, err := restclient.RequestPut(url, jsonMap, headerMap, true)
		resultJsonMap, _ := result.(map[string]interface{})
		if err != nil {
			return false, currentSize, err
		} else {
			replicas, _ := jsonparse.ConvertToInt64(resultJsonMap["spec"].(map[string]interface{})["replicas"])
			return true, int(replicas), nil
		}
	}
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:46,代碼來源:replication_controller.go

示例8: getContainerMonitorData

func getContainerMonitorData(urlSlice []string) ([]map[string]interface{}, []error) {
	dataMapSlice := make([]map[string]interface{}, 0)
	errorSlice := make([]error, 0)
	for _, url := range urlSlice {
		result, err := restclient.RequestGet(url, nil, true)
		jsonMap, _ := result.(map[string]interface{})
		if err != nil {
			dataMapSlice = append(dataMapSlice, nil)
			errorSlice = append(errorSlice, err)
		} else {
			dataMapSlice = append(dataMapSlice, jsonMap)
			errorSlice = append(errorSlice, nil)
		}
	}

	return dataMapSlice, errorSlice
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:17,代碼來源:pod.go

示例9: GetPodLog

func GetPodLog(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, podName string) (returnedLog map[string]interface{}, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetPodLog Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedLog = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/"+podName, headerMap, false)
	if err != nil {
		log.Error("Fail to get pod information with namespace %s pod %s endpoint: %s, token: %s, error: %s", namespace, podName, kubeApiServerEndPoint, kubeApiServerToken, err.Error())
		return nil, err
	}

	containerNameSlice := make([]string, 0)

	jsonMap, _ := result.(map[string]interface{})
	specJsonMap, _ := jsonMap["spec"].(map[string]interface{})
	containerSlice, _ := specJsonMap["containers"].([]interface{})
	for _, container := range containerSlice {
		containerJsonMap, _ := container.(map[string]interface{})
		containerName, ok := containerJsonMap["name"].(string)
		if ok {
			containerNameSlice = append(containerNameSlice, containerName)
		}
	}

	logJsonMap := make(map[string]interface{})
	for _, containerName := range containerNameSlice {
		byteSlice, err := restclient.RequestGetByteSliceResult(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/"+podName+"/log?container="+containerName, headerMap)
		if err != nil {
			log.Error("Fail to get log with namespace %s pod %s container %s endpoint: %s, token: %s, error: %s", namespace, podName, containerName, kubeApiServerEndPoint, kubeApiServerToken, err.Error())
			return nil, err
		} else {
			logJsonMap[containerName] = string(byteSlice)
		}
	}

	return logJsonMap, nil
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:45,代碼來源:pod_log.go

示例10: GetAllRepository

func (privateRegistry *PrivateRegistry) GetAllRepository() ([]string, error) {
	result, err := restclient.RequestGet(privateRegistry.getPrivateRegistryEndpoint()+"/v2/_catalog", nil, false)
	if err != nil {
		log.Error("Fail to get all repository with private registry: %v, error: %s", privateRegistry, err)
		return nil, err
	}

	jsonMap, _ := result.(map[string]interface{})
	repositoryJsonSlice, _ := jsonMap["repositories"].([]interface{})
	repositorySlice := make([]string, 0)
	for _, repositoryJsonInterface := range repositoryJsonSlice {
		if repository, ok := repositoryJsonInterface.(string); ok {
			repositorySlice = append(repositorySlice, repository)
		}
	}

	return repositorySlice, nil
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:18,代碼來源:private.go

示例11: ExistReplicationController

func ExistReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedExist bool, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("ExistReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedExist = false
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	_, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/replicationcontrollers/"+replicationControllerName, headerMap, true)
	if err != nil {
		log.Error("Fail to detect replication controller existence with endpoint: %s, token: %s, namespace: %s, replication controller name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
		return false, err
	} else {
		return true, nil
	}
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:21,代碼來源:replication_controller.go

示例12: GetReplicationControllerNameFromSelector

func GetReplicationControllerNameFromSelector(kubeApiServerEndPoint, kubeApiServerToken, namespace string, targetSelectorName string) (returnedReplicationControllerNameSlice []string, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetReplicationControllerNameFromSelector Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedReplicationControllerNameSlice = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/replicationcontrollers/", headerMap, true)
	jsonMap, _ := result.(map[string]interface{})
	if err != nil {
		log.Error("Fail to get all replication controller with endpoint: %s, token: %s, namespace: %s, selector name: %s",
			kubeApiServerEndPoint, kubeApiServerToken, namespace, targetSelectorName)
		return nil, err
	}

	nameSlice := make([]string, 0)
	for _, item := range jsonMap["items"].([]interface{}) {
		selector, ok := item.(map[string]interface{})["spec"].(map[string]interface{})["selector"].(map[string]interface{})
		if ok {
			selectorName, ok := selector["name"].(string)
			if ok {
				if targetSelectorName == selectorName {
					name, ok := item.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
					if ok {
						nameSlice = append(nameSlice, name)
					}
				}
			}
		}
	}

	return nameSlice, nil
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:39,代碼來源:replication_controller.go

示例13: GetAllPodBelongToReplicationController

func GetAllPodBelongToReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedPodSlice []Pod, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetAllPodBelongToReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedPodSlice = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/", headerMap, true)
	jsonMap, _ := result.(map[string]interface{})
	if err != nil {
		log.Error("Fail to get all pod inofrmation with endpoint %s, token: %s, namespace: %s, replication controller name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
		return nil, err
	}

	return GetAllPodBelongToReplicationControllerFromData(replicationControllerName, jsonMap)
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:22,代碼來源:pod.go

示例14: GetAllPodNameBelongToReplicationController

func GetAllPodNameBelongToReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedNameSlice []string, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetAllPodNameBelongToReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedNameSlice = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/", headerMap, true)
	if err != nil {
		log.Error("Fail to get replication controller inofrmation with endpoint %s, token: %s, namespace: %s, replication controller name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
		return nil, err
	}
	jsonMap, _ := result.(map[string]interface{})

	generateName := replicationControllerName + "-"
	podNameSlice := make([]string, 0)
	for _, data := range jsonMap["items"].([]interface{}) {
		generateNameField, _ := data.(map[string]interface{})["metadata"].(map[string]interface{})["generateName"].(string)
		nameField, nameFieldOk := data.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
		if generateName == generateNameField {
			if nameFieldOk {
				podNameSlice = append(podNameSlice, nameField)
			}
		} else if replicationControllerName == nameField {
			if nameFieldOk {
				podNameSlice = append(podNameSlice, nameField)
			}
		}
	}

	return podNameSlice, nil
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:38,代碼來源:pod.go

示例15: SendSMSNexmo

func (smsNexmo *SMSNexmo) SendSMSNexmo(smsNexmoURL string, smsNexmoAPIKey string, smsNexmoAPISecret string,
	sender string, receiverNumberSlice []string, text string) error {

	hasError := false
	buffer := bytes.Buffer{}
	for _, receiverNumber := range receiverNumberSlice {
		convertedURL, err := url.Parse(smsNexmoURL)
		if err != nil {
			log.Error("Parse url %s error %s", smsNexmoURL, err)
			return err
		}

		parameters := url.Values{}
		parameters.Add("api_key", smsNexmoAPIKey)
		parameters.Add("api_secret", smsNexmoAPISecret)
		parameters.Add("from", sender)
		parameters.Add("to", receiverNumber)
		parameters.Add("text", text)
		convertedURL.RawQuery = parameters.Encode()

		result, err := restclient.RequestGet(convertedURL.String(), nil, true)
		bodyJsonMap, _ := result.(map[string]interface{})
		if err != nil {
			log.Error("Request url %s error bodyJsonMap %s error %s", convertedURL.String(), bodyJsonMap, err)
			hasError = true
			buffer.WriteString(err.Error())
		} else {
			log.Info("SMS send to %s, bodyJsonMap %s", convertedURL.String(), bodyJsonMap)
		}
	}

	if hasError {
		return errors.New(buffer.String())
	} else {
		return nil
	}
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:37,代碼來源:sms.go


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