Public IP endpoint with GET /ip fixing #319

This commit is contained in:
Quentin McGaw
2020-12-27 21:06:00 +00:00
parent 2dc674559e
commit 82a02287ac
7 changed files with 92 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ package publicip
import (
"context"
"net"
"sync"
"time"
@@ -18,6 +19,7 @@ type Looper interface {
Stop()
GetPeriod() (period time.Duration)
SetPeriod(period time.Duration)
GetPublicIP() (publicIP net.IP)
}
type looper struct {
@@ -26,6 +28,8 @@ type looper struct {
getter IPGetter
logger logging.Logger
fileManager files.FileManager
ipMutex sync.RWMutex
ip net.IP
ipStatusFilepath models.Filepath
uid int
gid int
@@ -115,6 +119,7 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
l.logAndWait(ctx, err)
continue
}
l.setPublicIP(ip)
l.logger.Info("Public IP address is %s", ip)
const userReadWritePermissions = 0600
err = l.fileManager.WriteLinesToFile(