-
Notifications
You must be signed in to change notification settings - Fork 7
/
recconf.go
884 lines (827 loc) · 22.3 KB
/
recconf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
package recconf
import (
"encoding/json"
"errors"
"os"
"reflect"
"github.com/alibaba/pairec/config"
)
var (
Config *RecommendConfig
adapterName = "json"
//pairecConfigAdapterName = "pairec_config"
)
const (
DaoConf_Adapter_Mysql = "mysql"
DaoConf_Adapter_Redis = "redis"
DaoConf_Adapter_TableStore = "tablestore"
DaoConf_Adapter_HBase = "hbase"
DaoConf_Adapter_Hologres = "hologres"
DataSource_Type_Kafka = "kafka"
DataSource_Type_Datahub = "datahub"
DataSource_Type_ClickHouse = "clickhouse"
DataSource_Type_BE = "be"
DataSource_Type_Lindorm = "lindorm"
DataSource_Type_HBase_Thrift = "hbase_thrift"
DataSource_Type_FeatureStore = "featurestore"
Datasource_Type_Graph = "graph"
BE_RecallType_X2I = "x2i_recall"
BE_RecallType_Vector = "vector_recall"
BE_RecallType_MultiMerge = "multi_merge_recall"
)
func init() {
Config = newRecommendConfig()
}
type RecommendConfig struct {
RunMode string // Run Mode: daily | product
Region string
ListenConf ListenConfig
UserFeatureConfs map[string]SceneFeatureConfig
FeatureConfs map[string]SceneFeatureConfig
SortNames map[string][]string
FilterNames map[string][]string
AlgoConfs []AlgoConfig
RecallConfs []RecallConfig
FilterConfs []FilterConfig
BeFilterConfs []BeFilterConfig
SortConfs []SortConfig
RedisConfs map[string]RedisConfig
MysqlConfs map[string]MysqlConfig
ClickHouseConfs map[string]ClickHouseConfig
HologresConfs map[string]HologresConfig
LindormConfs map[string]LindormConfig
GraphConfs map[string]GraphConfig
FeatureStoreConfs map[string]FeatureStoreConfig
KafkaConfs map[string]KafkaConfig
SlsConfs map[string]SlsConfig
DatahubConfs map[string]DatahubConfig
BEConfs map[string]BEConfig
Ha3EngineConfs map[string]Ha3EngineConfig
HBaseConfs map[string]HBaseConfig
HBaseThriftConfs map[string]HBaseThriftConfig
TableStoreConfs map[string]TableStoreConfig
SceneConfs map[string]map[string]CategoryConfig
RankConf map[string]RankConfig
LogConf LogConfig
ABTestConf ABTestConfig
CallBackConfs map[string]CallBackConfig
GeneralRankConfs map[string]GeneralRankConfig
ColdStartGeneralRankConfs map[string]ColdStartGeneralRankConfig
ColdStartRankConfs map[string]ColdStartRankConfig
DPPConf []DPPSortConfig
DebugConfs map[string]DebugConfig
PipelineConfs map[string][]PipelineConfig
PrometheusConfig PrometheusConfig
UserDefineConfs json.RawMessage
}
type ListenConfig struct {
HttpAddr string
HttpPort int
}
type PrometheusConfig struct {
Enable bool
Subsystem string
PushGatewayURL string
PushIntervalSecs int
Job string
ReqDurBuckets []float64
ReqSizeBuckets []float64
RespSizeBuckets []float64
}
type DaoConfig struct {
Adapter string
AdapterType string
RedisName string
RedisPrefix string
RedisDataType string
RedisFieldType string
RedisDefaultKey string
RedisValueDelimeter string
MysqlName string
MysqlTable string
Config string
TableStoreName string
TableStoreTableName string
HBasePrefix string
HBaseName string
HBaseTable string
ColumnFamily string
Qualifier string
// hologres
HologresName string
HologresTableName string
// clickhouse
ClickHouseName string
ClickHouseTableName string
// be engine
BeName string
BizName string
BeRecallName string
BeTableName string
BeExposureUserIdName string
BeExposureItemIdName string
// feature store
FeatureStoreName string
FeatureStoreModelName string
FeatureStoreEntityName string
// graph
GraphName string
InstanceId string
TableName string
UserNode string
ItemNode string
Edge string
// lindorm
LindormTableName string
LindormName string
}
type SceneFeatureConfig struct {
FeatureLoadConfs []FeatureLoadConfig
AsynLoadFeature bool
}
type FeatureLoadConfig struct {
FeatureDaoConf FeatureDaoConfig
Features []FeatureConfig
}
type BeRTCntFieldConfig struct {
FieldNames []string
// if not set, Delims is empty string by default
// which indicates it is single value with no delimiter
Delims []string
// if not set, Alias is set to FieldNames[0] by default
Alias string
}
type FeatureDaoConfig struct {
DaoConfig
NoUsePlayTimeField bool
FeatureKey string
FeatureStore string // user or item
UserFeatureKeyName string
ItemFeatureKeyName string
TimestampFeatureKeyName string
EventFeatureKeyName string
PlayTimeFeatureKeyName string
TsFeatureKeyName string
UserSelectFields string
ItemSelectFields string
// FeatureAsyncLoad use async goroutine to load feature
FeatureAsyncLoad bool
FeatureType string // per feature type has different way of build
SequenceLength int
SequenceName string
SequenceEvent string
SequenceDelim string
// SequencePlayTime filter event by as least play time
// like play event need to large than 10s, so set value is "play:10000", timeunit is ms
// if has more than one event to filter, use ';' as delim , like "play:10000;read:50000"
SequencePlayTime string
SequenceOfflineTableName string
// SequenceDimFields fetch other dimension fields from db
SequenceDimFields string
BeItemFeatureKeyName string
BeTimestampFeatureKeyName string
BeEventFeatureKeyName string
BePlayTimeFeatureKeyName string
BeIsHomeField string
// separate by , if combined by multiple fields separate by :
// [depreciated], please set BeRTCntFieldInfo.FieldNames instead
BeRTCntFields string
BeRTCntFieldInfo []BeRTCntFieldConfig
BeRTTable string
RTCntWins string
RTCntMaxKey int
RTCntWinDelay int
OutRTCntFeaPattern string
OutHomeRTCntFeaPattern string
// [depreciated], please set BeRTCntFieldInfo.Alias instead
OutRTCntFieldAlias string
OutRTCntWinNames string
OutEventName string
// CacheFeaturesName When use UserFeatureConfs, can cache load features to the user cacheFeatures map.
// Only valid when FeatureStore = user
CacheFeaturesName string
// LoadFromCacheFeaturesName load features from user cacheFeatures map
// Only valid when FeatureStore = user
LoadFromCacheFeaturesName string
}
type FeatureConfig struct {
FeatureType string
FeatureName string
FeatureSource string
FeatureValue string
FeatureStore string // user or item
RemoveFeatureSource bool // delete feature source
Normalizer string
Expression string
}
type AlgoConfig struct {
Name string
Type string
EasConf EasConfig
VectorConf VectorConfig
MilvusConf MilvusConfig
LookupConf LookupConfig
SeldonConf SeldonConfig
TFservingConf TFservingConfig
}
type PIDControllerConfig struct {
SyncPIDStatus bool
HologresName string
LoadItemFeature bool
PreloadItemFeature bool
AllocateExperimentWise bool
MaxItemCacheSize int
MaxItemCacheTime int
RedisName string
RedisKeyPrefix string
SampleTime float32
DefaultKp float32
DefaultKi float32
DefaultKd float32
TestTimestamp int64
BoostScoreConditions []BoostScoreCondition
}
type LookupConfig struct {
FieldName string
}
type EasConfig struct {
Processor string
Url string
Auth string
EndpointType string
SignatureName string
Timeout int
RetryTimes int
ResponseFuncName string
Outputs []string
ModelName string
}
type TFservingConfig struct {
Url string
SignatureName string
Timeout int
RetryTimes int
ResponseFuncName string
Outputs []string
}
type SeldonConfig struct {
Url string
ResponseFuncName string
}
type VectorConfig struct {
ServerAddress string
Timeout int64
}
type MilvusConfig struct {
ServerAddress string
Timeout int64
}
type RecallConfig struct {
Name string
RecallType string
RecallCount int
RecallAlgo string
ItemType string
CacheAdapter string
CacheConfig string
CachePrefix string
CacheTime int // cache time by seconds
Triggers []TriggerConfig
HologresVectorConf HologresVectorConfig
BeVectorConf BeVectorConfig
MilvusVectorConf MilvusVectorConfig
UserCollaborativeDaoConf UserCollaborativeDaoConfig
ItemCollaborativeDaoConf ItemCollaborativeDaoConfig
User2ItemDaoConf User2ItemDaoConfig
UserTopicDaoConf UserTopicDaoConfig
DaoConf DaoConfig
VectorDaoConf VectorDaoConfig
ColdStartDaoConf ColdStartDaoConfig
RealTimeUser2ItemDaoConf RealTimeUser2ItemDaoConfig
UserFeatureConfs []FeatureLoadConfig // get user features
// be recall config
BeConf BeConfig
GraphConf GraphConf
}
type GraphConf struct {
GraphName string
ItemId string
QueryString string
Params []string
}
type BeConfig struct {
Count int
BeName string
BizName string
BeRecallType string
RecallNameMapping map[string]RecallNameMappingConfig
BeRecallParams []BeRecallParam
BeFilterNames []string
BeABParams map[string]interface{}
}
type RecallNameMappingConfig struct {
Format string
Fields []string
}
type BeRecallParam struct {
Count int
Priority int
RecallType string
RecallName string
ScorerClause string
TriggerType string // user or be or fixvalue or user_vector
UserTriggers []TriggerConfig
TriggerValue string //
TriggerParam BeTriggerParam
//RecallParamName string
UserVectorTrigger UserVectorTriggerConfig
UserTriggerDaoConf UserTriggerDaoConfig // online table for u2i
UserTriggerRulesConf UserTriggerRulesConfig // be recall diversity trigger, trigger have diff recall count
UserCollaborativeDaoConf UserCollaborativeDaoConfig // offline table for u2i
UserRealtimeEmbeddingTrigger UserRealtimeEmbeddingTriggerConfig // get user feature and invoke eas model, get item embedding sink to be
UserEmbeddingO2OTrigger UserEmbeddingO2OTriggerConfig
ItemIdName string
TriggerIdName string
RecallTableName string
DiversityParam string
CustomParams map[string]interface{}
}
type UserTriggerRulesConfig struct {
DefaultValue int
TriggerCounts []int
}
type UserVectorTriggerConfig struct {
CacheTime int
CachePrefix string
RecallAlgo string
UserFeatureConfs []FeatureLoadConfig // get user features
}
type UserEmbeddingO2OTriggerConfig struct {
BizName string
RecallName string
BeName string
SeqDelimiter string // seq feature delimiter
MultiValueDelimiter string // multi value feature delimiter
UserFeatureConfs []FeatureLoadConfig // get user features
}
type UserRealtimeEmbeddingTriggerConfig struct {
Debug bool
DebugLogDatahub string
EmbeddingNum int
RecallAlgo string
DistinctParamName string
DistinctParamValue string
UserFeatureConfs []FeatureLoadConfig // get user features
}
type BeTriggerParam struct {
BizName string
FieldName string
}
type ColdStartDaoConfig struct {
SqlDaoConfig
TimeInterval int // second
}
type SqlDaoConfig struct {
DaoConfig
Limit int
WhereClause string
PrimaryKey string
SelectFields string
}
type RealTimeUser2ItemDaoConfig struct {
UserTriggerDaoConf UserTriggerDaoConfig
Item2ItemTable string
}
type UserTriggerDaoConfig struct {
SqlDaoConfig
NoUsePlayTimeField bool
ItemCount int
TriggerCount int
EventPlayTime string
EventWeight string
WeightExpression string
WeightMode string
PropertyFields []string
DiversityRules []TriggerDiversityRuleConfig
BeItemFeatureKeyName string
BeTimestampFeatureKeyName string
BeEventFeatureKeyName string
BePlayTimeFeatureKeyName string
}
type TriggerDiversityRuleConfig struct {
Dimensions []string
Size int
}
type HologresVectorConfig struct {
HologresName string
VectorTable string // example: "item_emb_{partition}", '{partition}' will be replaced by partition info
VectorKeyField string
VectorEmbeddingField string
WhereClause string
TimeInterval int
}
type BeVectorConfig struct {
BizName string //
VectorKeyField string
VectorEmbeddingField string
}
type MilvusVectorConfig struct {
VectorKeyField string
VectorEmbeddingField string
CollectionName string
MetricType string
SearchParams map[string]interface{}
}
type UserCollaborativeDaoConfig struct {
DaoConfig
User2ItemTable string
Item2ItemTable string
Normalization string // set "on" to enable it, otherwise set "off", enabled by default
}
type ItemCollaborativeDaoConfig struct {
DaoConfig
Item2ItemTable string
}
type User2ItemDaoConfig struct {
DaoConfig
User2ItemTable string
Item2ItemTable string
}
type UserTopicDaoConfig struct {
DaoConfig
UserTopicTable string
TopicItemTable string
IndexName string
}
type VectorDaoConfig struct {
DaoConfig
EmbeddingField string
KeyField string
// set the following fields to get partition info,
// if not set, '{partition}' in table name won't be replaced (if it exists)
PartitionInfoTable string
PartitionInfoField string
}
type GraphConfig struct {
Host string
UserName string
Passwd string
}
type RedisConfig struct {
Host string
Port int
Password string
DbNum int
MaxIdle int
ConnectTimeout int
ReadTimeout int
WriteTimeout int
}
type MysqlConfig struct {
DSN string
}
type ClickHouseConfig struct {
DSN string
}
type HologresConfig struct {
DSN string
}
type LindormConfig struct {
Url string
User string
Password string
Database string
}
type FeatureStoreConfig struct {
Host string
Token string
ProjectName string
}
type KafkaConfig struct {
BootstrapServers string
Topic string
}
type DatahubConfig struct {
AccessId string
AccessKey string
Endpoint string
ProjectName string
TopicName string
Schemas []DatahubTopicSchema
}
type BEConfig struct {
Username string
Password string
Endpoint string
ReleaseType string // values: product or dev or prepub
}
type Ha3EngineConfig struct {
Username string
Password string
Endpoint string
InstanceId string
}
type DatahubTopicSchema struct {
Field string
//Type is the type of the datahub tuple field,valid value is string, integer
Type string
}
type HBaseConfig struct {
ZKQuorum string
}
type HBaseThriftConfig struct {
Host string
User string
Password string
}
type TableStoreConfig struct {
EndPoint string
InstanceName string
AccessKeyId string
AccessKeySecret string
RoleArn string
}
type SlsConfig struct {
EndPoint string
AccessKeyId string
AccessKeySecret string
ProjectName string
LogstoreName string
}
type SceneConfig struct {
Categories []string
}
type CategoryConfig struct {
RecallNames []string
}
type RankConfig struct {
RankAlgoList []string
RankScore string
Processor string
ContextFeatures []string
BatchCount int
ScoreRewrite map[string]string
}
type ActionConfig struct {
ActionType string
ActionName string
}
type OperatorValueConfig struct {
Type string // "property", "function"
Name string
From string // item or user
}
type LogConfig struct {
RetensionDays int
DiskSize int // unit : G, if value = 20, the true size is 20G
LogLevel string // valid value is DEBUG, INFO , ERROR , FATAL
Output string // valid value is file, console
SLSName string
}
type ABTestConfig struct {
Host string
Token string
}
type FilterConfig struct {
Name string
FilterType string
DaoConf DaoConfig
MaxItems int
TimeInterval int // second
RetainNum int
ShuffleItem bool
WriteLog bool
ClearLogIfNotEnoughScene string
Dimension string
ScoreWeight float64
GroupMinNum int
GroupMaxNum int
GroupWeightStrategy string
GroupWeightDimensionLimit map[string]int
WriteLogExcludeScenes []string
GenerateItemDataFuncName string
AdjustCountConfs []AdjustCountConfig
ItemStateDaoConf ItemStateDaoConfig
FilterEvaluableExpression string
FilterParams []FilterParamConfig
DiversityDaoConf DiversityDaoConfig
DiversityMinCount int
EnsureDiversity bool
FilterVal FilterValue
}
type BeFilterConfig struct {
FilterConfig
}
type FilterValue struct {
SelectCol string
WhereClause string
}
type SortConfig struct {
Debug bool
RemainItem bool
Name string
SortType string
SortByField string
SwitchThreshold float64
DiversitySize int
Size int
DPPConf DPPSortConfig
PIDConf PIDControllerConfig
MixSortRules []MixSortConfig
BoostScoreConditionsFilterAll bool
BoostScoreConditions []BoostScoreCondition
DistinctIdConditions []DistinctIdCondition
Conditions []FilterParamConfig
ExcludeRecalls []string
DiversityRules []DiversityRuleConfig
TimeInterval int
BoostScoreByWeightDao BoostScoreByWeightDaoConfig
}
type BoostScoreByWeightDaoConfig struct {
DaoConfig
ItemFieldName string
WeightFieldName string
}
type MixSortConfig struct {
MixStrategy string // fix_position, random_position
Positions []int
PositionField string
Number int
NumberRate float64
RecallNames []string
Conditions []FilterParamConfig
}
type DiversityRuleConfig struct {
Dimensions []string
IntervalSize int
WindowSize int
FrequencySize int
}
type FilterParamConfig struct {
Name string
Domain string
Operator string
Type string // string, int, int64
Value interface{}
}
type BoostScoreCondition struct {
Expression string
Conditions []FilterParamConfig
}
type DistinctIdCondition struct {
DistinctId int
Conditions []FilterParamConfig
}
type ItemStateDaoConfig struct {
DaoConfig
ItemFieldName string
WhereClause string
SelectFields string
}
type DiversityDaoConfig struct {
DaoConfig
ItemKeyField string
DistinctFields []string
CacheTimeInMinutes int
}
type AdjustCountConfig struct {
RecallName string
Count int
Type string
}
type CallBackConfig struct {
DataSource DataSourceConfig
RankConf RankConfig
RawFeatures bool
RawFeaturesRate int
}
type GeneralRankConfig struct {
FeatureLoadConfs []FeatureLoadConfig
RankConf RankConfig
ActionConfs []ActionConfig
}
type ColdStartGeneralRankConfig struct {
GeneralRankConfig
RecallNames []string
}
type ColdStartRankConfig struct {
RecallName string
AlgoName string
OnlyEmbeddingFeature bool
}
type DataSourceConfig struct {
Name string
Type string
}
type TriggerConfig struct {
TriggerKey string
DefaultValue string
Boundaries []int
}
type DPPSortConfig struct {
Name string
DaoConf DaoConfig
TableName string
TableSuffixParam string
TablePKey string
EmbeddingColumn string
EmbeddingSeparator string
Alpha float64
CacheTimeInMinutes int
EmbeddingHookNames []string
NormalizeEmb string
WindowSize int
EmbMissedThreshold float64
FilterRetrieveIds []string
EnsurePositiveSim string
}
type DebugConfig struct {
Rate int
DebugUsers []string
// OutputType represent log write to console or datahub or file
OutputType string
DatahubName string
FilePath string
MaxFileNum int
}
type PipelineConfig struct {
Name string
RecallNames []string
FilterNames []string
GeneralRankConf GeneralRankConfig
FeatureLoadConfs []FeatureLoadConfig
RankConf RankConfig
ColdStartRankConf ColdStartRankConfig
SortNames []string
}
func newRecommendConfig() *RecommendConfig {
conf := RecommendConfig{
RunMode: "daily",
ListenConf: ListenConfig{
HttpAddr: "",
HttpPort: 8000,
},
}
return &conf
}
func CopyConfig(src, dst *RecommendConfig, filters ...func(string) bool) {
srcVal := reflect.ValueOf(src).Elem()
srcType := reflect.TypeOf(src).Elem()
dstVal := reflect.ValueOf(dst).Elem()
numOfFields := srcVal.NumField()
for i := 0; i < numOfFields; i++ {
fieldType := srcType.Field(i)
flag := true
for _, filter := range filters {
flag = filter(fieldType.Name)
if !flag {
break
}
}
if !flag {
continue
}
elemField := dstVal.FieldByName(fieldType.Name)
if elemField.CanSet() {
fieldVal := srcVal.Field(i)
elemField.Set(fieldVal)
}
}
}
func loadConfigFromFile(filePath string) error {
configer, err := config.NewConfig(adapterName, filePath)
if err != nil {
return err
}
rawdata := configer.RawData()
err = json.Unmarshal(rawdata, Config)
if err != nil {
return err
}
return nil
}
// LoadConfig load config from file or pairec config server
// First check the environment CONFIG_NAME, if exist, load config data from pairec config server
func LoadConfig(filePath string) error {
if filePath == "" {
filePath = os.Getenv("CONFIG_PATH")
}
if filePath == "" {
return errors.New("config file path empty")
}
return loadConfigFromFile(filePath)
}
var notifyCh = make([]chan *RecommendConfig, 0)
func Subscribe() <-chan *RecommendConfig {
ch := make(chan *RecommendConfig)
notifyCh = append(notifyCh, ch)
return ch
}
func UpdateConf(conf *RecommendConfig) {
Config = conf
go func() {
for _, ch := range notifyCh {
ch <- conf
}
}()
}