From edb04392da772f74a918c34ec5f619805ab6477b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 12 Feb 2024 17:29:29 +0100 Subject: [PATCH 1/2] Add initializer for PartialResult This commit adds a NewPartialResult function which returns a PartialResult struct with "sane" default, mainly setting the defaultState to "Unknown". This should help developers implementing this library, since it avoids the following pattern: sc := result.PartialResult{} sc.setDefaultState(check.Unknown) This pattern is quite common, but in a sense useless. --- result/overall.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/result/overall.go b/result/overall.go index de7ccad..1625b28 100644 --- a/result/overall.go +++ b/result/overall.go @@ -41,6 +41,13 @@ type PartialResult struct { defaultStateSet bool // nolint: unused } +func NewPartialResult() PartialResult { + return PartialResult{ + stateSetExplicitly: false, + defaultState: check.Unknown, + } +} + // String returns the status and output of the PartialResult func (s *PartialResult) String() string { return fmt.Sprintf("[%s] %s", check.StatusText(s.GetStatus()), s.Output) From 3557937b0377389954e6609807500a1ffcc0e884 Mon Sep 17 00:00:00 2001 From: RincewindsHat Date: Tue, 13 Feb 2024 08:00:52 +0100 Subject: [PATCH 2/2] Add a little bit of documentation to the new initializer --- result/overall.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/result/overall.go b/result/overall.go index 1625b28..cb58991 100644 --- a/result/overall.go +++ b/result/overall.go @@ -41,6 +41,8 @@ type PartialResult struct { defaultStateSet bool // nolint: unused } +// Initializer for a PartialResult with "sane" defaults +// Notable default compared to the nil object: the default state is set to Unknown func NewPartialResult() PartialResult { return PartialResult{ stateSetExplicitly: false,