diff --git a/cmd/up.go b/cmd/up.go index f4ebd87..9a1986d 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -71,20 +71,15 @@ func runUp(cmd *cobra.Command, _ []string) error { log.Printf("Supervisor created in: %s\n", time.Since(start).String()) start = time.Now() - - err = supervisor.Start(services) - - if err != nil { + if err := supervisor.Start(services); err != nil { return err } - defer supervisor.Close() log.Printf("Supervisor init done in: %s\n", time.Since(start).String()) shutdownTimeout := time.Second * 1 timeout := time.Second * 60 - // proxyDoneCh := make(chan bool) wg := sync.WaitGroup{} wg.Add(1) @@ -101,8 +96,7 @@ func runUp(cmd *cobra.Command, _ []string) error { fmt.Println(err) } - // Close proxy - // proxyDoneCh <- true + // TODO: close proxies time.AfterFunc(shutdownTimeout, func() { wg.Done() }) @@ -130,8 +124,7 @@ func runUp(cmd *cobra.Command, _ []string) error { } } - // wg.Add(len(proxies)) - + // TODO: track proxies for later cancellation when receiving sigint/term for _, v := range proxies { go v.Start() } diff --git a/pkg/local_resolver.go b/pkg/local_resolver.go index df9a113..e1a2b59 100644 --- a/pkg/local_resolver.go +++ b/pkg/local_resolver.go @@ -9,17 +9,14 @@ import ( "time" ) -type Resolver interface { - Start() - Get(upstream string, got chan<- string, timeout time.Duration) -} - +// LocalResolver provides hostname to IP look-up for faasd core services type LocalResolver struct { Path string Map map[string]string Mutex *sync.RWMutex } +// NewLocalResolver creates a new resolver for reading from a hosts file func NewLocalResolver(path string) Resolver { return &LocalResolver{ Path: path, @@ -28,6 +25,7 @@ func NewLocalResolver(path string) Resolver { } } +// Start polling the disk for the hosts file in Path func (l *LocalResolver) Start() { var lastStat os.FileInfo @@ -76,7 +74,7 @@ func (l *LocalResolver) rebuild() { } } -// Get resolve an entry +// Get resolves a hostname to an IP, or timesout after the duration has passed func (l *LocalResolver) Get(upstream string, got chan<- string, timeout time.Duration) { start := time.Now() for { diff --git a/pkg/resolver.go b/pkg/resolver.go new file mode 100644 index 0000000..08761df --- /dev/null +++ b/pkg/resolver.go @@ -0,0 +1,12 @@ +package pkg + +import "time" + +// Resolver resolves an upstream IP address for a given upstream host +type Resolver interface { + // Start any polling or connections required to resolve + Start() + + // Get an IP address using an asynchronous operation + Get(upstream string, got chan<- string, timeout time.Duration) +}