func splice_n_key(cfg *generator.Cfg_t, prefix string) string { var n_key int = len(cfg.Keys) if n_key <= 1 { return "" } var is_key_has_str bool = false for _, keyidx := range cfg.Keys { if cfg.Fields[keyidx].Fieldtype == generator.Fieldtype_string { is_key_has_str = true break } } var keys generator.Fieldvec_t for _, keyidx := range cfg.Keys { var key generator.Field_t = cfg.Fields[keyidx] key.En_name = prefix + key.En_name keys = append(keys, key) } var text string if is_key_has_str { text = splice_str_key(&keys) } else { text = splice_int_key(keys) } return text }
func gen_n_key_map_insert_stmt(cfg *generator.Cfg_t) string { var n_key int = len(cfg.Keys) if n_key <= 1 { return "" } var keys generator.Fieldvec_t for _, v := range cfg.Keys { var key generator.Field_t = cfg.Fields[v] // 注意,这里进行了赋值拷贝 key.En_name = "cfg." + key.En_name keys = append(keys, key) } var map_key string = "\n " + splice_n_key(cfg, "cfg.") var map_insert string = "\n m_%map%[key] = curcfg;\n" map_insert = strings.Replace(map_insert, "%map%", get_n_key_map_name(cfg), -1) return map_key + map_insert }