From f58b98094825b264b05e4ccb3d60198ce122208e Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 20 Apr 2020 13:23:02 +0300 Subject: [PATCH] Simplify health checkers initialization --- Gopkg.lock | 4 ++-- di/handlers.go | 17 ++--------------- di/mojang_textures.go | 4 ++-- http/skinsystem.go | 2 +- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 788bc15..395335e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -65,7 +65,7 @@ [[projects]] branch = "master" - digest = "1:c6d147728b7bf08b508b13c4547edfd72f900a2b8467b8a7e86d525badef268b" + digest = "1:8c9f13aac9e92f3754ea591b39ada87b9f89f1e75c4b90ccbd0b1084069c436f" name = "github.com/goava/di" packages = [ ".", @@ -73,7 +73,7 @@ "internal/stacktrace", ] pruneopts = "" - revision = "30d61f45552a08a92f8aa54eaad3e7495f091260" + revision = "1eb6eb721bf050edff0efbf15c31636def701b4b" [[projects]] digest = "1:65c7ed49d9f36dd4752e43013323fa9229db60b29aa4f5a75aaecda3130c74e2" diff --git a/di/handlers.go b/di/handlers.go index f326c38..4a2d657 100644 --- a/di/handlers.go +++ b/di/handlers.go @@ -76,7 +76,7 @@ func newHandlerFactory( // Resolve health checkers last, because all the services required by the application // must first be initialized and each of them can publish its own checkers - var healthCheckers []namedHealthCheckerInterface + var healthCheckers []*namedHealthChecker if container.Has(&healthCheckers) { if err := container.Resolve(&healthCheckers); err != nil { return nil, err @@ -84,7 +84,7 @@ func newHandlerFactory( checkersOptions := make([]healthcheck.Option, len(healthCheckers)) for i, checker := range healthCheckers { - checkersOptions[i] = healthcheck.WithChecker(checker.GetName(), checker.GetChecker()) + checkersOptions[i] = healthcheck.WithChecker(checker.Name, checker.Checker) } router.Handle("/healthcheck", healthcheck.Handler()).Methods("GET") @@ -142,20 +142,7 @@ func mount(router *mux.Router, path string, handler http.Handler) { ) } -type namedHealthCheckerInterface interface { - GetName() string - GetChecker() healthcheck.Checker -} - type namedHealthChecker struct { Name string Checker healthcheck.Checker } - -func (c *namedHealthChecker) GetName() string { - return c.Name -} - -func (c *namedHealthChecker) GetChecker() healthcheck.Checker { - return c.Checker -} diff --git a/di/mojang_textures.go b/di/mojang_textures.go index 54f56ad..afd0851 100644 --- a/di/mojang_textures.go +++ b/di/mojang_textures.go @@ -89,7 +89,7 @@ func newMojangTexturesBatchUUIDsProvider( config.GetDuration("healthcheck.mojang_batch_uuids_provider_cool_down_duration"), ), } - }, di.As(new(namedHealthCheckerInterface)), di.WithName("mojangBatchUuidsProviderResponseChecker")); err != nil { + }); err != nil { return nil, err } @@ -103,7 +103,7 @@ func newMojangTexturesBatchUUIDsProvider( config.GetInt("healthcheck.mojang_batch_uuids_provider_queue_length_limit"), ), } - }, di.As(new(namedHealthCheckerInterface)), di.WithName("mojangBatchUuidsProviderQueueLengthChecker")); err != nil { + }); err != nil { return nil, err } diff --git a/http/skinsystem.go b/http/skinsystem.go index 2681b97..d8f7335 100644 --- a/http/skinsystem.go +++ b/http/skinsystem.go @@ -227,7 +227,7 @@ func (ctx *Skinsystem) signedTexturesHandler(response http.ResponseWriter, reque } responseData.Props = append(responseData.Props, &mojang.Property{ - Name: getStringOrDefault(ctx.TexturesExtraParamName, "chrly"), + Name: getStringOrDefault(ctx.TexturesExtraParamName, "chrly"), // TODO: extract to the default param value Value: getStringOrDefault(ctx.TexturesExtraParamValue, "how do you tame a horse in Minecraft?"), })