Document APIs

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd) 2020-09-18 11:55:30 +01:00 committed by Alex Ellis
parent 1c8e8bb615
commit cddc10acbe
3 changed files with 19 additions and 16 deletions

View File

@ -71,20 +71,15 @@ func runUp(cmd *cobra.Command, _ []string) error {
log.Printf("Supervisor created in: %s\n", time.Since(start).String()) log.Printf("Supervisor created in: %s\n", time.Since(start).String())
start = time.Now() start = time.Now()
if err := supervisor.Start(services); err != nil {
err = supervisor.Start(services)
if err != nil {
return err return err
} }
defer supervisor.Close() defer supervisor.Close()
log.Printf("Supervisor init done in: %s\n", time.Since(start).String()) log.Printf("Supervisor init done in: %s\n", time.Since(start).String())
shutdownTimeout := time.Second * 1 shutdownTimeout := time.Second * 1
timeout := time.Second * 60 timeout := time.Second * 60
// proxyDoneCh := make(chan bool)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(1) wg.Add(1)
@ -101,8 +96,7 @@ func runUp(cmd *cobra.Command, _ []string) error {
fmt.Println(err) fmt.Println(err)
} }
// Close proxy // TODO: close proxies
// proxyDoneCh <- true
time.AfterFunc(shutdownTimeout, func() { time.AfterFunc(shutdownTimeout, func() {
wg.Done() 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 { for _, v := range proxies {
go v.Start() go v.Start()
} }

View File

@ -9,17 +9,14 @@ import (
"time" "time"
) )
type Resolver interface { // LocalResolver provides hostname to IP look-up for faasd core services
Start()
Get(upstream string, got chan<- string, timeout time.Duration)
}
type LocalResolver struct { type LocalResolver struct {
Path string Path string
Map map[string]string Map map[string]string
Mutex *sync.RWMutex Mutex *sync.RWMutex
} }
// NewLocalResolver creates a new resolver for reading from a hosts file
func NewLocalResolver(path string) Resolver { func NewLocalResolver(path string) Resolver {
return &LocalResolver{ return &LocalResolver{
Path: path, 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() { func (l *LocalResolver) Start() {
var lastStat os.FileInfo 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) { func (l *LocalResolver) Get(upstream string, got chan<- string, timeout time.Duration) {
start := time.Now() start := time.Now()
for { for {

12
pkg/resolver.go Normal file
View File

@ -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)
}