本文整理汇总了Golang中github.com/catalyzeio/cli/lib/httpclient.GetHeaders函数的典型用法代码示例。如果您正苦于以下问题:Golang GetHeaders函数的具体用法?Golang GetHeaders怎么用?Golang GetHeaders使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetHeaders函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Create
func (f *SFiles) Create(svcID, filePath, name, mode string) (*models.ServiceFile, error) {
b, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}
sf := models.ServiceFile{
Contents: string(b),
GID: 0,
Mode: mode,
Name: name,
UID: 0,
EnableDownload: true,
}
body, err := json.Marshal(sf)
if err != nil {
return nil, err
}
headers := httpclient.GetHeaders(f.Settings.SessionToken, f.Settings.Version, f.Settings.Pod, f.Settings.UsersID)
resp, statusCode, err := httpclient.Post(body, fmt.Sprintf("%s%s/environments/%s/services/%s/files", f.Settings.PaasHost, f.Settings.PaasHostVersion, f.Settings.EnvironmentID, svcID), headers)
if err != nil {
return nil, err
}
var svcFile models.ServiceFile
err = httpclient.ConvertResp(resp, statusCode, &svcFile)
if err != nil {
return nil, err
}
return &svcFile, nil
}
示例2: signInWithCredentials
func (a *SAuth) signInWithCredentials() (*signinResponse, error) {
login := models.Login{
Identifier: a.Settings.Username,
Password: a.Settings.Password,
}
if a.Settings.Username == "" || a.Settings.Password == "" {
username, password, err := a.Prompts.UsernamePassword()
if err != nil {
return nil, err
}
login = models.Login{
Identifier: username,
Password: password,
}
}
b, err := json.Marshal(login)
if err != nil {
return nil, err
}
headers := httpclient.GetHeaders(a.Settings.SessionToken, a.Settings.Version, a.Settings.Pod, a.Settings.UsersID)
resp, statusCode, err := httpclient.Post(b, fmt.Sprintf("%s%s/auth/signin", a.Settings.AuthHost, a.Settings.AuthHostVersion), headers)
if err != nil {
return nil, err
}
signinResp := &signinResponse{}
return signinResp, httpclient.ConvertResp(resp, statusCode, signinResp)
}
示例3: Signout
// Signout signs out a user by their session token.
func (a *SAuth) Signout() error {
headers := httpclient.GetHeaders(a.Settings.SessionToken, a.Settings.Version, a.Settings.Pod, a.Settings.UsersID)
resp, statusCode, err := httpclient.Delete(nil, fmt.Sprintf("%s%s/auth/signout", a.Settings.AuthHost, a.Settings.AuthHostVersion), headers)
if err != nil {
return err
}
return httpclient.ConvertResp(resp, statusCode, nil)
}
示例4: Rm
func (r *SReleases) Rm(releaseName, svcID string) error {
headers := httpclient.GetHeaders(r.Settings.SessionToken, r.Settings.Version, r.Settings.Pod, r.Settings.UsersID)
resp, statusCode, err := httpclient.Delete(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/releases/%s", r.Settings.PaasHost, r.Settings.PaasHostVersion, r.Settings.EnvironmentID, svcID, releaseName), headers)
if err != nil {
return err
}
return httpclient.ConvertResp(resp, statusCode, nil)
}
示例5: Delete
func (j *SJobs) Delete(jobID, svcID string) error {
headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID)
resp, statusCode, err := httpclient.Delete(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 {
return err
}
return httpclient.ConvertResp(resp, statusCode, nil)
}
示例6: Unset
// Unset deletes an environment variable. Any changes to environment variables
// will not take effect until the service is redeployed by pushing new code
// or via `catalyze redeploy`.
func (v *SVars) Unset(svcID, variable string) error {
headers := httpclient.GetHeaders(v.Settings.SessionToken, v.Settings.Version, v.Settings.Pod, v.Settings.UsersID)
resp, statusCode, err := httpclient.Delete(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/env/%s", v.Settings.PaasHost, v.Settings.PaasHostVersion, v.Settings.EnvironmentID, svcID, variable), headers)
if err != nil {
return err
}
return httpclient.ConvertResp(resp, statusCode, nil)
}
示例7: 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
}
示例8: Remove
func (k *SKeys) Remove(name string) error {
headers := httpclient.GetHeaders(k.Settings.SessionToken, k.Settings.Version, k.Settings.Pod, k.Settings.UsersID)
resp, status, err := httpclient.Delete(nil, fmt.Sprintf("%s%s/keys/%s", k.Settings.AuthHost, k.Settings.AuthHostVersion, name), headers)
if err != nil {
return err
}
if httpclient.IsError(status) {
return httpclient.ConvertError(resp, status)
}
return nil
}
示例9: Set
// Set adds a new environment variables or updates the value of an existing
// environment variables. Any changes to environment variables will not take
// effect until the service is redeployed by pushing new code or via
// `catalyze redeploy`.
func (v *SVars) Set(svcID string, envVarsMap map[string]string) error {
b, err := json.Marshal(envVarsMap)
if err != nil {
return err
}
headers := httpclient.GetHeaders(v.Settings.SessionToken, v.Settings.Version, v.Settings.Pod, v.Settings.UsersID)
resp, statusCode, err := httpclient.Post(b, fmt.Sprintf("%s%s/environments/%s/services/%s/env", v.Settings.PaasHost, v.Settings.PaasHostVersion, v.Settings.EnvironmentID, svcID), headers)
if err != nil {
return err
}
return httpclient.ConvertResp(resp, statusCode, nil)
}
示例10: Update
func (e *SEnvironments) Update(envID string, updates map[string]string) error {
b, err := json.Marshal(updates)
if err != nil {
return err
}
headers := httpclient.GetHeaders(e.Settings.SessionToken, e.Settings.Version, e.Settings.Pod, e.Settings.UsersID)
resp, statusCode, err := httpclient.Put(b, fmt.Sprintf("%s%s/environments/%s", e.Settings.PaasHost, e.Settings.PaasHostVersion, envID), headers)
if err != nil {
return err
}
return httpclient.ConvertResp(resp, statusCode, nil)
}
示例11: Update
func (w *SWorker) Update(svcID string, workers *models.Workers) error {
b, err := json.Marshal(workers)
if err != nil {
return err
}
headers := httpclient.GetHeaders(w.Settings.SessionToken, w.Settings.Version, w.Settings.Pod, w.Settings.UsersID)
resp, statusCode, err := httpclient.Post(b, fmt.Sprintf("%s%s/environments/%s/services/%s/workers", w.Settings.PaasHost, w.Settings.PaasHostVersion, w.Settings.EnvironmentID, svcID), headers)
if err != nil {
return err
}
return httpclient.ConvertResp(resp, statusCode, nil)
}
示例12: signInWithKey
func (a *SAuth) signInWithKey() (*signinResponse, error) {
body := struct {
PublicKey string `json:"publicKey"`
Signature string `json:"signature"`
}{}
bytes, err := ioutil.ReadFile(a.Settings.PrivateKeyPath)
if err != nil {
return nil, err
}
block, _ := pem.Decode(bytes)
if block == nil {
return nil, errors.New("Private key is not PEM-encoded")
}
bytes = block.Bytes
if x509.IsEncryptedPEMBlock(block) {
passphrase := a.Prompts.KeyPassphrase(a.Settings.PrivateKeyPath)
bytes, err = x509.DecryptPEMBlock(block, []byte(passphrase))
if err != nil {
return nil, err
}
}
privateKey, err := x509.ParsePKCS1PrivateKey(bytes)
if err != nil {
return nil, err
}
publicKey, err := ioutil.ReadFile(a.Settings.PrivateKeyPath + ".pub")
if err != nil {
return nil, err
}
body.PublicKey = string(publicKey)
headers := httpclient.GetHeaders(a.Settings.SessionToken, a.Settings.Version, a.Settings.Pod, a.Settings.UsersID)
message := fmt.Sprintf("%s&%s", headers["X-Request-Nonce"][0], headers["X-Request-Timestamp"][0])
hashedMessage := sha256.Sum256([]byte(message))
signature, err := privateKey.Sign(rand.Reader, hashedMessage[:], crypto.SHA256)
if err != nil {
return nil, err
}
body.Signature = base64.StdEncoding.EncodeToString(signature)
b, err := json.Marshal(body)
if err != nil {
return nil, err
}
resp, statusCode, err := httpclient.Post(b, fmt.Sprintf("%s%s/auth/signin/key", a.Settings.AuthHost, a.Settings.AuthHostVersion), headers)
if err != nil {
return nil, err
}
signinResp := &signinResponse{}
return signinResp, httpclient.ConvertResp(resp, statusCode, signinResp)
}
示例13: 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
}
示例14: 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
}
示例15: 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
}