Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 228c2a8

Browse files
committed
allow chi v4. Version the gethealth backend.
1 parent d51afba commit 228c2a8

File tree

10 files changed

+21
-13
lines changed

10 files changed

+21
-13
lines changed

Gopkg.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
# go-tests = true
2525
# unused-packages = true
2626

27-
[[override]]
28-
name = "github.com/go-chi/chi"
29-
version = "3.3.2"
27+
# [[override]]
28+
# name = "github.com/go-chi/chi"
29+
# version = "3.3.2"
3030

3131
[prune]
3232
go-tests = true

authenticate/authenticate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type AuthStruct struct {
4646
// AuthCtxKey context key for authentication state & policy map
4747
type AuthCtxKey string
4848

49-
// Authenticate caller
49+
// Authenticate caller's token with vault
5050
func Authenticate(next http.Handler) http.Handler {
5151
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
5252
// Allow heath data without authenticating

health/health.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func Init(db *mgo.Database) {
5050
}
5151
}
5252

53-
// GetHealth Returns the gostint health status
54-
func GetHealth() (*map[string]string, error) {
53+
// GetHealthV1 Returns the gostint health status for api v1
54+
func GetHealthV1() (*map[string]string, error) {
5555
m := make(map[string]string)
5656
m["state"] = state.GetState()
5757

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func getDbCreds() (string, string, error) {
111111
// Routes defines RESTful api middleware and routes.
112112
func Routes() *chi.Mux {
113113
router := chi.NewRouter()
114+
114115
router.Use(
115116
metrics.NewMetrics("gostint"),
116117
render.SetContentType(render.ContentTypeJSON),
@@ -130,6 +131,7 @@ func Routes() *chi.Mux {
130131
r.Mount("/api/metrics", promhttp.Handler())
131132
})
132133

134+
// Allow optional UI user to login
133135
router.Get("/login", func(w http.ResponseWriter, r *http.Request) {
134136
logmsg.Info("/login URL: %v", r.URL)
135137
logmsg.Info("/login RequestURI: %v", r.RequestURI)

metrics/metrics.go

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/prometheus/client_golang/prometheus/promauto"
1111
)
1212

13+
// Prometheus api metrics collector
1314
// inspried by https://github.com/766b/chi-prometheus
1415

1516
const (
@@ -35,6 +36,7 @@ func NewMetrics(name string) func(next http.Handler) http.Handler {
3536
"path",
3637
},
3738
)
39+
3840
return m.handler
3941
}
4042

scripts/init_main.sh

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ wget -qO- https://dl.google.com/go/go${GOVER}.linux-amd64.tar.gz | \
4545
tar zx -C /usr/local/
4646
export PATH=$PATH:/usr/local/go/bin
4747
echo 'export PATH=$PATH:/usr/local/go/bin:~/go/bin' >> ~vagrant/.bashrc
48+
echo 'export GOPATH=$HOME/go' >> ~vagrant/.bashrc
4849

4950
export MYPATH=~vagrant/go/src/github.com/gbevan/gostint
5051

v1/health/health.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ func Routes(db *mgo.Database) *chi.Mux {
5757
return router
5858
}
5959

60+
// To retrieve this Gostint instance's health
6061
func getHealth(w http.ResponseWriter, req *http.Request) {
61-
// timer := prometheus.NewTimer(healthDuration)
62-
// defer timer.ObserveDuration()
63-
6462
req.ParseForm()
6563

66-
h, err := health.GetHealth()
64+
h, err := health.GetHealthV1()
6765
if err != nil {
6866
render.Render(w, req, apierrors.ErrInternalError(err))
6967
return

v1/job/job.go

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type listResponse struct {
117117
Total int `json:"total"`
118118
}
119119

120+
// Retrieve a list of jobs
120121
func listJobs(w http.ResponseWriter, req *http.Request) {
121122
// timer := prometheus.NewTimer(jobDuration.WithLabelValues("listJobs"))
122123
// defer timer.ObserveDuration()
@@ -177,6 +178,7 @@ func listJobs(w http.ResponseWriter, req *http.Request) {
177178
render.JSON(w, req, paginateResp)
178179
}
179180

181+
// Retrieve a Gostint job by Job ID
180182
func getJob(w http.ResponseWriter, req *http.Request) {
181183
// timer := prometheus.NewTimer(jobDuration.WithLabelValues("getJob"))
182184
// defer timer.ObserveDuration()
@@ -222,6 +224,7 @@ type deleteResponse struct {
222224
ID string `json:"_id"`
223225
}
224226

227+
// Delete a Gostint job by Job ID
225228
func deleteJob(w http.ResponseWriter, req *http.Request) {
226229
// timer := prometheus.NewTimer(jobDuration.WithLabelValues("deleteJob"))
227230
// defer timer.ObserveDuration()
@@ -337,6 +340,7 @@ type killResponse struct {
337340
KillRequested bool `json:"kill_requested"`
338341
}
339342

343+
// Kill a Gostint job by Job ID
340344
func killJob(w http.ResponseWriter, req *http.Request) {
341345
// timer := prometheus.NewTimer(jobDuration.WithLabelValues("killJob"))
342346
// defer timer.ObserveDuration()

v1/vault/vault.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func Routes() *chi.Mux {
4747
return router
4848
}
4949

50+
// Retrieve Gotstint's Vault info
5051
func getVault(w http.ResponseWriter, req *http.Request) {
5152
m := make(map[string]string)
5253
m["vault_addr"] = vaultAddr

0 commit comments

Comments
 (0)