mirror of
https://github.com/zix99/traefik-lazyload.git
synced 2025-12-24 06:28:31 +01:00
Handle signals, code cleanup, easier labels
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"traefik-lazyload/pkg/config"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type containerSettings struct {
|
||||
stopDelay time.Duration
|
||||
waitForCode int
|
||||
waitForPath string
|
||||
stopDelay time.Duration
|
||||
waitForCode int
|
||||
waitForPath string
|
||||
waitForMethod string
|
||||
needs []string
|
||||
}
|
||||
|
||||
type ContainerState struct {
|
||||
@@ -34,26 +34,11 @@ func newStateFromContainer(ct *types.Container) *ContainerState {
|
||||
}
|
||||
|
||||
func extractContainerLabels(ct *types.Container) (target containerSettings) {
|
||||
{ // Parse stop delay
|
||||
stopDelay, _ := labelOrDefault(ct, "stopdelay", config.Model.StopDelay.String())
|
||||
if dur, stopErr := time.ParseDuration(stopDelay); stopErr != nil {
|
||||
target.stopDelay = config.Model.StopDelay
|
||||
logrus.Warnf("Unable to parse stopdelay for %s of %s, defaulting to %s", containerShort(ct), stopDelay, target.stopDelay.String())
|
||||
} else {
|
||||
target.stopDelay = dur
|
||||
}
|
||||
}
|
||||
{ // WaitForCode
|
||||
codeStr, _ := labelOrDefault(ct, "waitforcode", "200")
|
||||
if code, err := strconv.Atoi(codeStr); err != nil {
|
||||
target.waitForCode = 200
|
||||
logrus.Warnf("Unable to parse WaitForCode of %s, defaulting to %d", containerShort(ct), target.waitForCode)
|
||||
} else {
|
||||
target.waitForCode = code
|
||||
}
|
||||
}
|
||||
|
||||
target.stopDelay, _ = labelOrDefaultDuration(ct, "stopdelay", config.Model.StopDelay)
|
||||
target.waitForCode, _ = labelOrDefaultInt(ct, "waitforcode", 200)
|
||||
target.waitForPath, _ = labelOrDefault(ct, "waitforpath", "/")
|
||||
target.waitForMethod, _ = labelOrDefault(ct, "waitformethod", "HEAD")
|
||||
target.needs, _ = labelOrDefaultArr(ct, "needs")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -85,6 +70,19 @@ func (s *containerSettings) StopDelay() string {
|
||||
return s.stopDelay.String()
|
||||
}
|
||||
|
||||
func (s *ContainerState) WaitForCode() int {
|
||||
return s.waitForCode
|
||||
}
|
||||
|
||||
func (s *ContainerState) WaitForPath() string {
|
||||
return s.waitForPath
|
||||
}
|
||||
|
||||
func (s *ContainerState) WaitForMethod() string {
|
||||
return s.waitForMethod
|
||||
}
|
||||
|
||||
// Wrapper for container results that opaques and adds some methods to that data
|
||||
type ContainerWrapper struct {
|
||||
types.Container
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user