Jamie Hannaford | e514541 | 2014-11-06 12:35:59 +0100 | [diff] [blame] | 1 | package sessions |
| 2 | |
| 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | ) |
| 8 | |
| 9 | // Type represents the type of session persistence being used. |
| 10 | type Type string |
| 11 | |
| 12 | const ( |
| 13 | // HTTPCOOKIE is a session persistence mechanism that inserts an HTTP cookie |
| 14 | // and is used to determine the destination back-end node. This is supported |
| 15 | // for HTTP load balancing only. |
| 16 | HTTPCOOKIE Type = "HTTP_COOKIE" |
| 17 | |
| 18 | // SOURCEIP is a session persistence mechanism that keeps track of the source |
| 19 | // IP address that is mapped and is able to determine the destination |
| 20 | // back-end node. This is supported for HTTPS pass-through and non-HTTP load |
| 21 | // balancing only. |
| 22 | SOURCEIP Type = "SOURCE_IP" |
| 23 | ) |
| 24 | |
| 25 | // SessionPersistence indicates how a load balancer is using session persistence |
| 26 | type SessionPersistence struct { |
| 27 | Type Type `mapstructure:"persistenceType"` |
| 28 | } |
| 29 | |
| 30 | // EnableResult represents the result of an enable operation. |
| 31 | type EnableResult struct { |
| 32 | gophercloud.ErrResult |
| 33 | } |
| 34 | |
| 35 | // DisableResult represents the result of a disable operation. |
| 36 | type DisableResult struct { |
| 37 | gophercloud.ErrResult |
| 38 | } |
| 39 | |
| 40 | // GetResult represents the result of a get operation. |
| 41 | type GetResult struct { |
| 42 | gophercloud.Result |
| 43 | } |
| 44 | |
Jamie Hannaford | 227d959 | 2014-11-13 10:32:07 +0100 | [diff] [blame] | 45 | // Extract interprets a GetResult as an SP, if possible. |
Jamie Hannaford | e514541 | 2014-11-06 12:35:59 +0100 | [diff] [blame] | 46 | func (r GetResult) Extract() (*SessionPersistence, error) { |
| 47 | if r.Err != nil { |
| 48 | return nil, r.Err |
| 49 | } |
| 50 | |
| 51 | var response struct { |
| 52 | SP SessionPersistence `mapstructure:"sessionPersistence"` |
| 53 | } |
| 54 | |
| 55 | err := mapstructure.Decode(r.Body, &response) |
| 56 | |
| 57 | return &response.SP, err |
| 58 | } |