本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}