本文整理汇总了Golang中github.com/lxc/lxd.HoistResponse函数的典型用法代码示例。如果您正苦于以下问题:Golang HoistResponse函数的具体用法?Golang HoistResponse怎么用?Golang HoistResponse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HoistResponse函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: httpGetFile
func (d *Daemon) httpGetFile(url string, certificate string) (*http.Response, error) {
var err error
var cert *x509.Certificate
if certificate != "" {
certBlock, _ := pem.Decode([]byte(certificate))
if certBlock == nil {
return nil, fmt.Errorf("Invalid certificate")
}
cert, err = x509.ParseCertificate(certBlock.Bytes)
if err != nil {
return nil, err
}
}
tlsConfig, err := shared.GetTLSConfig("", "", "", cert)
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: tlsConfig,
Dial: shared.RFC3493Dialer,
Proxy: d.proxy,
DisableKeepAlives: true,
}
myhttp := http.Client{
Transport: tr,
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", shared.UserAgent)
raw, err := myhttp.Do(req)
if err != nil {
return nil, err
}
if raw.StatusCode != 200 {
_, err := lxd.HoistResponse(raw, lxd.Error)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("non-200 status with no error response?")
}
return raw, nil
}
开发者ID:akshaykarle,项目名称:lxd,代码行数:54,代码来源:daemon.go
示例2: callHook
func callHook(args []string) error {
if len(args) < 4 {
return fmt.Errorf("Invalid arguments")
}
path := args[1]
id := args[2]
state := args[3]
target := ""
err := os.Setenv("LXD_DIR", path)
if err != nil {
return err
}
c, err := lxd.NewClient(&lxd.DefaultConfig, "local")
if err != nil {
return err
}
url := fmt.Sprintf("%s/internal/containers/%s/on%s", c.BaseURL, id, state)
if state == "stop" {
target = os.Getenv("LXC_TARGET")
if target == "" {
target = "unknown"
}
url = fmt.Sprintf("%s?target=%s", url, target)
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
raw, err := c.Http.Do(req)
if err != nil {
return err
}
_, err = lxd.HoistResponse(raw, lxd.Sync)
if err != nil {
return err
}
if target == "reboot" {
return fmt.Errorf("Reboot must be handled by LXD.")
}
return nil
}
开发者ID:czl349095941,项目名称:lxd,代码行数:51,代码来源:main.go
示例3: cmdWaitReady
func cmdWaitReady() error {
var timeout int
if *argTimeout == -1 {
timeout = 15
} else {
timeout = *argTimeout
}
finger := make(chan error, 1)
go func() {
for {
c, err := lxd.NewClient(&lxd.DefaultConfig, "local")
if err != nil {
time.Sleep(500 * time.Millisecond)
continue
}
req, err := http.NewRequest("GET", c.BaseURL+"/internal/ready", nil)
if err != nil {
time.Sleep(500 * time.Millisecond)
continue
}
raw, err := c.Http.Do(req)
if err != nil {
time.Sleep(500 * time.Millisecond)
continue
}
_, err = lxd.HoistResponse(raw, lxd.Sync)
if err != nil {
time.Sleep(500 * time.Millisecond)
continue
}
finger <- nil
return
}
}()
select {
case <-finger:
break
case <-time.After(time.Second * time.Duration(timeout)):
return fmt.Errorf("LXD still not running after %ds timeout.", timeout)
}
return nil
}
开发者ID:jsavikko,项目名称:lxd,代码行数:50,代码来源:main.go
示例4: httpGetFile
func (d *Daemon) httpGetFile(url string) (*http.Response, error) {
var err error
if d.tlsconfig == nil {
d.tlsconfig, err = shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return nil, err
}
}
tr := &http.Transport{
TLSClientConfig: d.tlsconfig,
Dial: shared.RFC3493Dialer,
Proxy: http.ProxyFromEnvironment,
}
myhttp := http.Client{
Transport: tr,
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", shared.UserAgent)
raw, err := myhttp.Do(req)
if err != nil {
return nil, err
}
if raw.StatusCode != 200 {
_, err := lxd.HoistResponse(raw, lxd.Error)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("non-200 status with no error response?")
}
return raw, nil
}
开发者ID:mickydelfavero,项目名称:lxd,代码行数:40,代码来源:daemon.go
示例5: cmdReady
func cmdReady() error {
c, err := lxd.NewClient(&lxd.DefaultConfig, "local")
if err != nil {
return err
}
req, err := http.NewRequest("PUT", c.BaseURL+"/internal/ready", nil)
if err != nil {
return err
}
raw, err := c.Http.Do(req)
if err != nil {
return err
}
_, err = lxd.HoistResponse(raw, lxd.Sync)
if err != nil {
return err
}
return nil
}
开发者ID:jsavikko,项目名称:lxd,代码行数:23,代码来源:main.go
示例6: cmdCallHook
func cmdCallHook(args []string) error {
if len(args) < 4 {
return fmt.Errorf("Invalid arguments")
}
path := args[1]
id := args[2]
state := args[3]
target := ""
err := os.Setenv("LXD_DIR", path)
if err != nil {
return err
}
c, err := lxd.NewClient(&lxd.DefaultConfig, "local")
if err != nil {
return err
}
url := fmt.Sprintf("%s/internal/containers/%s/on%s", c.BaseURL, id, state)
if state == "stop" {
target = os.Getenv("LXC_TARGET")
if target == "" {
target = "unknown"
}
url = fmt.Sprintf("%s?target=%s", url, target)
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
hook := make(chan error, 1)
go func() {
raw, err := c.Http.Do(req)
if err != nil {
hook <- err
return
}
_, err = lxd.HoistResponse(raw, lxd.Sync)
if err != nil {
hook <- err
return
}
hook <- nil
}()
select {
case err := <-hook:
if err != nil {
return err
}
break
case <-time.After(30 * time.Second):
return fmt.Errorf("Hook didn't finish within 30s")
}
if target == "reboot" {
return fmt.Errorf("Reboot must be handled by LXD.")
}
return nil
}
开发者ID:jsavikko,项目名称:lxd,代码行数:68,代码来源:main.go
注:本文中的github.com/lxc/lxd.HoistResponse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论