-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unfortunately healthchecks do not work with scratch images since they do not have systemd, thats why switch runner image to alpine
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strings" | ||
|
||
"github.com/go-playground/validator/v10" | ||
"github.com/knadh/koanf/providers/env" | ||
"github.com/knadh/koanf/v2" | ||
) | ||
|
||
type Config struct { | ||
Addr string `koanf:"addr" validate:"required" json:"addr"` | ||
} | ||
|
||
func main() { | ||
conf := Config{Addr: "localhost:8080"} | ||
|
||
k := koanf.New(".") | ||
k.Load(env.Provider("UNOTONE_", ".", func(s string) string { | ||
s = strings.TrimPrefix(s, "UNOTONE_") | ||
s = strings.ToLower(s) | ||
return s | ||
}), nil) | ||
k.Unmarshal("", &conf) | ||
|
||
validate := validator.New(validator.WithRequiredStructEnabled()) | ||
|
||
if err := validate.Struct(&conf); err != nil { | ||
fmt.Printf("failed ot validate config: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
resp, err := http.Get(fmt.Sprintf("http://%s/health", conf.Addr)) | ||
if err != nil { | ||
fmt.Printf("failed to get healthcheck: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
fmt.Errorf("health check failed with status code %d\n", resp.StatusCode) | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters