You can refer the golang scanner and copy the code here. In short, you need to create a scanner and scan the source file by yourself.
reader := bytes.NewBuffer(src)
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
line := scanner.Text()
nline := line
l += len(line)
// copied from src/cmd/compile/internal/syntax/parser.go
text := commentText(line)
// see src/cmd/compile/internal/noder/noder.go#L220
// to handle the gc directive you like.
if strings.HasPrefix(text, "go:linkname ") {
// do y
}
}