本文整理汇总了Golang中github.com/rackspace/gophercloud.MaybeString函数的典型用法代码示例。如果您正苦于以下问题:Golang MaybeString函数的具体用法?Golang MaybeString怎么用?Golang MaybeString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MaybeString函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Update
// Update changes an existing endpoint with new data.
// All fields are optional in the provided EndpointOpts.
func Update(client *gophercloud.ServiceClient, endpointID string, opts EndpointOpts) UpdateResult {
type endpoint struct {
Interface *string `json:"interface,omitempty"`
Name *string `json:"name,omitempty"`
Region *string `json:"region,omitempty"`
URL *string `json:"url,omitempty"`
ServiceID *string `json:"service_id,omitempty"`
}
type request struct {
Endpoint endpoint `json:"endpoint"`
}
reqBody := request{Endpoint: endpoint{}}
reqBody.Endpoint.Interface = gophercloud.MaybeString(string(opts.Availability))
reqBody.Endpoint.Name = gophercloud.MaybeString(opts.Name)
reqBody.Endpoint.Region = gophercloud.MaybeString(opts.Region)
reqBody.Endpoint.URL = gophercloud.MaybeString(opts.URL)
reqBody.Endpoint.ServiceID = gophercloud.MaybeString(opts.ServiceID)
var result UpdateResult
_, result.Err = client.Request("PATCH", endpointURL(client, endpointID), gophercloud.RequestOpts{
JSONBody: &reqBody,
JSONResponse: &result.Body,
OkCodes: []int{200},
})
return result
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:30,代码来源:requests.go
示例2: Create
// Create accepts a CreateOpts struct and uses the values to create a new
// logical router. When it is created, the router does not have an internal
// interface - it is not associated to any subnet.
//
// You can optionally specify an external gateway for a router using the
// GatewayInfo struct. The external gateway for the router must be plugged into
// an external network (it is external if its `router:external' field is set to
// true).
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
type router struct {
Name *string `json:"name,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
TenantID *string `json:"tenant_id,omitempty"`
GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"`
}
type request struct {
Router router `json:"router"`
}
reqBody := request{Router: router{
Name: gophercloud.MaybeString(opts.Name),
AdminStateUp: opts.AdminStateUp,
TenantID: gophercloud.MaybeString(opts.TenantID),
}}
if opts.GatewayInfo != nil {
reqBody.Router.GatewayInfo = opts.GatewayInfo
}
var res CreateResult
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
OkCodes: []int{201},
})
return res
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:39,代码来源:requests.go
示例3: Create
// Create accepts a CreateOpts struct and uses the values to create a new
// logical router. When it is created, the router does not have an internal
// interface - it is not associated to any subnet.
//
// You can optionally specify an external gateway for a router using the
// GatewayInfo struct. The external gateway for the router must be plugged into
// an external network (it is external if its `router:external' field is set to
// true).
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
type router struct {
Name *string `json:"name,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
TenantID *string `json:"tenant_id,omitempty"`
GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"`
}
type request struct {
Router router `json:"router"`
}
reqBody := request{Router: router{
Name: gophercloud.MaybeString(opts.Name),
AdminStateUp: opts.AdminStateUp,
TenantID: gophercloud.MaybeString(opts.TenantID),
}}
if opts.GatewayInfo != nil {
reqBody.Router.GatewayInfo = opts.GatewayInfo
}
var res CreateResult
_, res.Err = c.Post(rootURL(c), reqBody, &res.Body, nil)
return res
}
开发者ID:metalmolly,项目名称:packer,代码行数:34,代码来源:requests.go
示例4: ToRouterCreateMap
// ToRouterCreateMap casts a routerCreateOpts struct to a map.
func (opts RouterCreateOpts) ToRouterCreateMap() (map[string]interface{}, error) {
r := make(map[string]interface{})
if gophercloud.MaybeString(opts.Name) != nil {
r["name"] = opts.Name
}
if opts.AdminStateUp != nil {
r["admin_state_up"] = opts.AdminStateUp
}
if opts.Distributed != nil {
r["distributed"] = opts.Distributed
}
if gophercloud.MaybeString(opts.TenantID) != nil {
r["tenant_id"] = opts.TenantID
}
if opts.GatewayInfo != nil {
r["external_gateway_info"] = opts.GatewayInfo
}
if opts.ValueSpecs != nil {
for k, v := range opts.ValueSpecs {
r[k] = v
}
}
return map[string]interface{}{"router": r}, nil
}
开发者ID:Zordrak,项目名称:terraform,代码行数:32,代码来源:resource_openstack_networking_router_v2.go
示例5: Update
// Update allows routers to be updated. You can update the name, administrative
// state, and the external gateway. For more information about how to set the
// external gateway for a router, see Create. This operation does not enable
// the update of router interfaces. To do this, use the AddInterface and
// RemoveInterface functions.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
type router struct {
Name *string `json:"name,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"`
}
type request struct {
Router router `json:"router"`
}
reqBody := request{Router: router{
Name: gophercloud.MaybeString(opts.Name),
AdminStateUp: opts.AdminStateUp,
}}
if opts.GatewayInfo != nil {
reqBody.Router.GatewayInfo = opts.GatewayInfo
}
// Send request to API
var res UpdateResult
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
OkCodes: []int{200},
})
return res
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:36,代码来源:requests.go
示例6: Update
// Update allows routers to be updated. You can update the name, administrative
// state, and the external gateway. For more information about how to set the
// external gateway for a router, see Create. This operation does not enable
// the update of router interfaces. To do this, use the AddInterface and
// RemoveInterface functions.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
type router struct {
Name *string `json:"name,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
GatewayInfo *GatewayInfo `json:"external_gateway_info,omitempty"`
Routes []Route `json:"routes"`
}
type request struct {
Router router `json:"router"`
}
reqBody := request{Router: router{
Name: gophercloud.MaybeString(opts.Name),
AdminStateUp: opts.AdminStateUp,
}}
if opts.GatewayInfo != nil {
reqBody.Router.GatewayInfo = opts.GatewayInfo
}
if opts.Routes != nil {
reqBody.Router.Routes = opts.Routes
}
// Send request to API
var res UpdateResult
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return res
}
开发者ID:metalmolly,项目名称:packer,代码行数:38,代码来源:requests.go
示例7: Update
// Update is an operation which modifies the attributes of the specified VIP.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
type vip struct {
Name string `json:"name,omitempty"`
PoolID string `json:"pool_id,omitempty"`
Description *string `json:"description,omitempty"`
Persistence *SessionPersistence `json:"session_persistence,omitempty"`
ConnLimit *int `json:"connection_limit,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
type request struct {
VirtualIP vip `json:"vip"`
}
reqBody := request{VirtualIP: vip{
Name: opts.Name,
PoolID: opts.PoolID,
Description: gophercloud.MaybeString(opts.Description),
ConnLimit: opts.ConnLimit,
AdminStateUp: opts.AdminStateUp,
}}
if opts.Persistence != nil {
reqBody.VirtualIP.Persistence = opts.Persistence
}
var res UpdateResult
_, res.Err = c.Put(resourceURL(c, id), reqBody, &res.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 202},
})
return res
}
开发者ID:40a,项目名称:bootkube,代码行数:34,代码来源:requests.go
示例8: Update
// Update is an operation which modifies the attributes of the specified monitor.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
var res UpdateResult
if opts.Delay > 0 && opts.Timeout > 0 && opts.Delay < opts.Timeout {
res.Err = errDelayMustGETimeout
}
type monitor struct {
Delay int `json:"delay"`
Timeout int `json:"timeout"`
MaxRetries int `json:"max_retries"`
URLPath *string `json:"url_path,omitempty"`
ExpectedCodes *string `json:"expected_codes,omitempty"`
HTTPMethod *string `json:"http_method,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
type request struct {
Monitor monitor `json:"health_monitor"`
}
reqBody := request{Monitor: monitor{
Delay: opts.Delay,
Timeout: opts.Timeout,
MaxRetries: opts.MaxRetries,
URLPath: gophercloud.MaybeString(opts.URLPath),
ExpectedCodes: gophercloud.MaybeString(opts.ExpectedCodes),
HTTPMethod: gophercloud.MaybeString(opts.HTTPMethod),
AdminStateUp: opts.AdminStateUp,
}}
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
OkCodes: []int{200, 202},
})
return res
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:41,代码来源:requests.go
示例9: Create
// Create inserts a new Endpoint into the service catalog.
// Within EndpointOpts, Region may be omitted by being left as "", but all other fields are required.
func Create(client *gophercloud.ServiceClient, opts EndpointOpts) CreateResult {
// Redefined so that Region can be re-typed as a *string, which can be omitted from the JSON output.
type endpoint struct {
Interface string `json:"interface"`
Name string `json:"name"`
Region *string `json:"region,omitempty"`
URL string `json:"url"`
ServiceID string `json:"service_id"`
}
type request struct {
Endpoint endpoint `json:"endpoint"`
}
// Ensure that EndpointOpts is fully populated.
if opts.Availability == "" {
return createErr(ErrAvailabilityRequired)
}
if opts.Name == "" {
return createErr(ErrNameRequired)
}
if opts.URL == "" {
return createErr(ErrURLRequired)
}
if opts.ServiceID == "" {
return createErr(ErrServiceIDRequired)
}
// Populate the request body.
reqBody := request{
Endpoint: endpoint{
Interface: string(opts.Availability),
Name: opts.Name,
URL: opts.URL,
ServiceID: opts.ServiceID,
},
}
reqBody.Endpoint.Region = gophercloud.MaybeString(opts.Region)
var result CreateResult
_, result.Err = perigee.Request("POST", listURL(client), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &result.Body,
OkCodes: []int{201},
})
return result
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:50,代码来源:requests.go
示例10: Create
// Create is an operation which provisions a new health monitor. There are
// different types of monitor you can provision: PING, TCP or HTTP(S). Below
// are examples of how to create each one.
//
// Here is an example config struct to use when creating a PING or TCP monitor:
//
// CreateOpts{Type: TypePING, Delay: 20, Timeout: 10, MaxRetries: 3}
// CreateOpts{Type: TypeTCP, Delay: 20, Timeout: 10, MaxRetries: 3}
//
// Here is an example config struct to use when creating a HTTP(S) monitor:
//
// CreateOpts{Type: TypeHTTP, Delay: 20, Timeout: 10, MaxRetries: 3,
// HttpMethod: "HEAD", ExpectedCodes: "200"}
//
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
var res CreateResult
// Validate inputs
allowed := map[string]bool{TypeHTTP: true, TypeHTTPS: true, TypeTCP: true, TypePING: true}
if opts.Type == "" || allowed[opts.Type] == false {
res.Err = errValidTypeRequired
}
if opts.Delay == 0 {
res.Err = errDelayRequired
}
if opts.Timeout == 0 {
res.Err = errTimeoutRequired
}
if opts.MaxRetries == 0 {
res.Err = errMaxRetriesRequired
}
if opts.Type == TypeHTTP || opts.Type == TypeHTTPS {
if opts.URLPath == "" {
res.Err = errURLPathRequired
}
if opts.ExpectedCodes == "" {
res.Err = errExpectedCodesRequired
}
}
if opts.Delay < opts.Timeout {
res.Err = errDelayMustGETimeout
}
if res.Err != nil {
return res
}
type monitor struct {
Type string `json:"type"`
Delay int `json:"delay"`
Timeout int `json:"timeout"`
MaxRetries int `json:"max_retries"`
TenantID *string `json:"tenant_id,omitempty"`
URLPath *string `json:"url_path,omitempty"`
ExpectedCodes *string `json:"expected_codes,omitempty"`
HTTPMethod *string `json:"http_method,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
type request struct {
Monitor monitor `json:"health_monitor"`
}
reqBody := request{Monitor: monitor{
Type: opts.Type,
Delay: opts.Delay,
Timeout: opts.Timeout,
MaxRetries: opts.MaxRetries,
TenantID: gophercloud.MaybeString(opts.TenantID),
URLPath: gophercloud.MaybeString(opts.URLPath),
ExpectedCodes: gophercloud.MaybeString(opts.ExpectedCodes),
HTTPMethod: gophercloud.MaybeString(opts.HTTPMethod),
AdminStateUp: opts.AdminStateUp,
}}
_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
JSONBody: &reqBody,
JSONResponse: &res.Body,
OkCodes: []int{201},
})
return res
}
开发者ID:rtgoodwin,项目名称:cs-reboot-info,代码行数:82,代码来源:requests.go
示例11: Create
// Create is an operation which provisions a new virtual IP based on the
// configuration defined in the CreateOpts struct. Once the request is
// validated and progress has started on the provisioning process, a
// CreateResult will be returned.
//
// Please note that the PoolID should refer to a pool that is not already
// associated with another vip. If the pool is already used by another vip,
// then the operation will fail with a 409 Conflict error will be returned.
//
// Users with an admin role can create VIPs on behalf of other tenants by
// specifying a TenantID attribute different than their own.
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
var res CreateResult
// Validate required opts
if opts.Name == "" {
res.Err = errNameRequired
return res
}
if opts.SubnetID == "" {
res.Err = errSubnetIDRequried
return res
}
if opts.Protocol == "" {
res.Err = errProtocolRequired
return res
}
if opts.ProtocolPort == 0 {
res.Err = errProtocolPortRequired
return res
}
if opts.PoolID == "" {
res.Err = errPoolIDRequired
return res
}
type vip struct {
Name string `json:"name"`
SubnetID string `json:"subnet_id"`
Protocol string `json:"protocol"`
ProtocolPort int `json:"protocol_port"`
PoolID string `json:"pool_id"`
Description *string `json:"description,omitempty"`
TenantID *string `json:"tenant_id,omitempty"`
Address *string `json:"address,omitempty"`
Persistence *SessionPersistence `json:"session_persistence,omitempty"`
ConnLimit *int `json:"connection_limit,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
}
type request struct {
VirtualIP vip `json:"vip"`
}
reqBody := request{VirtualIP: vip{
Name: opts.Name,
SubnetID: opts.SubnetID,
Protocol: opts.Protocol,
ProtocolPort: opts.ProtocolPort,
PoolID: opts.PoolID,
Description: gophercloud.MaybeString(opts.Description),
TenantID: gophercloud.MaybeString(opts.TenantID),
Address: gophercloud.MaybeString(opts.Address),
ConnLimit: opts.ConnLimit,
AdminStateUp: opts.AdminStateUp,
}}
if opts.Persistence != nil {
reqBody.VirtualIP.Persistence = opts.Persistence
}
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res.Body,
OkCodes: []int{201},
})
return res
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:80,代码来源:requests.go
注:本文中的github.com/rackspace/gophercloud.MaybeString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论