Skip to content

Commit

Permalink
simple health check
Browse files Browse the repository at this point in the history
  • Loading branch information
archmagece committed Sep 5, 2024
1 parent 14dedfc commit 9069bcb
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 102 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ tmp/
~tmp/
~/
tmpconf/
*-test.yaml
*-test.yml
*-test.json
26 changes: 18 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,54 @@ go 1.22
require (
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/assert/v2 v2.2.0
github.com/go-sql-driver/mysql v1.8.1
github.com/joho/godotenv v1.5.1
github.com/mitchellh/go-homedir v1.1.0
gopkg.in/testfixtures.v2 v2.6.0
github.com/tavsec/gin-healthcheck v1.6.3
gopkg.in/yaml.v3 v3.0.1
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/bytedance/sonic v1.11.9 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/influxdata/influxdb-client-go/v2 v2.13.0 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lib/pq v1.1.1 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/oapi-codegen/runtime v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/redis/go-redis/v9 v9.6.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.16.1 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
114 changes: 71 additions & 43 deletions go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func main() {
fmt.Print(e)
}

r := routers.SetupRouter()
r := routers.BaseRouter()
routers.HealthRouter(r)
routers.ProxyRouter(r)

port := os.Getenv("port")
Expand Down
4 changes: 2 additions & 2 deletions routers/base_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"github.com/gin-gonic/gin"
)

// SetupRouter function will perform all route operations
func SetupRouter() *gin.Engine {
// BaseRouter function will perform all route operations
func BaseRouter() *gin.Engine {
r := gin.Default()

//Giving access to storage folder
Expand Down
22 changes: 22 additions & 0 deletions routers/health_router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package routers

import (
"github.com/gin-gonic/gin"
healthcheck "github.com/tavsec/gin-healthcheck"
"github.com/tavsec/gin-healthcheck/checks"
"github.com/tavsec/gin-healthcheck/config"
)

func HealthRouter(r *gin.Engine) {
//confDirCheck := checks.NewEnvCheck("BASE_DIR")
// You can also validate env format using regex
//BaseDirCheck := checks.NewEnvCheck("BASE_DIR")
//BaseDirCheck.SetRegexValidator("^(~|/).+")
//healthcheck.New(r, config.DefaultConfig(), []checks.Check{confDirCheck})

//ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
//defer stop()
//signalsCheck := checks.NewContextCheck(ctx, "signals")
//healthcheck.New(r, config.DefaultConfig(), []checks.Check{signalsCheck})
healthcheck.New(r, config.DefaultConfig(), []checks.Check{})
}
4 changes: 0 additions & 4 deletions seeder/fixtures/user.yml

This file was deleted.

43 changes: 0 additions & 43 deletions seeder/seeder.go

This file was deleted.

6 changes: 5 additions & 1 deletion templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@

<h1>Deproxy Dashboard</h1>

<h2>Status</h2>
<div>Running: {{.running}}</div>
<div>Healthz: <a href="/healthz">status</a></div>

<h2>Maven</h2>
{{range .mavenProxy}}
<div><a href="{{.Url}}">{{.Name}}</a> {{.Url}}</div>
<div><a href="{{ .Url }}">{{.Name}}</a> {{.Url}}</div>
{{end}}

<h2>Apt</h2>
Expand Down

0 comments on commit 9069bcb

Please sign in to comment.