2015-04-20 15:44:06 +00:00
|
|
|
// Package types contains types that are common across libnetwork project
|
|
|
|
package types
|
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2022-10-05 14:30:15 +00:00
|
|
|
"strconv"
|
2015-05-20 20:28:46 +00:00
|
|
|
"strings"
|
2017-06-13 05:29:56 +00:00
|
|
|
|
|
|
|
"github.com/ishidawataru/sctp"
|
2015-05-20 20:28:46 +00:00
|
|
|
)
|
|
|
|
|
2016-02-26 22:58:11 +00:00
|
|
|
// constants for the IP address type
|
2021-08-18 10:50:27 +00:00
|
|
|
// Deprecated: use the consts defined in github.com/docker/docker/libnetwork/resolvconf
|
2016-02-26 22:58:11 +00:00
|
|
|
const (
|
|
|
|
IP = iota // IPv4 and IPv6
|
|
|
|
IPv4
|
|
|
|
IPv6
|
|
|
|
)
|
|
|
|
|
2016-06-04 09:10:19 +00:00
|
|
|
// EncryptionKey is the libnetwork representation of the key distributed by the lead
|
|
|
|
// manager.
|
|
|
|
type EncryptionKey struct {
|
|
|
|
Subsystem string
|
|
|
|
Algorithm int32
|
|
|
|
Key []byte
|
|
|
|
LamportTime uint64
|
|
|
|
}
|
|
|
|
|
2015-04-20 15:44:06 +00:00
|
|
|
// UUID represents a globally unique ID of various resources like network and endpoint
|
|
|
|
type UUID string
|
2015-05-20 20:28:46 +00:00
|
|
|
|
2016-03-28 21:50:55 +00:00
|
|
|
// QosPolicy represents a quality of service policy on an endpoint
|
|
|
|
type QosPolicy struct {
|
|
|
|
MaxEgressBandwidth uint64
|
|
|
|
}
|
|
|
|
|
2016-05-23 02:55:17 +00:00
|
|
|
// TransportPort represents a local Layer 4 endpoint
|
2015-05-20 20:28:46 +00:00
|
|
|
type TransportPort struct {
|
|
|
|
Proto Protocol
|
|
|
|
Port uint16
|
|
|
|
}
|
|
|
|
|
2015-10-06 19:08:54 +00:00
|
|
|
// Equal checks if this instance of Transportport is equal to the passed one
|
|
|
|
func (t *TransportPort) Equal(o *TransportPort) bool {
|
|
|
|
if t == o {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if o == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.Proto != o.Proto || t.Port != o.Port {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
// GetCopy returns a copy of this TransportPort structure instance
|
|
|
|
func (t *TransportPort) GetCopy() TransportPort {
|
|
|
|
return TransportPort{Proto: t.Proto, Port: t.Port}
|
|
|
|
}
|
|
|
|
|
2015-10-06 19:08:54 +00:00
|
|
|
// String returns the TransportPort structure in string form
|
|
|
|
func (t *TransportPort) String() string {
|
|
|
|
return fmt.Sprintf("%s/%d", t.Proto.String(), t.Port)
|
|
|
|
}
|
|
|
|
|
2016-05-23 02:55:17 +00:00
|
|
|
// PortBinding represents a port binding between the container and the host
|
2015-05-20 20:28:46 +00:00
|
|
|
type PortBinding struct {
|
2015-06-12 01:19:42 +00:00
|
|
|
Proto Protocol
|
|
|
|
IP net.IP
|
|
|
|
Port uint16
|
|
|
|
HostIP net.IP
|
|
|
|
HostPort uint16
|
|
|
|
HostPortEnd uint16
|
2015-05-20 20:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HostAddr returns the host side transport address
|
|
|
|
func (p PortBinding) HostAddr() (net.Addr, error) {
|
|
|
|
switch p.Proto {
|
|
|
|
case UDP:
|
|
|
|
return &net.UDPAddr{IP: p.HostIP, Port: int(p.HostPort)}, nil
|
|
|
|
case TCP:
|
|
|
|
return &net.TCPAddr{IP: p.HostIP, Port: int(p.HostPort)}, nil
|
2017-06-13 05:29:56 +00:00
|
|
|
case SCTP:
|
2019-05-02 11:23:31 +00:00
|
|
|
return &sctp.SCTPAddr{IPAddrs: []net.IPAddr{{IP: p.HostIP}}, Port: int(p.HostPort)}, nil
|
2015-05-20 20:28:46 +00:00
|
|
|
default:
|
|
|
|
return nil, ErrInvalidProtocolBinding(p.Proto.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContainerAddr returns the container side transport address
|
|
|
|
func (p PortBinding) ContainerAddr() (net.Addr, error) {
|
|
|
|
switch p.Proto {
|
|
|
|
case UDP:
|
|
|
|
return &net.UDPAddr{IP: p.IP, Port: int(p.Port)}, nil
|
|
|
|
case TCP:
|
|
|
|
return &net.TCPAddr{IP: p.IP, Port: int(p.Port)}, nil
|
2017-06-13 05:29:56 +00:00
|
|
|
case SCTP:
|
2019-05-02 11:23:31 +00:00
|
|
|
return &sctp.SCTPAddr{IPAddrs: []net.IPAddr{{IP: p.IP}}, Port: int(p.Port)}, nil
|
2015-05-20 20:28:46 +00:00
|
|
|
default:
|
|
|
|
return nil, ErrInvalidProtocolBinding(p.Proto.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCopy returns a copy of this PortBinding structure instance
|
|
|
|
func (p *PortBinding) GetCopy() PortBinding {
|
|
|
|
return PortBinding{
|
2015-06-12 01:19:42 +00:00
|
|
|
Proto: p.Proto,
|
|
|
|
IP: GetIPCopy(p.IP),
|
|
|
|
Port: p.Port,
|
|
|
|
HostIP: GetIPCopy(p.HostIP),
|
|
|
|
HostPort: p.HostPort,
|
|
|
|
HostPortEnd: p.HostPortEnd,
|
2015-05-20 20:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-23 02:55:17 +00:00
|
|
|
// String returns the PortBinding structure in string form
|
2015-10-06 19:08:54 +00:00
|
|
|
func (p *PortBinding) String() string {
|
|
|
|
ret := fmt.Sprintf("%s/", p.Proto)
|
|
|
|
if p.IP != nil {
|
2017-05-09 23:07:09 +00:00
|
|
|
ret += p.IP.String()
|
2015-10-06 19:08:54 +00:00
|
|
|
}
|
|
|
|
ret = fmt.Sprintf("%s:%d/", ret, p.Port)
|
|
|
|
if p.HostIP != nil {
|
2017-05-09 23:07:09 +00:00
|
|
|
ret += p.HostIP.String()
|
2015-10-06 19:08:54 +00:00
|
|
|
}
|
|
|
|
ret = fmt.Sprintf("%s:%d", ret, p.HostPort)
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
// Equal checks if this instance of PortBinding is equal to the passed one
|
|
|
|
func (p *PortBinding) Equal(o *PortBinding) bool {
|
|
|
|
if p == o {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if o == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-06-12 01:19:42 +00:00
|
|
|
if p.Proto != o.Proto || p.Port != o.Port ||
|
|
|
|
p.HostPort != o.HostPort || p.HostPortEnd != o.HostPortEnd {
|
2015-05-20 20:28:46 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.IP != nil {
|
|
|
|
if !p.IP.Equal(o.IP) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if o.IP != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.HostIP != nil {
|
|
|
|
if !p.HostIP.Equal(o.HostIP) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if o.HostIP != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:56:15 +00:00
|
|
|
// ErrInvalidProtocolBinding is returned when the port binding protocol is not valid.
|
|
|
|
type ErrInvalidProtocolBinding string
|
|
|
|
|
|
|
|
func (ipb ErrInvalidProtocolBinding) Error() string {
|
|
|
|
return fmt.Sprintf("invalid transport protocol: %s", string(ipb))
|
|
|
|
}
|
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
const (
|
|
|
|
// ICMP is for the ICMP ip protocol
|
|
|
|
ICMP = 1
|
|
|
|
// TCP is for the TCP ip protocol
|
|
|
|
TCP = 6
|
|
|
|
// UDP is for the UDP ip protocol
|
|
|
|
UDP = 17
|
2017-06-13 05:29:56 +00:00
|
|
|
// SCTP is for the SCTP ip protocol
|
|
|
|
SCTP = 132
|
2015-05-20 20:28:46 +00:00
|
|
|
)
|
|
|
|
|
2016-06-02 05:37:39 +00:00
|
|
|
// Protocol represents an IP protocol number
|
2015-05-20 20:28:46 +00:00
|
|
|
type Protocol uint8
|
|
|
|
|
|
|
|
func (p Protocol) String() string {
|
|
|
|
switch p {
|
|
|
|
case ICMP:
|
|
|
|
return "icmp"
|
|
|
|
case TCP:
|
|
|
|
return "tcp"
|
|
|
|
case UDP:
|
|
|
|
return "udp"
|
2017-06-13 05:29:56 +00:00
|
|
|
case SCTP:
|
|
|
|
return "sctp"
|
2015-05-20 20:28:46 +00:00
|
|
|
default:
|
2022-10-05 14:30:15 +00:00
|
|
|
return strconv.Itoa(int(p))
|
2015-05-20 20:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseProtocol returns the respective Protocol type for the passed string
|
|
|
|
func ParseProtocol(s string) Protocol {
|
|
|
|
switch strings.ToLower(s) {
|
|
|
|
case "icmp":
|
|
|
|
return ICMP
|
|
|
|
case "udp":
|
|
|
|
return UDP
|
|
|
|
case "tcp":
|
|
|
|
return TCP
|
2017-06-13 05:29:56 +00:00
|
|
|
case "sctp":
|
|
|
|
return SCTP
|
2015-05-20 20:28:46 +00:00
|
|
|
default:
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMacCopy returns a copy of the passed MAC address
|
|
|
|
func GetMacCopy(from net.HardwareAddr) net.HardwareAddr {
|
2015-10-03 23:11:50 +00:00
|
|
|
if from == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2015-05-20 20:28:46 +00:00
|
|
|
to := make(net.HardwareAddr, len(from))
|
|
|
|
copy(to, from)
|
|
|
|
return to
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetIPCopy returns a copy of the passed IP address
|
|
|
|
func GetIPCopy(from net.IP) net.IP {
|
2015-10-03 23:11:50 +00:00
|
|
|
if from == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2015-05-20 20:28:46 +00:00
|
|
|
to := make(net.IP, len(from))
|
|
|
|
copy(to, from)
|
|
|
|
return to
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetIPNetCopy returns a copy of the passed IP Network
|
|
|
|
func GetIPNetCopy(from *net.IPNet) *net.IPNet {
|
|
|
|
if from == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
bm := make(net.IPMask, len(from.Mask))
|
|
|
|
copy(bm, from.Mask)
|
|
|
|
return &net.IPNet{IP: GetIPCopy(from.IP), Mask: bm}
|
|
|
|
}
|
|
|
|
|
2015-07-24 23:59:27 +00:00
|
|
|
// GetIPNetCanonical returns the canonical form for the passed network
|
|
|
|
func GetIPNetCanonical(nw *net.IPNet) *net.IPNet {
|
|
|
|
if nw == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
c := GetIPNetCopy(nw)
|
|
|
|
c.IP = c.IP.Mask(nw.Mask)
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
// CompareIPNet returns equal if the two IP Networks are equal
|
|
|
|
func CompareIPNet(a, b *net.IPNet) bool {
|
|
|
|
if a == b {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if a == nil || b == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return a.IP.Equal(b.IP) && bytes.Equal(a.Mask, b.Mask)
|
|
|
|
}
|
2015-05-14 21:56:15 +00:00
|
|
|
|
2015-06-25 02:11:44 +00:00
|
|
|
// GetMinimalIP returns the address in its shortest form
|
2018-05-23 15:21:31 +00:00
|
|
|
// If ip contains an IPv4-mapped IPv6 address, the 4-octet form of the IPv4 address will be returned.
|
|
|
|
// Otherwise ip is returned unchanged.
|
2015-06-25 02:11:44 +00:00
|
|
|
func GetMinimalIP(ip net.IP) net.IP {
|
|
|
|
if ip != nil && ip.To4() != nil {
|
|
|
|
return ip.To4()
|
|
|
|
}
|
|
|
|
return ip
|
|
|
|
}
|
|
|
|
|
2016-02-26 22:58:11 +00:00
|
|
|
// IsIPNetValid returns true if the ipnet is a valid network/mask
|
|
|
|
// combination. Otherwise returns false.
|
|
|
|
func IsIPNetValid(nw *net.IPNet) bool {
|
|
|
|
return nw.String() != "0.0.0.0/0"
|
|
|
|
}
|
|
|
|
|
2015-06-25 02:11:44 +00:00
|
|
|
var v4inV6MaskPrefix = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
|
|
|
|
2015-09-22 20:20:55 +00:00
|
|
|
// compareIPMask checks if the passed ip and mask are semantically compatible.
|
|
|
|
// It returns the byte indexes for the address and mask so that caller can
|
|
|
|
// do bitwise operations without modifying address representation.
|
|
|
|
func compareIPMask(ip net.IP, mask net.IPMask) (is int, ms int, err error) {
|
2015-06-25 02:11:44 +00:00
|
|
|
// Find the effective starting of address and mask
|
|
|
|
if len(ip) == net.IPv6len && ip.To4() != nil {
|
|
|
|
is = 12
|
|
|
|
}
|
|
|
|
if len(ip[is:]) == net.IPv4len && len(mask) == net.IPv6len && bytes.Equal(mask[:12], v4inV6MaskPrefix) {
|
|
|
|
ms = 12
|
|
|
|
}
|
|
|
|
// Check if address and mask are semantically compatible
|
|
|
|
if len(ip[is:]) != len(mask[ms:]) {
|
2015-09-22 20:20:55 +00:00
|
|
|
err = fmt.Errorf("ip and mask are not compatible: (%#v, %#v)", ip, mask)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetHostPartIP returns the host portion of the ip address identified by the mask.
|
|
|
|
// IP address representation is not modified. If address and mask are not compatible
|
|
|
|
// an error is returned.
|
|
|
|
func GetHostPartIP(ip net.IP, mask net.IPMask) (net.IP, error) {
|
|
|
|
// Find the effective starting of address and mask
|
|
|
|
is, ms, err := compareIPMask(ip, mask)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot compute host portion ip address because %s", err)
|
2015-06-25 02:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute host portion
|
|
|
|
out := GetIPCopy(ip)
|
|
|
|
for i := 0; i < len(mask[ms:]); i++ {
|
|
|
|
out[is+i] &= ^mask[ms+i]
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2015-09-22 20:20:55 +00:00
|
|
|
// GetBroadcastIP returns the broadcast ip address for the passed network (ip and mask).
|
|
|
|
// IP address representation is not modified. If address and mask are not compatible
|
|
|
|
// an error is returned.
|
|
|
|
func GetBroadcastIP(ip net.IP, mask net.IPMask) (net.IP, error) {
|
|
|
|
// Find the effective starting of address and mask
|
|
|
|
is, ms, err := compareIPMask(ip, mask)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot compute broadcast ip address because %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute broadcast address
|
|
|
|
out := GetIPCopy(ip)
|
|
|
|
for i := 0; i < len(mask[ms:]); i++ {
|
|
|
|
out[is+i] |= ^mask[ms+i]
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseCIDR returns the *net.IPNet represented by the passed CIDR notation
|
|
|
|
func ParseCIDR(cidr string) (n *net.IPNet, e error) {
|
|
|
|
var i net.IP
|
|
|
|
if i, n, e = net.ParseCIDR(cidr); e == nil {
|
|
|
|
n.IP = i
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-05-20 00:08:56 +00:00
|
|
|
const (
|
|
|
|
// NEXTHOP indicates a StaticRoute with an IP next hop.
|
|
|
|
NEXTHOP = iota
|
|
|
|
|
2016-02-28 16:34:30 +00:00
|
|
|
// CONNECTED indicates a StaticRoute with an interface for directly connected peers.
|
2015-05-20 00:08:56 +00:00
|
|
|
CONNECTED
|
|
|
|
)
|
|
|
|
|
|
|
|
// StaticRoute is a statically-provisioned IP route.
|
|
|
|
type StaticRoute struct {
|
|
|
|
Destination *net.IPNet
|
|
|
|
|
|
|
|
RouteType int // NEXT_HOP or CONNECTED
|
|
|
|
|
|
|
|
// NextHop will be resolved by the kernel (i.e. as a loose hop).
|
|
|
|
NextHop net.IP
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCopy returns a copy of this StaticRoute structure
|
|
|
|
func (r *StaticRoute) GetCopy() *StaticRoute {
|
|
|
|
d := GetIPNetCopy(r.Destination)
|
|
|
|
nh := GetIPCopy(r.NextHop)
|
|
|
|
return &StaticRoute{Destination: d,
|
2015-09-09 23:06:35 +00:00
|
|
|
RouteType: r.RouteType,
|
|
|
|
NextHop: nh,
|
|
|
|
}
|
2015-05-20 00:08:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-26 17:12:20 +00:00
|
|
|
// InterfaceStatistics represents the interface's statistics
|
|
|
|
type InterfaceStatistics struct {
|
|
|
|
RxBytes uint64
|
|
|
|
RxPackets uint64
|
|
|
|
RxErrors uint64
|
|
|
|
RxDropped uint64
|
|
|
|
TxBytes uint64
|
|
|
|
TxPackets uint64
|
|
|
|
TxErrors uint64
|
|
|
|
TxDropped uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (is *InterfaceStatistics) String() string {
|
|
|
|
return fmt.Sprintf("\nRxBytes: %d, RxPackets: %d, RxErrors: %d, RxDropped: %d, TxBytes: %d, TxPackets: %d, TxErrors: %d, TxDropped: %d",
|
|
|
|
is.RxBytes, is.RxPackets, is.RxErrors, is.RxDropped, is.TxBytes, is.TxPackets, is.TxErrors, is.TxDropped)
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:56:15 +00:00
|
|
|
/******************************
|
|
|
|
* Well-known Error Interfaces
|
|
|
|
******************************/
|
|
|
|
|
|
|
|
// MaskableError is an interface for errors which can be ignored by caller
|
|
|
|
type MaskableError interface {
|
|
|
|
// Maskable makes implementer into MaskableError type
|
|
|
|
Maskable()
|
|
|
|
}
|
|
|
|
|
2015-06-15 18:20:28 +00:00
|
|
|
// RetryError is an interface for errors which might get resolved through retry
|
|
|
|
type RetryError interface {
|
|
|
|
// Retry makes implementer into RetryError type
|
|
|
|
Retry()
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:56:15 +00:00
|
|
|
// BadRequestError is an interface for errors originated by a bad request
|
|
|
|
type BadRequestError interface {
|
|
|
|
// BadRequest makes implementer into BadRequestError type
|
|
|
|
BadRequest()
|
|
|
|
}
|
|
|
|
|
|
|
|
// NotFoundError is an interface for errors raised because a needed resource is not available
|
|
|
|
type NotFoundError interface {
|
|
|
|
// NotFound makes implementer into NotFoundError type
|
|
|
|
NotFound()
|
|
|
|
}
|
|
|
|
|
2016-02-28 16:34:30 +00:00
|
|
|
// ForbiddenError is an interface for errors which denote a valid request that cannot be honored
|
2015-05-14 21:56:15 +00:00
|
|
|
type ForbiddenError interface {
|
|
|
|
// Forbidden makes implementer into ForbiddenError type
|
|
|
|
Forbidden()
|
|
|
|
}
|
|
|
|
|
2016-02-28 16:34:30 +00:00
|
|
|
// NoServiceError is an interface for errors returned when the required service is not available
|
2015-05-14 21:56:15 +00:00
|
|
|
type NoServiceError interface {
|
|
|
|
// NoService makes implementer into NoServiceError type
|
|
|
|
NoService()
|
|
|
|
}
|
|
|
|
|
2016-02-28 16:34:30 +00:00
|
|
|
// TimeoutError is an interface for errors raised because of timeout
|
2015-05-14 21:56:15 +00:00
|
|
|
type TimeoutError interface {
|
|
|
|
// Timeout makes implementer into TimeoutError type
|
|
|
|
Timeout()
|
|
|
|
}
|
|
|
|
|
2016-02-28 16:34:30 +00:00
|
|
|
// NotImplementedError is an interface for errors raised because of requested functionality is not yet implemented
|
2015-05-14 21:56:15 +00:00
|
|
|
type NotImplementedError interface {
|
|
|
|
// NotImplemented makes implementer into NotImplementedError type
|
|
|
|
NotImplemented()
|
|
|
|
}
|
|
|
|
|
|
|
|
// InternalError is an interface for errors raised because of an internal error
|
|
|
|
type InternalError interface {
|
|
|
|
// Internal makes implementer into InternalError type
|
|
|
|
Internal()
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************
|
2015-06-15 18:20:28 +00:00
|
|
|
* Well-known Error Formatters
|
2015-05-14 21:56:15 +00:00
|
|
|
******************************/
|
|
|
|
|
|
|
|
// BadRequestErrorf creates an instance of BadRequestError
|
|
|
|
func BadRequestErrorf(format string, params ...interface{}) error {
|
|
|
|
return badRequest(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
// NotFoundErrorf creates an instance of NotFoundError
|
|
|
|
func NotFoundErrorf(format string, params ...interface{}) error {
|
|
|
|
return notFound(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForbiddenErrorf creates an instance of ForbiddenError
|
|
|
|
func ForbiddenErrorf(format string, params ...interface{}) error {
|
|
|
|
return forbidden(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
// NoServiceErrorf creates an instance of NoServiceError
|
|
|
|
func NoServiceErrorf(format string, params ...interface{}) error {
|
|
|
|
return noService(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
// NotImplementedErrorf creates an instance of NotImplementedError
|
|
|
|
func NotImplementedErrorf(format string, params ...interface{}) error {
|
|
|
|
return notImpl(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TimeoutErrorf creates an instance of TimeoutError
|
|
|
|
func TimeoutErrorf(format string, params ...interface{}) error {
|
|
|
|
return timeout(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
// InternalErrorf creates an instance of InternalError
|
|
|
|
func InternalErrorf(format string, params ...interface{}) error {
|
|
|
|
return internal(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
|
|
|
// InternalMaskableErrorf creates an instance of InternalError and MaskableError
|
|
|
|
func InternalMaskableErrorf(format string, params ...interface{}) error {
|
|
|
|
return maskInternal(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
2015-06-15 18:20:28 +00:00
|
|
|
// RetryErrorf creates an instance of RetryError
|
|
|
|
func RetryErrorf(format string, params ...interface{}) error {
|
|
|
|
return retry(fmt.Sprintf(format, params...))
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:56:15 +00:00
|
|
|
/***********************
|
|
|
|
* Internal Error Types
|
|
|
|
***********************/
|
|
|
|
type badRequest string
|
|
|
|
|
|
|
|
func (br badRequest) Error() string {
|
|
|
|
return string(br)
|
|
|
|
}
|
|
|
|
func (br badRequest) BadRequest() {}
|
|
|
|
|
|
|
|
type notFound string
|
|
|
|
|
|
|
|
func (nf notFound) Error() string {
|
|
|
|
return string(nf)
|
|
|
|
}
|
|
|
|
func (nf notFound) NotFound() {}
|
|
|
|
|
|
|
|
type forbidden string
|
|
|
|
|
|
|
|
func (frb forbidden) Error() string {
|
|
|
|
return string(frb)
|
|
|
|
}
|
|
|
|
func (frb forbidden) Forbidden() {}
|
|
|
|
|
|
|
|
type noService string
|
|
|
|
|
|
|
|
func (ns noService) Error() string {
|
|
|
|
return string(ns)
|
|
|
|
}
|
|
|
|
func (ns noService) NoService() {}
|
|
|
|
|
|
|
|
type timeout string
|
|
|
|
|
|
|
|
func (to timeout) Error() string {
|
|
|
|
return string(to)
|
|
|
|
}
|
|
|
|
func (to timeout) Timeout() {}
|
|
|
|
|
|
|
|
type notImpl string
|
|
|
|
|
|
|
|
func (ni notImpl) Error() string {
|
|
|
|
return string(ni)
|
|
|
|
}
|
|
|
|
func (ni notImpl) NotImplemented() {}
|
|
|
|
|
|
|
|
type internal string
|
|
|
|
|
|
|
|
func (nt internal) Error() string {
|
|
|
|
return string(nt)
|
|
|
|
}
|
|
|
|
func (nt internal) Internal() {}
|
|
|
|
|
|
|
|
type maskInternal string
|
|
|
|
|
|
|
|
func (mnt maskInternal) Error() string {
|
|
|
|
return string(mnt)
|
|
|
|
}
|
|
|
|
func (mnt maskInternal) Internal() {}
|
|
|
|
func (mnt maskInternal) Maskable() {}
|
2015-06-15 18:20:28 +00:00
|
|
|
|
|
|
|
type retry string
|
|
|
|
|
|
|
|
func (r retry) Error() string {
|
|
|
|
return string(r)
|
|
|
|
}
|
|
|
|
func (r retry) Retry() {}
|