Created
July 3, 2017 03:16
-
-
Save therealplato/27e1c3ea716b25674ca158c9b9496cd2 to your computer and use it in GitHub Desktop.
repro: golint generated files problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code generated by protoc-gen-go. | |
// source: contact-list-service.proto | |
// DO NOT EDIT! | |
/* | |
Package main is a generated protocol buffer package. | |
It is generated from these files: | |
asdf.proto | |
hasf.proto | |
It has these top-level messages: | |
Start | |
Stop | |
*/ | |
package main | |
var foo_bar int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"log" | |
) | |
var ( | |
genHdr = []byte("// Code generated ") | |
genFtr = []byte(" DO NOT EDIT.") | |
) | |
func main() { | |
bb, err := ioutil.ReadFile("gen.pb.go") | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(isGenerated(bb)) | |
} | |
// isGenerated reports whether the source file is generated code | |
// according the rules from https://golang.org/s/generatedcode. | |
func isGenerated(src []byte) bool { | |
sc := bufio.NewScanner(bytes.NewReader(src)) | |
for sc.Scan() { | |
b := sc.Bytes() | |
if bytes.HasPrefix(b, genHdr) && bytes.HasSuffix(b, genFtr) && len(b) >= len(genHdr)+len(genFtr) { | |
return true | |
} | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment