// SetAllRefs sets all available sync references according to Region func (sync *Sync)…
- User
// SetAllRefs sets all available sync references according to Region func (sync *Sync) SetAllRefs(rd map[string]map[string][]interface{}) { sync.AllRefs = make(map[string][]string) for _, syncType := range []string{"ntp", "ptp"} { syncTypeLabel := fmt.Sprintf( "%s%s", strings.ToUpper( string(syncType[0]), ), syncType[1:], ) sync.AllRefs[syncTypeLabel] = []string{} m := map[string]bool{} for _, set := range rd { for _, syncRef := range set[syncType] { ref := fmt.Sprintf("%s", syncRef) if _, ok := m[ref]; !ok { sync.AllRefs[syncTypeLabel] = append(sync.AllRefs[syncTypeLabel], ref) m[ref] = true } } } } }
- Assistant
This method
SetAllRefssets all available sync references according to the region.The method takes a map
rdas an argument, which contains the sync references for NTP and PTP sync types categorized by region. The keys of the map represent the region names, and the values are inner maps containing the sync references for each sync type.The method initializes the
AllRefsmap in theSyncstruct to store the sync references. It then iterates over each sync type ("ntp" and "ptp") and creates a label for each sync type by capitalizing the first letter of the sync type.Inside the loop, it creates a temporary map
mto store the already added sync references to avoid duplicates. It then iterates over each set of sync references in the inner map using a nested loop. For each sync reference, it converts it to a string and checks if it exists in the temporary map. If it doesn't exist, it appends the sync reference to theAllRefsmap for the corresponding sync type label and marks it as added in the temporary map.After the loop completes, the
AllRefsmap will contain all available sync references categorized by sync type.