本文整理汇总了Golang中github.com/racker/perigee.Post函数的典型用法代码示例。如果您正苦于以下问题:Golang Post函数的具体用法?Golang Post怎么用?Golang Post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Post函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: papersPlease
// papersPlease contains the common logic between authentication and re-authentication.
// The name, obviously a joke on the process of authentication, was chosen because
// of how many other entities exist in the program containing the word Auth or Authorization.
// I didn't need another one.
func (c *Context) papersPlease(p Provider, options AuthOptions) (*Access, error) {
var access *Access
if (options.Username == "") || (options.Password == "") {
return nil, ErrCredentials
}
err := perigee.Post(p.AuthEndpoint, perigee.Options{
CustomClient: c.httpClient,
ReqBody: &AuthContainer{
Auth: Auth{
PasswordCredentials: PasswordCredentials{
Username: options.Username,
Password: options.Password,
},
TenantId: options.TenantId,
TenantName: options.TenantName,
},
},
Results: &struct {
Access **Access `json:"access"`
}{
&access,
},
})
if err == nil {
access.options = options
access.provider = p
access.context = c
}
return access, err
}
示例2: CreateFloatingIp
func (gsp *genericServersProvider) CreateFloatingIp(pool string) (FloatingIp, error) {
fip := new(FloatingIp)
err := gsp.context.WithReauth(gsp.access, func() error {
url := gsp.endpoint + "/os-floating-ips"
return perigee.Post(url, perigee.Options{
CustomClient: gsp.context.httpClient,
ReqBody: map[string]string{
"pool": pool,
},
Results: &struct {
FloatingIp **FloatingIp `json:"floating_ip"`
}{&fip},
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
})
})
if fip.Ip == "" {
return *fip, errors.New("Error creating floating IP")
}
return *fip, err
}
示例3: Authenticate
// Authenticate attempts to verify this Identity object's credentials.
func (id *identity) Authenticate() error {
creds := &AuthContainer{
Auth: Auth{
PasswordCredentials: PasswordCredentials{
Username: id.username,
Password: id.password,
},
},
}
err := perigee.Post(id.AuthEndpoint(), perigee.Options{
CustomClient: id.httpClient,
ReqBody: creds,
Results: &id.access,
})
if err != nil {
return err
}
id.isAuthenticated = true
id.token = id.access.Access.Token.Id
id.expires = id.access.Access.Token.Expires
id.tenantId = id.access.Access.Token.Tenant.Id
id.tenantName = id.access.Access.Token.Tenant.Name
return nil
}
示例4: RevertResizeServer
// RevertResizeServer will reject a server's resized configuration, thus
// rolling back to the original server.
func (r *raxRegion) RevertResizeServer(id string) error {
baseUrl, err := r.EndpointByName("servers")
serverUrl := fmt.Sprintf("%s/%s/action", baseUrl, id)
err = perigee.Post(serverUrl, perigee.Options{
ReqBody: &struct {
RevertResize *int `json:"revertResize"`
}{nil},
OkCodes: []int{204},
MoreHeaders: map[string]string{
"X-Auth-Token": r.token,
},
})
return err
}
示例5: UnrescueServer
// See the CloudServersProvider interface for details
func (gsp *genericServersProvider) UnrescueServer(id string) error {
return gsp.context.WithReauth(gsp.access, func() error {
url := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, id)
return perigee.Post(url, perigee.Options{
ReqBody: &struct {
Unrescue *int `json:"unrescue"`
}{nil},
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
OkCodes: []int{202},
})
})
}
示例6: AssociateFloatingIp
func (gsp *genericServersProvider) AssociateFloatingIp(serverId string, ip FloatingIp) error {
return gsp.context.WithReauth(gsp.access, func() error {
ep := fmt.Sprintf("%s/servers/%s/action", gsp.endpoint, serverId)
return perigee.Post(ep, perigee.Options{
CustomClient: gsp.context.httpClient,
ReqBody: map[string](map[string]string){
"addFloatingIp": map[string]string{"address": ip.Ip},
},
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
OkCodes: []int{202},
})
})
}
示例7: CreateDefaultSGRule
// See the CloudServersProvider interface for details.
func (gsp *genericServersProvider) CreateDefaultSGRule(r SGRule) (*SGRule, error) {
var sgr *SGRule
err := gsp.context.WithReauth(gsp.access, func() error {
ep := fmt.Sprintf("%s/os-security-group-default-rules", gsp.endpoint)
return perigee.Post(ep, perigee.Options{
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
Results: &struct{ Security_group_default_rule **SGRule }{&sgr},
ReqBody: struct {
Security_group_default_rule SGRule `json:"security_group_default_rule"`
}{r},
})
})
return sgr, err
}
示例8: AssociateMonitor
func (gnp *genericNetworksProvider) AssociateMonitor(monitorId string, poolId string) error {
monitor := Monitor{Id: monitorId}
ep := gnp.endpoint + "/v2.0/lb/pools/" + poolId + "/health_monitors"
err := perigee.Post(ep, perigee.Options{
ReqBody: &struct {
Monitor *Monitor `json:"health_monitor"`
}{&monitor},
MoreHeaders: map[string]string{
"X-Auth-Token": gnp.access.AuthToken(),
},
OkCodes: []int{201},
})
return err
}
示例9: CreateSubnet
func (gnp *genericNetworksProvider) CreateSubnet(ns NewSubnet) (*Subnet, error) {
var s *Subnet
ep := gnp.endpoint + "/v2.0/subnets"
err := perigee.Post(ep, perigee.Options{
ReqBody: &struct {
NewSubnet *NewSubnet `json:"subnet"`
}{&ns},
Results: &struct{ Subnet **Subnet }{&s},
MoreHeaders: map[string]string{
"X-Auth-Token": gnp.access.AuthToken(),
},
OkCodes: []int{201},
})
return s, err
}
示例10: CreateVip
func (gnp *genericNetworksProvider) CreateVip(newVip NewVip) (*Vip, error) {
var vip *Vip
ep := gnp.endpoint + "/v2.0/lb/vips"
err := perigee.Post(ep, perigee.Options{
ReqBody: &struct {
NewVip *NewVip `json:"vip"`
}{&newVip},
Results: &struct{ Vip **Vip }{&vip},
MoreHeaders: map[string]string{
"X-Auth-Token": gnp.access.AuthToken(),
},
OkCodes: []int{201},
})
return vip, err
}
示例11: CreateMember
func (gnp *genericNetworksProvider) CreateMember(newMember NewMember) (*Member, error) {
var member *Member
ep := gnp.endpoint + "/v2.0/lb/members"
err := perigee.Post(ep, perigee.Options{
ReqBody: &struct {
NewMember *NewMember `json:"member"`
}{&newMember},
Results: &struct{ Member **Member }{&member},
MoreHeaders: map[string]string{
"X-Auth-Token": gnp.access.AuthToken(),
},
OkCodes: []int{201},
})
return member, err
}
示例12: CreatePool
func (gnp *genericNetworksProvider) CreatePool(newPool NewPool) (*Pool, error) {
var pool *Pool
ep := gnp.endpoint + "/v2.0/lb/pools"
err := perigee.Post(ep, perigee.Options{
ReqBody: &struct {
NewPool *NewPool `json:"pool"`
}{&newPool},
Results: &struct{ Pool **Pool }{&pool},
MoreHeaders: map[string]string{
"X-Auth-Token": gnp.access.AuthToken(),
},
OkCodes: []int{201},
})
return pool, err
}
示例13: CreateNetwork
func (gnp *genericNetworksProvider) CreateNetwork(nn NewNetwork) (*Network, error) {
var n *Network
ep := gnp.endpoint + "/v2.0/networks"
err := perigee.Post(ep, perigee.Options{
ReqBody: &struct {
NewNetwork *NewNetwork `json:"network"`
}{&nn},
Results: &struct{ Network **Network }{&n},
MoreHeaders: map[string]string{
"X-Auth-Token": gnp.access.AuthToken(),
},
OkCodes: []int{201},
})
return n, err
}
示例14: CreateSecurityGroupRule
func (gnp *genericNetworksProvider) CreateSecurityGroupRule(nsgr SecurityGroupRule) (*SecurityGroupRule, error) {
var sgr *SecurityGroupRule
ep := gnp.endpoint + "/v2.0/security-group-rules"
err := perigee.Post(ep, perigee.Options{
ReqBody: &struct {
SecurityGroupRule *SecurityGroupRule `json:"security_group_rule"`
}{&nsgr},
Results: &struct{ SecurityGroupRule **SecurityGroupRule }{&sgr},
MoreHeaders: map[string]string{
"X-Auth-Token": gnp.access.AuthToken(),
},
OkCodes: []int{201},
})
return sgr, err
}
示例15: CreateKeyPair
func (gsp *genericServersProvider) CreateKeyPair(nkp NewKeyPair) (KeyPair, error) {
var kp KeyPair
err := gsp.context.WithReauth(gsp.access, func() error {
url := gsp.endpoint + "/os-keypairs"
return perigee.Post(url, perigee.Options{
ReqBody: &struct {
KeyPair *NewKeyPair `json:"keypair"`
}{&nkp},
CustomClient: gsp.context.httpClient,
Results: &struct{ KeyPair *KeyPair }{&kp},
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
})
})
return kp, err
}