本文整理汇总了Golang中github.com/kumoru/kumoru-sdk-go/pkg/kumoru.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Show
//Show requests account details from Kumoru and marshals the data into the Account type.
func (a *Account) Show() (*Account, *http.Response, []error) {
k := kumoru.New()
k.Get(fmt.Sprintf("%v/v1/accounts/%v", k.EndPoint.Authorization, a.Email))
k.SignRequest(true)
resp, body, errs := k.End()
if len(errs) > 0 {
return a, resp, errs
}
if resp.StatusCode >= 400 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
return a, resp, errs
}
err := json.Unmarshal([]byte(body), &a)
if err != nil {
errs = append(errs, err)
return a, resp, errs
}
return a, resp, nil
}
示例2: Show
//Show is a method on an Application which retrieves a particular Application from Kumoru.
func (a *Application) Show() (*Application, *http.Response, []error) {
k := kumoru.New()
k.Get(fmt.Sprintf("%s/v1/applications/%s", k.EndPoint.Application, a.UUID))
k.SignRequest(true)
resp, body, errs := k.End()
if len(errs) > 0 {
return a, resp, errs
}
if resp.StatusCode >= 400 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
}
err := json.Unmarshal([]byte(body), &a)
if err != nil {
errs = append(errs, fmt.Errorf("%s", err))
return a, resp, errs
}
return a, resp, nil
}
示例3: List
//List retreives all secrets a role has access to
func List() ([]*Secret, *http.Response, []error) {
apps := []*Secret{}
k := kumoru.New()
k.Get(fmt.Sprintf("%s/v1/secrets/", k.EndPoint.Authorization))
k.SignRequest(true)
resp, body, errs := k.End()
if len(errs) > 0 {
return nil, resp, errs
}
if resp.StatusCode >= 400 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
}
err := json.Unmarshal([]byte(body), &apps)
if err != nil {
errs = append(errs, fmt.Errorf("%s", err))
}
return apps, resp, nil
}
示例4: CreateAcct
//CreateAcct requests a particular account be made in Kumoru.
//It returns the updated Account.
func (a *Account) CreateAcct(password string) (*Account, *http.Response, []error) {
k := kumoru.New()
k.Put(fmt.Sprintf("%s/v1/accounts/%s", k.EndPoint.Authorization, a.Email))
k.Send(fmt.Sprintf("given_name=%s&surname=%s&password=%s", a.GivenName, a.Surname, password))
resp, body, errs := k.End()
if len(errs) > 0 {
return a, resp, errs
}
if resp.StatusCode >= 400 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
}
err := json.Unmarshal([]byte(body), &a)
if err != nil {
errs = append(errs, err)
return a, resp, errs
}
return a, resp, nil
}
示例5: Create
//Create is a method on an Application which requests that the application be drafted in Kumoru.
func (a *Application) Create() (*Application, *http.Response, []error) {
var errs []error
k := kumoru.New()
k.Post(fmt.Sprintf("%s/v1/applications/", k.EndPoint.Application))
k.TargetType = "json"
s, err := json.Marshal(*a)
if err != nil {
errs = append(errs, fmt.Errorf("%s", err))
return a, nil, errs
}
k.RawString = string(s)
k.SignRequest(true)
resp, body, errs := k.End()
if len(errs) > 0 {
return a, resp, errs
}
if resp.StatusCode >= 400 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
}
err = json.Unmarshal([]byte(body), &a)
if err != nil {
errs = append(errs, err)
return a, resp, errs
}
return a, resp, nil
}
示例6: List
// List retrieves a list of Applications a role has access to.
func List() (*http.Response, string, []error) {
k := kumoru.New()
k.Get(fmt.Sprintf("%s/v1/applications/", k.EndPoint.Application))
k.SignRequest(true)
return k.End()
}
示例7: Patch
// Patch is a method on an application which will modify an Application.
func (a *Application) Patch(certificates, name, image, metaData string, envVars, rules, ports, sslPorts []string) (*http.Response, string, []error) {
k := kumoru.New()
k.Patch(fmt.Sprintf("%s/v1/applications/%s", k.EndPoint.Application, a.UUID))
k.Send(genParameters(certificates, name, image, metaData, envVars, rules, ports, sslPorts))
k.SignRequest(true)
return k.End()
}
示例8: ResetPassword
//ResetPassword requests the password be reset for a given Account.
func (a *Account) ResetPassword() (*Account, *http.Response, []error) {
k := kumoru.New()
k.Get(fmt.Sprintf("%v/v1/accounts/%v/password/resets/", k.EndPoint.Authorization, a.Email))
resp, _, errs := k.End()
return a, resp, errs
}
示例9: GetTokens
//GetTokens generates a new token(uuid), stores this token in Kumoru and retrieves the private half of the token.
func GetTokens(username, password string) (string, *http.Response, string, []error) {
k := kumoru.New()
token := uuid.New()
k.Put(fmt.Sprintf("%v/v1/tokens/%v", k.EndPoint.Authorization, token))
k.SetBasicAuth(username, password)
resp, body, errs := k.End()
return token, resp, body, errs
}
示例10: Find
//Find is a method which will search for Locations based on inputs
func (l *Location) Find() (string, []error) {
k := kumoru.New()
k.Get(l.buildFindPath(k.EndPoint.Location))
k.SignRequest(true)
resp, body, errs := k.End()
if resp.StatusCode != 200 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
}
return string(body), errs
}
示例11: Delete
//Delete will request that a particular Location be removed
func (l *Location) Delete() []error {
k := kumoru.New()
k.Delete(fmt.Sprintf("%s/v1/locations/%s/%s", k.EndPoint.Location, l.Provider, l.Region))
k.SignRequest(true)
resp, _, errs := k.End()
if resp.StatusCode != 204 {
errs = append(errs, fmt.Errorf("s", resp.Status))
}
return errs
}
示例12: Create
//Create is a method which will request a Location be created
func (l *Location) Create() (string, []error) {
k := kumoru.New()
k.Put(fmt.Sprintf("%s/v1/locations/%s/%s", k.EndPoint.Location, l.Provider, l.Region))
k.SignRequest(true)
resp, body, errs := k.End()
if resp.StatusCode != 201 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
}
return string(body), errs
}
示例13: Patch
// Patch is a method on an application which will modify an existing Application.
func (a *Application) Patch(patchedApplication *Application) (*Application, *http.Response, []error) {
o, err := json.Marshal(a)
if err != nil {
return nil, nil, []error{err}
}
p, err := json.Marshal(patchedApplication)
if err != nil {
return nil, nil, []error{err}
}
patch, err := jsonpatch.CreatePatch([]byte(o), []byte(p))
if err != nil {
fmt.Printf("Error creating JSON patch:%v", err)
return nil, nil, []error{err}
}
patchBytes, err := json.Marshal(patch)
if err != nil {
return nil, nil, []error{err}
}
k := kumoru.New()
k.Logger.Debugf("Patch string: %s", patchBytes)
k.Patch(fmt.Sprintf("%s/v1/applications/%s", k.EndPoint.Application, a.UUID))
k.TargetType = "json-patch+json"
k.RawString = string(string(patchBytes))
k.SignRequest(true)
resp, body, errs := k.End()
if len(errs) > 0 {
return a, resp, errs
}
if resp.StatusCode >= 400 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
}
pApp := Application{}
err = json.Unmarshal([]byte(body), &pApp)
if err != nil {
errs = append(errs, err)
return a, resp, errs
}
return &pApp, resp, nil
}
示例14: Delete
//Delete is a method on a Location that will remove Kumoru resources from the provider region
func (l *Location) Delete(uuid string) (*Location, *http.Response, []error) {
k := kumoru.New()
k.Delete(fmt.Sprintf("%v/v1/pools/%s", k.EndPoint.Pool, uuid))
k.SignRequest(true)
resp, _, errs := k.End()
if errs != nil {
return l, resp, errs
}
return l, resp, nil
}
示例15: Delete
//Delete is a method on an Application which request an Application be deleted in Kumoru.
func (a *Application) Delete() (*Application, *http.Response, []error) {
k := kumoru.New()
k.Delete(fmt.Sprintf("%s/v1/applications/%s", k.EndPoint.Application, a.UUID))
k.SignRequest(true)
resp, _, errs := k.End()
if len(errs) > 0 {
return a, resp, errs
}
if resp.StatusCode >= 400 {
errs = append(errs, fmt.Errorf("%s", resp.Status))
}
return a, resp, nil
}