Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom http response status code #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ var (
poll bool
wg sync.WaitGroup

templatesFlag sliceVar
templateDirsFlag sliceVar
stdoutTailFlag sliceVar
stderrTailFlag sliceVar
headersFlag sliceVar
delimsFlag string
delims []string
headers []HttpHeader
urls []url.URL
waitFlag hostFlagsVar
waitRetryInterval time.Duration
waitTimeoutFlag time.Duration
dependencyChan chan struct{}
noOverwriteFlag bool
templatesFlag sliceVar
templateDirsFlag sliceVar
stdoutTailFlag sliceVar
stderrTailFlag sliceVar
headersFlag sliceVar
delimsFlag string
delims []string
headers []HttpHeader
urls []url.URL
waitFlag hostFlagsVar
waitRetryInterval time.Duration
waitTimeoutFlag time.Duration
expectResponseCode int
dependencyChan chan struct{}
noOverwriteFlag bool

ctx context.Context
cancel context.CancelFunc
Expand Down Expand Up @@ -135,7 +136,10 @@ func waitForDependencies() {
if err != nil {
log.Printf("Problem with request: %s. Sleeping %s\n", err.Error(), waitRetryInterval)
time.Sleep(waitRetryInterval)
} else if err == nil && resp.StatusCode >= 200 && resp.StatusCode < 300 {
} else if resp.StatusCode == expectResponseCode {
log.Printf("Received user expected response code %d from %s\n", resp.StatusCode, u.String())
return
} else if err == nil && expectResponseCode == 0 && resp.StatusCode >= 200 && resp.StatusCode < 300 {
log.Printf("Received %d from %s\n", resp.StatusCode, u.String())
return
} else {
Expand Down Expand Up @@ -220,6 +224,7 @@ func main() {
flag.Var(&waitFlag, "wait", "Host (tcp/tcp4/tcp6/http/https/unix/file) to wait for before this container starts. Can be passed multiple times. e.g. tcp://db:5432")
flag.DurationVar(&waitTimeoutFlag, "timeout", 10*time.Second, "Host wait timeout")
flag.DurationVar(&waitRetryInterval, "wait-retry-interval", defaultWaitRetryInterval, "Duration to wait before retrying")
flag.IntVar(&expectResponseCode, "expect-response-code", 0, "Http response code expected")

flag.Usage = usage
flag.Parse()
Expand Down