github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/lint/generated.go (about) 1 package lint 2 3 import ( 4 "bufio" 5 "bytes" 6 "io" 7 ) 8 9 var ( 10 // used by cgo before Go 1.11 11 oldCgo = []byte("// Created by cgo - DO NOT EDIT") 12 prefix = []byte("// Code generated ") 13 suffix = []byte(" DO NOT EDIT.") 14 nl = []byte("\n") 15 crnl = []byte("\r\n") 16 ) 17 18 func isGenerated(r io.Reader) bool { 19 br := bufio.NewReader(r) 20 for { 21 s, err := br.ReadBytes('\n') 22 if err != nil && err != io.EOF { 23 return false 24 } 25 s = bytes.TrimSuffix(s, crnl) 26 s = bytes.TrimSuffix(s, nl) 27 if bytes.HasPrefix(s, prefix) && bytes.HasSuffix(s, suffix) { 28 return true 29 } 30 if bytes.Equal(s, oldCgo) { 31 return true 32 } 33 if err == io.EOF { 34 break 35 } 36 } 37 return false 38 }