2016-03-23 20:53:09 +01:00
|
|
|
package fastly
|
|
|
|
|
|
|
|
import (
|
2016-04-20 20:43:54 +02:00
|
|
|
"bytes"
|
|
|
|
"encoding"
|
2016-03-23 20:53:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type statusResp struct {
|
2016-04-20 20:43:54 +02:00
|
|
|
Status string
|
|
|
|
Msg string
|
2016-03-23 20:53:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *statusResp) Ok() bool {
|
2016-04-20 20:43:54 +02:00
|
|
|
return t.Status == "ok"
|
2016-03-23 20:53:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure Compatibool implements the proper interfaces.
|
|
|
|
var (
|
2016-04-20 20:43:54 +02:00
|
|
|
_ encoding.TextMarshaler = new(Compatibool)
|
|
|
|
_ encoding.TextUnmarshaler = new(Compatibool)
|
2016-03-23 20:53:09 +01:00
|
|
|
)
|
|
|
|
|
2016-10-26 15:16:54 +02:00
|
|
|
// Helper function to get a pointer to bool
|
|
|
|
func CBool(b bool) *Compatibool {
|
|
|
|
c := Compatibool(b)
|
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
2016-03-23 20:53:09 +01:00
|
|
|
// Compatibool is a boolean value that marshalls to 0/1 instead of true/false
|
|
|
|
// for compatability with Fastly's API.
|
|
|
|
type Compatibool bool
|
|
|
|
|
|
|
|
// MarshalText implements the encoding.TextMarshaler interface.
|
|
|
|
func (b Compatibool) MarshalText() ([]byte, error) {
|
2016-04-20 20:43:54 +02:00
|
|
|
if b {
|
|
|
|
return []byte("1"), nil
|
|
|
|
}
|
|
|
|
return []byte("0"), nil
|
2016-03-23 20:53:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
2016-07-21 21:10:33 +02:00
|
|
|
func (b *Compatibool) UnmarshalText(t []byte) error {
|
2016-04-20 20:43:54 +02:00
|
|
|
if bytes.Equal(t, []byte("1")) {
|
2016-07-21 21:10:33 +02:00
|
|
|
*b = Compatibool(true)
|
2016-04-20 20:43:54 +02:00
|
|
|
}
|
|
|
|
return nil
|
2016-03-23 20:53:09 +01:00
|
|
|
}
|