msg

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package msg defines the Service structure which is used for service discovery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Domain

func Domain(s string) string

Domain is the opposite of Path.

func Path

func Path(s, prefix string) string

Path converts a domainname to an etcd path. If s looks like service.staging.skydns.local., the resulting key will be /skydns/local/skydns/staging/service .

func PathWithWildcard

func PathWithWildcard(s, prefix string) (string, bool)

PathWithWildcard ascts as Path, but if a name contains wildcards (* or any), the name will be chopped of before the (first) wildcard, and we do a highler evel search and later find the matching names. So service.*.skydns.local, will look for all services under skydns.local and will later check for names that match service.*.skydns.local. If a wildcard is found the returned bool is true.

Types

type Service

type Service struct {
	Host     string `json:"host,omitempty"`
	Port     int    `json:"port,omitempty"`
	Priority int    `json:"priority,omitempty"`
	Weight   int    `json:"weight,omitempty"`
	Text     string `json:"text,omitempty"`
	Mail     bool   `json:"mail,omitempty"` // Be an MX record. Priority becomes Preference.
	TTL      uint32 `json:"ttl,omitempty"`

	// When a SRV record with a "Host: IP-address" is added, we synthesize
	// a srv.Target domain name.  Normally we convert the full Key where
	// the record lives to a DNS name and use this as the srv.Target.  When
	// TargetStrip > 0 we strip the left most TargetStrip labels from the
	// DNS name.
	TargetStrip int `json:"targetstrip,omitempty"`

	// Group is used to group (or *not* to group) different services
	// together. Services with an identical Group are returned in the same
	// answer.
	Group string `json:"group,omitempty"`

	// Etcd key where we found this service and ignored from json un-/marshalling
	Key string `json:"-"`
}

Service defines a discoverable service in etcd. It is the rdata from a SRV record, but with a twist. Host (Target in SRV) must be a domain name, but if it looks like an IP address (4/6), we will treat it like an IP address.

func Group

func Group(sx []Service) []Service

Group checks the services in sx, it looks for a Group attribute on the shortest keys. If there are multiple shortest keys *and* the group attribute disagrees (and is not empty), we don't consider it a group. If a group is found, only services with *that* group (or no group) will be returned.

func (*Service) HostType

func (s *Service) HostType() (what uint16, normalized net.IP)

HostType returns the DNS type of what is encoded in the Service Host field. We're reusing dns.TypeXXX to not reinvent a new set of identifiers.

dns.TypeA: the service's Host field contains an A record. dns.TypeAAAA: the service's Host field contains an AAAA record. dns.TypeCNAME: the service's Host field contains a name.

Note that a service can double/triple as a TXT record or MX record.

func (*Service) NewA

func (s *Service) NewA(name string, ip net.IP) *dns.A

NewA returns a new A record based on the Service.

func (*Service) NewAAAA

func (s *Service) NewAAAA(name string, ip net.IP) *dns.AAAA

NewAAAA returns a new AAAA record based on the Service.

func (*Service) NewCNAME

func (s *Service) NewCNAME(name string, target string) *dns.CNAME

NewCNAME returns a new CNAME record based on the Service.

func (*Service) NewMX

func (s *Service) NewMX(name string) *dns.MX

NewMX returns a new MX record based on the Service.

func (*Service) NewNS

func (s *Service) NewNS(name string) *dns.NS

NewNS returns a new NS record based on the Service.

func (*Service) NewPTR

func (s *Service) NewPTR(name string, target string) *dns.PTR

NewPTR returns a new PTR record based on the Service.

func (*Service) NewSRV

func (s *Service) NewSRV(name string, weight uint16) *dns.SRV

NewSRV returns a new SRV record based on the Service.

func (*Service) NewTXT

func (s *Service) NewTXT(name string) *dns.TXT

NewTXT returns a new TXT record based on the Service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL