Support rewrite default config from config file or ENV var

Change-Id: Ibd8529b545f3c49fe1e57043e8d5293ff72dfdd1
diff --git a/config/config.go b/config/config.go
index 6c4c9bf..d685708 100644
--- a/config/config.go
+++ b/config/config.go
@@ -38,7 +38,7 @@
 	LayerB      string        `yaml:"layerB,omitempty"`
 	FieldA      string        `yaml:"fieldA,omitempty"`
 	FieldB      string        `yaml:"fieldB,omitempty"`
-	Rewrites    bool          `yaml:"rewrites,omitempty"`
+	Rewrites    *bool         `yaml:"rewrites,omitempty"`
 	Mappings    []MappingRule `yaml:"mappings"`
 }
 
@@ -47,6 +47,16 @@
 	return list.Type == "corpus"
 }
 
+// EffectiveRewrites returns the resolved rewrites setting for this list.
+// If the list has an explicit per-list override, it is used; otherwise the
+// global default is returned.
+func (list *MappingList) EffectiveRewrites(globalDefault bool) bool {
+	if list.Rewrites != nil {
+		return *list.Rewrites
+	}
+	return globalDefault
+}
+
 // ParseCorpusMappings parses all mapping rules as corpus rules.
 // Bare values (without key=) are always allowed and receive the default
 // field name from the mapping list header (FieldA/FieldB) when set.
@@ -102,6 +112,7 @@
 	Port         int           `yaml:"port,omitempty"`
 	LogLevel     string        `yaml:"loglevel,omitempty"`
 	RateLimit    int           `yaml:"rateLimit,omitempty"` // max requests per minute per IP (0 = use default 100)
+	Rewrites     bool          `yaml:"rewrites,omitempty"`  // global default for koral:rewrite annotations
 	Lists        []MappingList `yaml:"lists,omitempty"`
 }
 
@@ -265,6 +276,7 @@
 		Port:         globalConfig.Port,
 		LogLevel:     globalConfig.LogLevel,
 		RateLimit:    globalConfig.RateLimit,
+		Rewrites:     globalConfig.Rewrites,
 		Lists:        allLists,
 	}
 
@@ -341,6 +353,10 @@
 			config.RateLimit = rl
 		}
 	}
+
+	if val := os.Getenv("KORAL_MAPPER_REWRITES"); val != "" {
+		config.Rewrites = val == "true"
+	}
 }
 
 // validateMappingLists validates a slice of mapping lists (without duplicate ID checking)