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


Golang ServiceClient.Request方法代碼示例

本文整理匯總了Golang中github.com/rackspace/gophercloud.ServiceClient.Request方法的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceClient.Request方法的具體用法?Golang ServiceClient.Request怎麽用?Golang ServiceClient.Request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/rackspace/gophercloud.ServiceClient的用法示例。


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

示例1: Delete

// Delete deletes the interface with interfaceID attached to the instance with
// instanceID.
func Delete(c *gophercloud.ServiceClient, instanceID, interfaceID string) DeleteResult {
	var res DeleteResult
	_, res.Err = c.Request("DELETE", deleteURL(c, instanceID, interfaceID), gophercloud.RequestOpts{
		OkCodes: []int{200, 204},
	})
	return res
}
開發者ID:rtgoodwin,項目名稱:cs-reboot-info,代碼行數:9,代碼來源:requests.go

示例2: Get

// Get is a function that retrieves an account's metadata. To extract just the
// custom metadata, call the ExtractMetadata method on the GetResult. To extract
// all the headers that are returned (including the metadata), call the
// ExtractHeader method on the GetResult.
func Get(c *gophercloud.ServiceClient, opts GetOptsBuilder) GetResult {
	var res GetResult
	h := c.AuthenticatedHeaders()

	if opts != nil {
		headers, err := opts.ToAccountGetMap()
		if err != nil {
			res.Err = err
			return res
		}

		for k, v := range headers {
			h[k] = v
		}
	}

	resp, err := c.Request("HEAD", getURL(c), gophercloud.RequestOpts{
		MoreHeaders: h,
		OkCodes:     []int{204},
	})
	if resp != nil {
		res.Header = resp.Header
	}
	res.Err = err
	return res
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:30,代碼來源:requests.go

示例3: Delete

// Delete is the operation responsible for permanently deleting a VIP.
func Delete(c *gophercloud.ServiceClient, lbID, vipID int) DeleteResult {
	var res DeleteResult
	_, res.Err = c.Request("DELETE", resourceURL(c, lbID, vipID), gophercloud.RequestOpts{
		OkCodes: []int{202},
	})
	return res
}
開發者ID:rtgoodwin,項目名稱:cs-reboot-info,代碼行數:8,代碼來源:requests.go

示例4: 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

示例5: Update

// Update is a function that creates, updates, or deletes an object's metadata.
func Update(c *gophercloud.ServiceClient, containerName, objectName string, opts UpdateOptsBuilder) UpdateResult {
	var res UpdateResult
	h := c.AuthenticatedHeaders()

	if opts != nil {
		headers, err := opts.ToObjectUpdateMap()
		if err != nil {
			res.Err = err
			return res
		}

		for k, v := range headers {
			h[k] = v
		}
	}

	url := updateURL(c, containerName, objectName)
	resp, err := c.Request("POST", url, gophercloud.RequestOpts{
		MoreHeaders: h,
	})
	if resp != nil {
		res.Header = resp.Header
	}
	res.Err = err
	return res
}
開發者ID:CorainChicago,項目名稱:gophercloud,代碼行數:27,代碼來源:requests.go

示例6: GetPassword

// GetPassword makes a request against the nova API to get the encrypted administrative password.
func GetPassword(client *gophercloud.ServiceClient, serverId string) GetPasswordResult {
	var res GetPasswordResult
	_, res.Err = client.Request("GET", passwordURL(client, serverId), gophercloud.RequestOpts{
		JSONResponse: &res.Body,
	})
	return res
}
開發者ID:40a,項目名稱:bootkube,代碼行數:8,代碼來源:requests.go

示例7: Get

// Get retreives data for the given stack template.
func Get(c *gophercloud.ServiceClient, stackName, stackID string) GetResult {
	var res GetResult
	_, res.Err = c.Request("GET", getURL(c, stackName, stackID), gophercloud.RequestOpts{
		JSONResponse: &res.Body,
	})
	return res
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:8,代碼來源:requests.go

示例8: Create

// Create is a function that creates a new object or replaces an existing object.
func Create(c *gophercloud.ServiceClient, containerName, objectName string, content io.ReadSeeker, opts CreateOptsBuilder) CreateResult {
	var res CreateResult

	url := createURL(c, containerName, objectName)
	h := make(map[string]string)

	if opts != nil {
		headers, query, err := opts.ToObjectCreateParams()
		if err != nil {
			res.Err = err
			return res
		}

		for k, v := range headers {
			h[k] = v
		}

		url += query
	}

	ropts := gophercloud.RequestOpts{
		RawBody:     content,
		MoreHeaders: h,
	}

	resp, err := c.Request("PUT", url, ropts)
	if resp != nil {
		res.Header = resp.Header
	}
	res.Err = err
	return res
}
開發者ID:CorainChicago,項目名稱:gophercloud,代碼行數:33,代碼來源:requests.go

示例9: Delete

// Delete is a function that deletes a container.
func Delete(c *gophercloud.ServiceClient, containerName string) DeleteResult {
	var res DeleteResult
	_, res.Err = c.Request("DELETE", deleteURL(c, containerName), gophercloud.RequestOpts{
		OkCodes: []int{202, 204},
	})
	return res
}
開發者ID:rtgoodwin,項目名稱:cs-reboot-info,代碼行數:8,代碼來源:requests.go

示例10: Create

// Create is a function that creates a new container.
func Create(c *gophercloud.ServiceClient, containerName string, opts CreateOptsBuilder) CreateResult {
	var res CreateResult
	h := make(map[string]string)

	if opts != nil {
		headers, err := opts.ToContainerCreateMap()
		if err != nil {
			res.Err = err
			return res
		}

		for k, v := range headers {
			h[k] = v
		}
	}

	resp, err := c.Request("PUT", createURL(c, containerName), gophercloud.RequestOpts{
		MoreHeaders: h,
		OkCodes:     []int{201, 202, 204},
	})
	if resp != nil {
		res.Header = resp.Header
	}
	res.Err = err
	return res
}
開發者ID:Originate,項目名稱:terraform,代碼行數:27,代碼來源:requests.go

示例11: Update

// Update allows floating IP resources to be updated. Currently, the only way to
// "update" a floating IP is to associate it with a new internal port, or
// disassociated it from all ports. See UpdateOpts for instructions of how to
// do this.
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
	type floatingIP struct {
		PortID *string `json:"port_id"`
	}

	type request struct {
		FloatingIP floatingIP `json:"floatingip"`
	}

	var portID *string
	if opts.PortID == "" {
		portID = nil
	} else {
		portID = &opts.PortID
	}

	reqBody := request{FloatingIP: floatingIP{PortID: portID}}

	// Send request to API
	var res UpdateResult
	_, res.Err = c.Request("PUT", resourceURL(c, id), gophercloud.RequestOpts{
		JSONBody:     &reqBody,
		JSONResponse: &res.Body,
		OkCodes:      []int{200},
	})

	return res
}
開發者ID:rtgoodwin,項目名稱:cs-reboot-info,代碼行數:32,代碼來源:requests.go

示例12: Create

// Create accepts a CreateOpts struct and uses the values to create a new
// load balancer pool member.
func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
	type member struct {
		TenantID     string `json:"tenant_id,omitempty"`
		ProtocolPort int    `json:"protocol_port"`
		Address      string `json:"address"`
		PoolID       string `json:"pool_id"`
	}
	type request struct {
		Member member `json:"member"`
	}

	reqBody := request{Member: member{
		Address:      opts.Address,
		TenantID:     opts.TenantID,
		ProtocolPort: opts.ProtocolPort,
		PoolID:       opts.PoolID,
	}}

	var res CreateResult
	_, res.Err = c.Request("POST", rootURL(c), gophercloud.RequestOpts{
		JSONBody:     &reqBody,
		JSONResponse: &res.Body,
		OkCodes:      []int{201},
	})
	return res
}
開發者ID:rtgoodwin,項目名稱:cs-reboot-info,代碼行數:28,代碼來源:requests.go

