From 2e326d354a536ec8626809c9fe9b411d05e79c46 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 8 Oct 2024 17:04:30 +0200 Subject: Use only one Config struct This commit switches from a GlobalConfig struct with named sub-structs to a single struct definition with anonymous sub-structs. The advantage is that there are not so many names the reader has to understand. A custom UnmarshalJSON() function on the Config struct level ensures that the error checking can be embedded into the parsing process and native Go types like net.HardwareAddr can be used in the struct definition while the string-based struct for JSON unmarshaling is an implementation detail of the custom UnmarshalJSON() function. In general the user of this type and its method only has to parse the config with json.Unmarshal(), handle error at this step and can rely on validated configuration data with native Go types from that point on. --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 8302155..20ee049 100644 --- a/main.go +++ b/main.go @@ -38,7 +38,7 @@ func main() { type State struct { sync.Mutex - Config GlobalConfig + Config Config Theme *material.Theme Title string UrlEditor widget.Editor @@ -53,7 +53,7 @@ type Ui struct { State State } -func NewUi(config GlobalConfig) *Ui { +func NewUi(config Config) *Ui { ui := Ui{} ui.State.Config = config -- cgit v1.2.3-70-g09d2