Refactor message.Mode select #32

Closed
opened 2024-11-10 19:19:14 +00:00 by smark · 1 comment
Owner
	switch message.Mode {
	case "Work":
		duration = float64(message.Settings.Work)
	case "ShortBreak":
		duration = float64(message.Settings.ShortBreak)
	case "LongBreak":
		duration = float64(message.Settings.LongBreak)
	}

sollte geschrieben werden können als duration = message.Settings.${message.Mode}

Möglicherweise geht das in Go nicht, die obige Lösung ist aber sehr unschön.

Relevant Files:

  • notification.go
  • terminal.go
``` switch message.Mode { case "Work": duration = float64(message.Settings.Work) case "ShortBreak": duration = float64(message.Settings.ShortBreak) case "LongBreak": duration = float64(message.Settings.LongBreak) } ``` sollte geschrieben werden können als `duration = message.Settings.${message.Mode}` Möglicherweise geht das in Go nicht, die obige Lösung ist aber sehr unschön. Relevant Files: - notification.go - terminal.go
smark changed title from Refactor message.Mode select to Refactor message.Mode select 2024-11-10 19:36:32 +00:00
Author
Owner

One of the main points when using structs is that the way how to access the fields is known at compile time.Then the produced code uses fixed indexes added to a base address of the struct.

For any kind of dynamism here you just need to use map[string]string or similar.

https://stackoverflow.com/a/49428647

> One of the main points when using structs is that the way how to access the fields is known at compile time.Then the produced code uses fixed indexes added to a base address of the struct. > > For any kind of dynamism here you just need to use map[string]string or similar. https://stackoverflow.com/a/49428647
smark closed this issue 2024-11-21 19:06:05 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: pomodoro/ChronoTomato#32
No description provided.