示例13: 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.Request("POST", rootURL(c), gophercloud.RequestOpts{
		JSONBody:     &reqBody,
		JSONResponse: &res.Body,
		OkCodes:      []int{201},
	})
	return res
}
開發者ID:rtgoodwin,項目名稱:cs-reboot-info,代碼行數:38,代碼來源:requests.go

示例14: Create

// Create is the operation responsible for creating a new node on a load
// balancer. Since every load balancer exists in both ServiceNet and the public
// Internet, both private and public IP addresses can be used for nodes.
//
// If nodes need time to boot up services before they become operational, you
// can temporarily prevent traffic from being sent to that node by setting the
// Condition field to DRAINING. Health checks will still be performed; but once
// your node is ready, you can update its condition to ENABLED and have it
// handle traffic.
func Create(client *gophercloud.ServiceClient, loadBalancerID int, opts CreateOptsBuilder) CreateResult {
	var res CreateResult

	reqBody, err := opts.ToNodeCreateMap()
	if err != nil {
		res.Err = err
		return res
	}

	resp, err := client.Request("POST", rootURL(client, loadBalancerID), gophercloud.RequestOpts{
		JSONBody:     &reqBody,
		JSONResponse: &res.Body,
		OkCodes:      []int{202},
	})
	if err != nil {
		res.Err = err
		return res
	}

	pr, err := pagination.PageResultFrom(resp)
	if err != nil {
		res.Err = err
		return res
	}

	return CreateResult{pagination.SinglePageBase(pr)}
}
開發者ID:rtgoodwin,項目名稱:cs-reboot-info,代碼行數:36,代碼來源:requests.go

示例15: Download

// Download is a function that retrieves the content and metadata for an object.
// To extract just the content, pass the DownloadResult response to the
// ExtractContent function.
func Download(c *gophercloud.ServiceClient, containerName, objectName string, opts DownloadOptsBuilder) DownloadResult {
	var res DownloadResult

	url := downloadURL(c, containerName, objectName)
	h := c.AuthenticatedHeaders()

	if opts != nil {
		headers, query, err := opts.ToObjectDownloadParams()
		if err != nil {
			res.Err = err
			return res
		}

		for k, v := range headers {
			h[k] = v
		}

		url += query
	}

	resp, err := c.Request("GET", url, gophercloud.RequestOpts{
		MoreHeaders: h,
		OkCodes:     []int{200, 304},
	})
	if resp != nil {
		res.Header = resp.Header
		res.Body = resp.Body
	}
	res.Err = err

	return res
}
開發者ID:CorainChicago,項目名稱:gophercloud,代碼行數:35,代碼來源:requests.go


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