File: results.go

package info (click to toggle)
golang-github-rackspace-gophercloud 1.0.0%2Bgit20161013.1012.e00690e8-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,148 kB
  • ctags: 6,414
  • sloc: sh: 16; makefile: 6
file content (90 lines) | stat: -rw-r--r-- 2,429 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package monitors

import (
	"github.com/mitchellh/mapstructure"

	"github.com/rackspace/gophercloud"
)

// Type represents the type of Monitor.
type Type string

// Useful constants.
const (
	CONNECT Type = "CONNECT"
	HTTP    Type = "HTTP"
	HTTPS   Type = "HTTPS"
)

// Monitor represents a health monitor API resource. A monitor comes in three
// forms: CONNECT, HTTP or HTTPS.
//
// A CONNECT monitor establishes a basic connection to each node on its defined
// port to ensure that the service is listening properly. The connect monitor
// is the most basic type of health check and does no post-processing or
// protocol-specific health checks.
//
// HTTP and HTTPS health monitors are generally considered more intelligent and
// powerful than CONNECT. It is capable of processing an HTTP or HTTPS response
// to determine the condition of a node. It supports the same basic properties
// as CONNECT and includes additional attributes that are used to evaluate the
// HTTP response.
type Monitor struct {
	// Number of permissible monitor failures before removing a node from
	// rotation.
	AttemptLimit int `mapstructure:"attemptsBeforeDeactivation"`

	// The minimum number of seconds to wait before executing the health monitor.
	Delay int

	// Maximum number of seconds to wait for a connection to be established
	// before timing out.
	Timeout int

	// Type of the health monitor.
	Type Type

	// A regular expression that will be used to evaluate the contents of the
	// body of the response.
	BodyRegex string

	// The name of a host for which the health monitors will check.
	HostHeader string

	// The HTTP path that will be used in the sample request.
	Path string

	// A regular expression that will be used to evaluate the HTTP status code
	// returned in the response.
	StatusRegex string
}

// UpdateResult represents the result of an Update operation.
type UpdateResult struct {
	gophercloud.ErrResult
}

// GetResult represents the result of a Get operation.
type GetResult struct {
	gophercloud.Result
}

// DeleteResult represents the result of an Delete operation.
type DeleteResult struct {
	gophercloud.ErrResult
}

// Extract interprets any GetResult as a Monitor.
func (r GetResult) Extract() (*Monitor, error) {
	if r.Err != nil {
		return nil, r.Err
	}

	var response struct {
		M Monitor `mapstructure:"healthMonitor"`
	}

	err := mapstructure.Decode(r.Body, &response)

	return &response.M, err
}