本文整理汇总了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
}
}
示例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()
}
}
示例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
}
示例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
}
示例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
}
}
}
示例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
}
示例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
}
}
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例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
}
示例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)
}
示例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
}
示例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
}
}