NewHosts returns new Hosts from given addresses.
(source map[string]Host)
| 96 | |
| 97 | // NewHosts returns new Hosts from given addresses. |
| 98 | func NewHosts(source map[string]Host) (*Hosts, error) { |
| 99 | h := &Hosts{ |
| 100 | source: toLowerKeys(source), |
| 101 | n: &trieNode{ |
| 102 | children: make(map[rune]*trieNode), |
| 103 | }, |
| 104 | } |
| 105 | |
| 106 | for k := range h.source { |
| 107 | err := h.insert(k) |
| 108 | if err != nil { |
| 109 | return nil, err |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return h, nil |
| 114 | } |
| 115 | |
| 116 | func toLowerKeys(source map[string]Host) map[string]Host { |
| 117 | result := make(map[string]Host, len(source)) |
searching dependent graphs…