func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) {
	var params *m.QueryParam
	var ch chan *m.ServiceEntry
	var v6, v4 bool
	var addrs []string
	var err error

	// default to null logger
	if l == nil {
		l = log.New(ioutil.Discard, "", 0)
	}

	// init params
	params = new(m.QueryParam)

	// validate and set service record
	if args["service"] == "" {
		return nil, fmt.Errorf("discover-mdns: Service record not provided." +
			"  Please specify a service record for the mDNS lookup.")
	}
	params.Service = args["service"]

	// validate and set domain
	if args["domain"] != "" {
		params.Domain = args["domain"]
	} else {
		params.Domain = "local"
	}

	// validate and set timeout
	if args["timeout"] != "" {
		if params.Timeout, err = time.ParseDuration(args["timeout"]); err != nil {
			return nil, fmt.Errorf("discover-mdns: Failed to parse timeout: %s", err)
		}
	} else {
		params.Timeout = 5 * time.Second
	}

	// validate and set v6 toggle
	if args["v6"] != "" {
		if v6, err = strconv.ParseBool(args["v6"]); err != nil {
			return nil, fmt.Errorf("discover-mdns: Failed to parse v6: %s", err)
		}
	} else {
		v6 = true
	}

	// validate and set v4 toggle
	if args["v4"] != "" {
		if v4, err = strconv.ParseBool(args["v4"]); err != nil {
			return nil, fmt.Errorf("discover-mdns: Failed to parse v4: %s", err)
		}
	} else {
		v4 = true
	}

	// init entries channel
	ch = make(chan *m.ServiceEntry)
	defer close(ch)
	params.Entries = ch

	// build addresses
	go func() {
		var addr string
		for e := range ch {
			addr = "" // reset addr each loop
			if v6 && e.AddrV6 != nil {
				addr = net.JoinHostPort(e.AddrV6.String(),
					strconv.Itoa(e.Port))
			}
			if addr == "" && v4 && e.AddrV4 != nil {
				addr = net.JoinHostPort(e.AddrV4.String(),
					strconv.Itoa(e.Port))
			}
			if addr != "" {
				l.Printf("[DEBUG] discover-mdns: %s -> %s",
					e.Host, addr)
				// build address list
				addrs = append(addrs, addr)
			}
		}
	}()

	// lookup and return
	return addrs, m.Query(params)
}
func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) {
	var params *m.QueryParam
	var ch chan *m.ServiceEntry
	var v6, v4 bool
	var addrs []string
	var err error

	
	if l == nil {
		l = log.New(ioutil.Discard, "", 0)
	}

	
	params = new(m.QueryParam)

	
	if args["service"] == "" {
		return nil, fmt.Errorf("discover-mdns: Service record not provided." +
			"  Please specify a service record for the mDNS lookup.")
	}
	params.Service = args["service"]

	
	if args["domain"] != "" {
		params.Domain = args["domain"]
	} else {
		params.Domain = "local"
	}

	
	if args["timeout"] != "" {
		if params.Timeout, err = time.ParseDuration(args["timeout"]); err != nil {
			return nil, fmt.Errorf("discover-mdns: Failed to parse timeout: %s", err)
		}
	} else {
		params.Timeout = 5 * time.Second
	}

	
	if args["v6"] != "" {
		if v6, err = strconv.ParseBool(args["v6"]); err != nil {
			return nil, fmt.Errorf("discover-mdns: Failed to parse v6: %s", err)
		}
	} else {
		v6 = true
	}

	
	if args["v4"] != "" {
		if v4, err = strconv.ParseBool(args["v4"]); err != nil {
			return nil, fmt.Errorf("discover-mdns: Failed to parse v4: %s", err)
		}
	} else {
		v4 = true
	}

	
	ch = make(chan *m.ServiceEntry)
	defer close(ch)
	params.Entries = ch

	
	go func() {
		var addr string
		for e := range ch {
			addr = "" 
			if v6 && e.AddrV6 != nil {
				addr = net.JoinHostPort(e.AddrV6.String(),
					strconv.Itoa(e.Port))
			}
			if addr == "" && v4 && e.AddrV4 != nil {
				addr = net.JoinHostPort(e.AddrV4.String(),
					strconv.Itoa(e.Port))
			}
			if addr != "" {
				l.Printf("[DEBUG] discover-mdns: %s -> %s",
					e.Host, addr)
				
				addrs = append(addrs, addr)
			}
		}
	}()

	
	return addrs, m.Query(params)
}
func ( p * Provider ) Addrs ( args map [ string ] string , l * log . Logger ) ( [ ] string , error ) { var params * m . QueryParam var ch chan * m . ServiceEntry var v6 , v4 bool var addrs [ ] string var err error // default to null logger if l == nil { l = log . New ( ioutil . Discard , " " , 0 ) } // init params params = new ( m . QueryParam ) // validate and set service record if args [ " " ] == " " { return nil , fmt . Errorf ( " " + " " ) } params . Service = args [ " " ] // validate and set domain if args [ " " ] != " " { params . Domain = args [ " " ] } else { params . Domain = " " } // validate and set timeout if args [ " " ] != " " { if params . Timeout , err = time . ParseDuration ( args [ " " ] ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } } else { params . Timeout = 5 * time . Second } // validate and set v6 toggle if args [ " " ] != " " { if v6 , err = strconv . ParseBool ( args [ " " ] ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } } else { v6 = true } // validate and set v4 toggle if args [ " " ] != " " { if v4 , err = strconv . ParseBool ( args [ " " ] ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } } else { v4 = true } // init entries channel ch = make ( chan * m . ServiceEntry ) defer close ( ch ) params . Entries = ch // build addresses go func ( ) { var addr string for e := range ch { addr = " " // reset addr each loop if v6 && e . AddrV6 != nil { addr = net . JoinHostPort ( e . AddrV6 . String ( ) , strconv . Itoa ( e . Port ) ) } if addr == " " && v4 && e . AddrV4 != nil { addr = net . JoinHostPort ( e . AddrV4 . String ( ) , strconv . Itoa ( e . Port ) ) } if addr != " " { l . Printf ( " " , e . Host , addr ) // build address list addrs = append ( addrs , addr ) } } } ( ) // lookup and return return addrs , m . Query ( params ) }
// Addrs returns discovered addresses for the mDNS package.
Addrs returns discovered addresses for the mDNS package .