diff --git a/.theruziev/taskfile/vars.yml b/.theruziev/taskfile/vars.yml index 8be8d40..92a2555 100644 --- a/.theruziev/taskfile/vars.yml +++ b/.theruziev/taskfile/vars.yml @@ -8,5 +8,5 @@ vars: GIT_BRANCH: sh: git branch --show-current LD_FLAGS: >- - -X '{{.PACKAGE_PREFIX}}/internal/pkg/git.Version={{.GIT_TAG}}' - -X '{{.PACKAGE_PREFIX}}/internal/pkg/git.Commit={{.GIT_COMMIT}}' + -X '{{.PACKAGE_PREFIX}}/internal/pkg/info.Version={{.GIT_TAG}}' + -X '{{.PACKAGE_PREFIX}}/internal/pkg/info.Commit={{.GIT_COMMIT}}' diff --git a/cmd/version.go b/cmd/version.go index 0048bf1..04f541a 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -4,13 +4,13 @@ import ( "encoding/json" "fmt" - "github.com/theruziev/starter/internal/pkg/git" + "github.com/theruziev/starter/internal/pkg/info" ) type versionCli struct{} func (v *versionCli) Run(_ *contextCli) error { - resultJSON, err := json.Marshal(git.Information()) + resultJSON, err := json.Marshal(info.Information()) if err != nil { panic(err) } diff --git a/internal/app/server/app.go b/internal/app/server/app.go index 7a6b960..678ebab 100644 --- a/internal/app/server/app.go +++ b/internal/app/server/app.go @@ -8,8 +8,8 @@ import ( "github.com/go-chi/chi/v5" "github.com/theruziev/starter/internal/pkg/closer" - "github.com/theruziev/starter/internal/pkg/git" "github.com/theruziev/starter/internal/pkg/healthcheck" + "github.com/theruziev/starter/internal/pkg/info" "github.com/theruziev/starter/internal/pkg/logx" "google.golang.org/grpc/health" "google.golang.org/grpc/health/grpc_health_v1" @@ -53,7 +53,7 @@ func (s *Server) initRouter(_ context.Context) { }) r.Get("/live", healthcheck.NewLivenessHandler()) r.Get("/ready", healthcheck.NewReadinessHandler(s.healthcheck)) - r.Get("/version", git.Handler()) + r.Get("/version", info.Handler()) s.r = r } diff --git a/internal/pkg/git/git.go b/internal/pkg/info/info.go similarity index 72% rename from internal/pkg/git/git.go rename to internal/pkg/info/info.go index b3f0fca..9b11459 100644 --- a/internal/pkg/git/git.go +++ b/internal/pkg/info/info.go @@ -1,4 +1,4 @@ -package git +package info import ( "encoding/json" @@ -20,8 +20,9 @@ func Handler() http.HandlerFunc { info := Information() w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - jsonBytes, _ := json.Marshal(info) - _, _ = w.Write(jsonBytes) - + if err := json.NewEncoder(w).Encode(info); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } }