func (rs *Registries) LoadConfig(registriesFile string) {
	if rs.Viper == nil {
		rs.Viper = viper.New()
	}
	if registriesFile != "" {
		rs.AddConfigPath(path.Dir(registriesFile))
		base := path.Base(registriesFile)
		ext := path.Ext(registriesFile)
		rs.SetConfigName(base[0 : len(base)-len(ext)])
		logrus.Infof("Using registries located in %s with file name %s", path.Dir(registriesFile), base[0:len(base)-len(ext)])
	} else {
		rs.SetConfigName("registries")
		var root string
		_, run, _, ok := runtime.Caller(0)
		if ok {
			root = filepath.Dir(run)
			rs.AddConfigPath(root)
		} else {
			logrus.Fatalf("Failed to get runtime caller for parser")
		}
		logrus.Infof("Using registries located in %s with file name %s", root, "registries.yml")
	}
	config := make(map[string]map[string]registriesConfig)
	if err := rs.ReadInConfig(); err != nil {
		logrus.Fatalf("Failed to read in registries file: %s", err)
	}
	if err := rs.Unmarshal(&config); err != nil {
		logrus.Fatalf("Unable to unmarshal registries file: %s", err)
	}
	for name, r := range config["registries"] {
		if r.URL != "" {
			url, err := url.Parse(r.URL)
			if err != nil {
				logrus.Fatalf("Failed to parse registry from the passed url (%s): %s", r.URL, err)
			}
			duration, err := time.ParseDuration(r.RefreshRate)
			if err != nil {
				logrus.Fatalf("Failed to add registry (%s), invalid duration: %s", r.URL, err)
			}
			new, err := NewRegistry(url.Scheme, url.Hostname(), name, r.DisplayName, r.Username, r.Password, r.Port, duration, r.SkipTLS, r.DockerhubIntegration, r.ReadOnly)
			if err != nil {
				logrus.Fatalf("Failed to create registry (%s): %s", r.URL, err)
			}
			AllRegistries.Add(new)
		}
	}
}
LoadConfig adds the registries parsed from the passed yaml file
package manager
import (
	"net/url"
	"path"
	"path/filepath"
	"runtime"
	"sync"
	"time"
	"github.com/sirupsen/logrus"
	"github.com/spf13/viper"
)
var AllRegistries Registries
var avoidUpdateOnRegistries = make(map[string]struct{})
func init() {
	AllRegistries.Registries = map[string]*Registry{}
	go func() {
		for {
			avoidUpdateOnRegistries = make(map[string]struct{})
			registriesToUpdate := make(map[string]*Registry)
			AllRegistries.Lock()
			for registryName, registry := range AllRegistries.Registries {
				if time.Now().UTC().Sub(registry.LastRefresh) >= registry.TTL {
					registriesToUpdate[registryName] = registry
				}
			}
			AllRegistries.Unlock()
			for registryName, registry := range registriesToUpdate {
				updatedRegistry := registry.Update()
				registriesToUpdate[registryName] = &updatedRegistry
			}
			AllRegistries.Lock()
			for registryName, updatedRegistry := range registriesToUpdate {
				if _, registryExists := AllRegistries.Registries[registryName]; !registryExists {
					continue
				}
				if _, registryWasEdited := avoidUpdateOnRegistries[registryName]; registryWasEdited {
					continue
				}
				AllRegistries.Registries[registryName] = updatedRegistry
			}
			AllRegistries.Unlock()
			time.Sleep(1 * time.Second)
		}
	}()
}
type Registries struct {
	Registries map[string]*Registry
	*viper.Viper
	sync.RWMutex
}
func (rs *Registries) Add(r *Registry) {
	AllRegistries.Lock()
	AllRegistries.Registries[r.Name] = r
	AllRegistries.Unlock()
	logrus.Infof("Added new registry: %s", r.Name)
}
func (rs *Registries) Remove(r *Registry) {
	AllRegistries.Lock()
	delete(AllRegistries.Registries, r.Name)
	AllRegistries.Unlock()
	logrus.Infof("Removed registry: %s", r.Name)
}
func (rs *Registries) Edit(new, old *Registry) {
	AllRegistries.Lock()
	delete(AllRegistries.Registries, old.Name)
	new.History = old.History
	AllRegistries.Registries[new.Name] = new
	avoidUpdateOnRegistries[new.Name] = struct{}{}
	AllRegistries.Unlock()
	logrus.Infof("Edited registry: %s", old.Name)
}
type registriesConfig struct {
	DisplayName          string
	URL                  string
	Port                 int
	Username             string
	Password             string
	SkipTLS              bool   `mapstructure:"skip-tls-validation" yaml:"skip-tls-validation"`
	RefreshRate          string `mapstructure:"refresh-rate" yaml:"refresh-rate"`
	DockerhubIntegration bool   `mapstructure:"dockerhub-integration" yaml:"dockerhub-integration"`
	ReadOnly             bool   `mapstructure:"read-only" yaml:"read-only"`
}