// TrimQuote trim quote for pair's key and value func (p *Pair) TrimQuote() bool { key, match := strings2.TrimQuote(p.Key) if !match { return false } value, match := strings2.TrimQuote(p.Value) if !match { return false } p.Key, p.Value = key, value return true }
func (p Parser) parseStruct(spec *ast.StructType, attrs *Attrs) (err error) { defer nonTypeEnd(&err) for _, f := range spec.Fields.List { attrs.S.Type = "" attrs.S.Doc = p.parseDoc(f.Doc) if f.Type != nil { attrs.S.Type = fmt.Sprint(f.Type) } for _, n := range f.Names { attrs.S.Field = n.Name attrs.S.Tag = "" if f.Tag != nil { tag, _ := strings2.TrimQuote(f.Tag.Value) attrs.S.Tag = reflect.StructTag(tag) } if err = p.Struct(attrs); err != nil { return } } } if len(spec.Fields.List) == 0 { p.Struct(attrs) } return }
func (MySQL) DuplicateKey(err error) string { if err == nil { return "" } // Duplicate entry ... for key 'keyname' const DUPLICATE = "Duplicate" const FORKEY = "for key" s := err.Error() index := strings.Index(s, DUPLICATE) if index < 0 { return "" } s = s[index+len(DUPLICATE):] index = strings.Index(s, FORKEY) + len(FORKEY) if index < 0 { return "" } s, _ = strings2.TrimQuote(s[index:]) return s }
const DUPLICATE = "Duplicate" const FORKEY = "for key" s := err.Error() index := strings.Index(s, DUPLICATE) if index < 0 { return "" } s = s[index+len(DUPLICATE):] index = strings.Index(s, FORKEY) + len(FORKEY) if index < 0 { return "" } s, _ = strings2.TrimQuote(s[index:]) return s } var foreignKey = func(err error) string { if err == nil { return "" } // FOREIGN KEY (`keyname`) const FOREIGNKEY = "FOREIGN KEY " s := err.Error() index := strings.Index(s, FOREIGNKEY) if index < 0 { return ""