Repository navigation
ip transformer修改 - #730
ip transformer修改#730
Conversation
|
已实测 |
| DefaultNoUse: true, | ||
| Description: "IP数据库路径(data_path)", | ||
| Type: transforms.TransformTypeString, | ||
| AdvanceDepend: transforms.LocalEnable, |
There was a problem hiding this comment.
根据前端的功能做对应修改:https://jira.qiniu.io/browse/PDR-7261
| Required: true, | ||
| DefaultNoUse: false, | ||
| Description: "使用本地解析", | ||
| Type: transforms.TransformTypeBoolean, |
There was a problem hiding this comment.
说明一下本地IP解析和服务端解析最大的区别:
- 本地解析是用客户自己的IP库,更为灵活。
- 服务端解析是固定使用七牛IP库,用户无需提供IP库
|
|
||
| func (t *Transformer) Init() error { | ||
| if t.Key != "" { | ||
| t.LocalEnable = true |
09587ff to
214b7f8
Compare
| config := make(map[string]interface{}) | ||
| config[transforms.KeyType] = Name | ||
| config[transforms.LocalEnable] = t.LocalEnable | ||
| t.keys = GetKeys(t.Key) |
There was a problem hiding this comment.
这里不用GetKeys了,直接原样给出去,在pandora-go-sdk里面去split,然后转成DSL的结构
| transforms.KeyFieldName, | ||
| { | ||
| KeyName: "data_path", | ||
| KeyName: transforms.LocalEnable, |
There was a problem hiding this comment.
这个key的名字不应该叫localEnable了,叫 At 或者 TransformAt
| } | ||
|
|
||
| func setSenderConfig(senderConfig conf.MapConf, serverConfigs []map[string]interface{}) conf.MapConf { | ||
| if senderConfig[sender.KeySenderType] != sender.TypePandora { |
There was a problem hiding this comment.
sender.Type可以作为参数传进来,也许以后别的Sender也要这样
| } | ||
| autoCreate := senderConfig[sender.KeyPandoraAutoCreate] | ||
| localEnable, localEnableOk := serverConfig[transforms.LocalEnable].(string) | ||
| if localEnableOk && localEnable == ip.Local { |
There was a problem hiding this comment.
localEnable == ip.Server
| } else if index := strings.Index(autoCreate, schema); index != -1 { | ||
| autoCreate = autoCreate[:index] + autoCreate[index+len(schema):] | ||
| } | ||
| senderConfig[sender.KeyPandoraAutoCreate] = autoCreate |
There was a problem hiding this comment.
我觉得这块逻辑要单独做个函数,叫inject Ip Transformer config,以后别人再加个类似的函数就行了,不需要理解你这块for循环里的细节逻辑
|
|
||
| if !strings.Contains(autoCreate, KeyIP) { | ||
| senderConfig[sender.KeyPandoraAutoCreate] += fmt.Sprintf(",%v ip", key) | ||
| } |
There was a problem hiding this comment.
这里拼接的方式可能要修改,看服务端未来会不会支持嵌套类型指定IP字段
7a75786 to
27078fa
Compare
| var err error | ||
| for _, serverConfig := range serverConfigs { | ||
| keyType, ok := serverConfig[transforms.KeyType].(string) | ||
| if !ok || keyType != ip.Name { |
There was a problem hiding this comment.
不用再pandorakeyType是不是等于ip.Name了,下面会switch
| return senderConfig, fmt.Errorf("key: %v ip transform key in server doesn't support dot(.)", key) | ||
| } | ||
| autoCreate := senderConfig[sender.KeyPandoraAutoCreate] | ||
| transformAt, transformAtOk := serverConfig[transforms.TransformAt].(string) |
There was a problem hiding this comment.
先pandora TransformAtOk为false的情况,直接return
| return senderConfig, nil | ||
| } | ||
|
|
||
| if !strings.Contains(autoCreate, KeyIP) { |
There was a problem hiding this comment.
这里不应该判断这个,我可以有多个IP字段通过服务端解析
| } | ||
|
|
||
| if autoCreate == "" { | ||
| senderConfig[sender.KeyPandoraAutoCreate] = fmt.Sprintf("%v ip", key) |
There was a problem hiding this comment.
你这里要不直接用字符串拼接更好,而且你专门写了个 KeyIP可以用上。
用fmt的时候,能 %s 尽量不要 %v 哈
207c9ce to
91da253
Compare
| return tags | ||
| } | ||
|
|
||
| func setSenderConfig(senderConfig conf.MapConf, serverConfigs []map[string]interface{}) (conf.MapConf, error) { |
There was a problem hiding this comment.
如果只允许Pandora Sender,函数名可以明确的写 setPandoraServerConfig
| Description: "mmdb格式库使用的语种", | ||
| Advance: true, | ||
| Description: "要进行Transform变化的键(key)", | ||
| ToolTip: "对该字段的值进行transform变换, 服务端不支持嵌套(.)", |
There was a problem hiding this comment.
后面加上,“对该字段的值进行transform变换, 服务端转换不支持嵌套(.),请先使用rename,本地转换支持”
|
comments都修改了 |
|
LGTM |
@wonderflow
@unknwon
ip transfomer 增加选项 local_enable, 表示是否使用本地ip解析,默认为false,使用服务端解析
如果local_enable,pandora sender处相应修改schema