From c992b8ea546e82b9715a867bd89a951b7281d444 Mon Sep 17 00:00:00 2001
From: Patrick Pacher <patrick.pacher@gmail.com>
Date: Wed, 19 Jul 2023 10:59:31 +0200
Subject: [PATCH] Add config annotation to mark a setting as "plan requires"

---
 .gitignore       | 2 ++
 config/option.go | 5 +++++
 config/set.go    | 5 +++--
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0b7b06c..764174c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@ misc
 
 go.mod.*
 vendor
+go.work
+go.work.sum
diff --git a/config/option.go b/config/option.go
index 7337145..4e1173e 100644
--- a/config/option.go
+++ b/config/option.go
@@ -108,6 +108,11 @@ const (
 	// requirement. The type of RequiresAnnotation is []ValueRequirement
 	// or ValueRequirement.
 	RequiresAnnotation = "safing/portbase:config:requires"
+
+	// SettingRequiresFeaturePlan can be used to mark a setting as only available
+	// when the user has a certain feature ID activated by the subscription plan.
+	// The type is []string or string.
+	SettingRequiresFeaturePlan = "safing/portmaster:ui:config:requires-feature"
 )
 
 // QuickSettingsAction defines the action of a quick setting.
diff --git a/config/set.go b/config/set.go
index 41686b4..8b621b8 100644
--- a/config/set.go
+++ b/config/set.go
@@ -52,6 +52,7 @@ func replaceConfig(newValues map[string]interface{}) []*ValidationError {
 
 		option.Lock()
 		option.activeValue = nil
+
 		if ok {
 			valueCache, err := validateValue(option, newValue)
 			if err == nil {
@@ -103,11 +104,11 @@ func replaceDefaultConfig(newValues map[string]interface{}) []*ValidationError {
 }
 
 // SetConfigOption sets a single value in the (prioritized) user defined config.
-func SetConfigOption(key string, value interface{}) error {
+func SetConfigOption(key string, value any) error {
 	return setConfigOption(key, value, true)
 }
 
-func setConfigOption(key string, value interface{}, push bool) (err error) {
+func setConfigOption(key string, value any, push bool) (err error) {
 	option, err := GetOption(key)
 	if err != nil {
 		return err