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


Golang httpclient.Get函數代碼示例

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


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

示例1: List

func (k *SKeys) List() (*[]models.UserKey, error) {
	headers := httpclient.GetHeaders(k.Settings.SessionToken, k.Settings.Version, k.Settings.Pod, k.Settings.UsersID)
	resp, status, err := httpclient.Get(nil, fmt.Sprintf("%s%s/keys", k.Settings.AuthHost, k.Settings.AuthHostVersion), headers)
	if err != nil {
		return nil, err
	}

	keys := []models.UserKey{}
	err = httpclient.ConvertResp(resp, status, &keys)
	return &keys, err
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:11,代碼來源:list.go

示例2: Retrieve

func (j *SJobs) Retrieve(jobID, svcID string, includeSpec bool) (*models.Job, error) {
	headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID)
	resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs/%s?spec=true", j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, jobID), headers)
	if err != nil {
		return nil, err
	}
	var job models.Job
	err = httpclient.ConvertResp(resp, statusCode, &job)
	if err != nil {
		return nil, err
	}
	return &job, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:13,代碼來源:retrieve.go

示例3: Retrieve

func (w *SWorker) Retrieve(svcID string) (*models.Workers, error) {
	headers := httpclient.GetHeaders(w.Settings.SessionToken, w.Settings.Version, w.Settings.Pod, w.Settings.UsersID)
	resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/workers", w.Settings.PaasHost, w.Settings.PaasHostVersion, w.Settings.EnvironmentID, svcID), headers)
	if err != nil {
		return nil, err
	}
	var workers models.Workers
	err = httpclient.ConvertResp(resp, statusCode, &workers)
	if err != nil {
		return nil, err
	}
	return &workers, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:13,代碼來源:list.go

示例4: RetrieveByStatus

func (j *SJobs) RetrieveByStatus(svcID, status string) (*[]models.Job, error) {
	headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID)
	resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs?status=%s", j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, status), headers)
	if err != nil {
		return nil, err
	}
	var jobs []models.Job
	err = httpclient.ConvertResp(resp, statusCode, &jobs)
	if err != nil {
		return nil, err
	}
	return &jobs, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:13,代碼來源:retrieve.go

示例5: List

func (j *SJobs) List(svcID string, page, pageSize int) (*[]models.Job, error) {
	headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID)
	resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs?pageNumber=%d&pageSize=%d", j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, page, pageSize), headers)
	if err != nil {
		return nil, err
	}
	var jobs []models.Job
	err = httpclient.ConvertResp(resp, statusCode, &jobs)
	if err != nil {
		return nil, err
	}
	return &jobs, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:13,代碼來源:list.go

示例6: RetrieveServiceMetrics

// RetrieveServiceMetrics retrieves metrics data for the given service.
func (m *SMetrics) RetrieveServiceMetrics(mins int, svcID string) (*models.Metrics, error) {
	headers := httpclient.GetHeaders(m.Settings.SessionToken, m.Settings.Version, m.Settings.Pod, m.Settings.UsersID)
	resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/metrics?time=%dm", m.Settings.PaasHost, m.Settings.PaasHostVersion, m.Settings.EnvironmentID, svcID, mins), headers)
	if err != nil {
		return nil, err
	}
	var metrics models.Metrics
	err = httpclient.ConvertResp(resp, statusCode, &metrics)
	if err != nil {
		return nil, err
	}
	return &metrics, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:14,代碼來源:metrics.go

示例7: ListRoles

// ListRoles lists all available roles
func (i *SInvites) ListRoles() (*[]models.Role, error) {
	headers := httpclient.GetHeaders(i.Settings.SessionToken, i.Settings.Version, i.Settings.Pod, i.Settings.UsersID)
	resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/orgs/roles", i.Settings.AuthHost, i.Settings.AuthHostVersion), headers)
	if err != nil {
		return nil, err
	}
	var roles []models.Role
	err = httpclient.ConvertResp(resp, statusCode, &roles)
	if err != nil {
		return nil, err
	}
	return &roles, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:14,代碼來源:list.go

示例8: TempLogsURL

func (d *SDb) TempLogsURL(jobID string, serviceID string) (*models.TempURL, error) {
	headers := httpclient.GetHeaders(d.Settings.SessionToken, d.Settings.Version, d.Settings.Pod, d.Settings.UsersID)
	resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/backup-restore-logs-url/%s", d.Settings.PaasHost, d.Settings.PaasHostVersion, d.Settings.EnvironmentID, serviceID, jobID), headers)
	if err != nil {
		return nil, err
	}
	var tempURL models.TempURL
	err = httpclient.ConvertResp(resp, statusCode, &tempURL)
	if err != nil {
		return nil, err
	}
	return &tempURL, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:13,代碼來源:logs.go

示例9: Verify

// Verify verifies if a given session token is still valid or not. If it is
// valid, the returned error will be nil.
func (a *SAuth) Verify() (*models.User, error) {
	headers := httpclient.GetHeaders(a.Settings.SessionToken, a.Settings.Version, a.Settings.Pod, a.Settings.UsersID)
	resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/auth/verify", a.Settings.AuthHost, a.Settings.AuthHostVersion), headers)
	if err != nil {
		return nil, err
	}
	var user models.User
	err = httpclient.ConvertResp(resp, statusCode, &user)
	if err != nil {
		return nil, err
	}
	a.Settings.UsersID = user.UsersID
	return &user, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:16,代碼來源:signin.go

示例10: Output

func (l *SLogs) Output(queryString, sessionToken, domain string, follow bool, hours, minutes, seconds, from int, startTimestamp, endTimestamp time.Time, env *models.Environment) (int, time.Time, error) {
	appLogsIdentifier := "source"
	appLogsValue := "app"
	if strings.HasPrefix(domain, "pod01") || strings.HasPrefix(domain, "csb01") {
		appLogsIdentifier = "syslog_program"
		appLogsValue = "supervisord"
	}

	urlString := fmt.Sprintf("https://%s/__es", domain)

	headers := map[string][]string{"Cookie": {"sessionToken=" + url.QueryEscape(sessionToken)}}

	logrus.Println("        @timestamp       -        message")
	for {
		queryBytes := generateQuery(queryString, appLogsIdentifier, appLogsValue, startTimestamp, from)

		resp, statusCode, err := httpclient.Get(queryBytes, fmt.Sprintf("%s/_search", urlString), headers)
		if err != nil {
			return from, startTimestamp, err
		}
		var logs models.Logs
		err = httpclient.ConvertResp(resp, statusCode, &logs)
		if err != nil {
			return from, startTimestamp, err
		}

		end := time.Time{}
		for _, lh := range *logs.Hits.Hits {
			logrus.Printf("%s - %s", lh.Fields["@timestamp"][0], lh.Fields["message"][0])
			end, _ = time.Parse(time.RFC3339Nano, lh.Fields["@timestamp"][0])
		}
		amount := len(*logs.Hits.Hits)

		from += len(*logs.Hits.Hits)
		// TODO this will infinite loop if it always retrieves `size` hits
		// and it fails to parse the end timestamp. very small window of opportunity.
		if amount < size || end.After(endTimestamp) {
			break
		}
		time.Sleep(config.JobPollTime * time.Second)
	}
	return from, startTimestamp, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:43,代碼來源:logs.go

示例11: Retrieve

func (f *SFiles) Retrieve(fileName string, svcID string) (*models.ServiceFile, error) {
	files, err := f.List(svcID)
	if err != nil {
		return nil, err
	}
	for _, ff := range *files {
		if ff.Name == fileName {
			headers := httpclient.GetHeaders(f.Settings.SessionToken, f.Settings.Version, f.Settings.Pod, f.Settings.UsersID)
			resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/files/%d", f.Settings.PaasHost, f.Settings.PaasHostVersion, f.Settings.EnvironmentID, svcID, ff.ID), headers)
			if err != nil {
				return nil, err
			}
			var file models.ServiceFile
			err = httpclient.ConvertResp(resp, statusCode, &file)
			if err != nil {
				return nil, err
			}
			return &file, nil
		}
	}
	return nil, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:22,代碼來源:download.go

示例12: PollForStatus

func (j *SJobs) PollForStatus(statuses []string, jobID, svcID string) (string, error) {
	var job models.Job
	failedAttempts := 0
poll:
	for {
		failed := false
		headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID)
		resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs/%s", j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, jobID), headers)
		if err != nil {
			failed = true
		}
		err = httpclient.ConvertResp(resp, statusCode, &job)
		if err != nil {
			failed = true
		}
		if failed {
			failedAttempts++
		}
		s := job.Status
		switch {
		case contains(s, statuses):
			break poll
		case contains(s, []string{"scheduled", "queued", "started", "running", "stopped", "waiting"}):
			if failedAttempts >= 3 {
				return "", fmt.Errorf("Error - ended in status '%s'.", job.Status)
			}
			// all because logrus treats print, println, and printf the same
			logrus.StandardLogger().Out.Write([]byte("."))
			time.Sleep(config.JobPollTime * time.Second)
		default:
			return "", fmt.Errorf("Error - ended in status '%s'.", job.Status)
		}
	}
	if !contains(job.Status, statuses) {
		return "", fmt.Errorf("Error - ended in status '%s'.", job.Status)
	}
	return job.Status, nil
}
開發者ID:catalyzeio,項目名稱:cli,代碼行數:38,代碼來源:poll.go


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