It's required because:
- go.mod file can contain comments
- easyjson should respect comments and be able to parse go.mod
This commit replaces the logic of parsing go.mod file with the original
one from golang.org/x/mod/modfile package. Tests have been
introduced to check the behavior of `getModulePath` function.
Ref:
- https://golang.org/cmd/go/#hdr-The_go_mod_file
Fix case when file is located in gopath but they have different volume letter. For example:
Error parsing fast.go: file 'E:\!project\go\src\coursera\hw3_bench\fast.go' is not in GOPATH 'e:\!project\go\'
1) filepath.Rel takes care about that;
2) add gopath variable to error
The `chromedp-gen` tool, which makes use of the raw code, always
encounters issues with slow builds. This adds a simple `sync.RWMutex` to
the Go module map package path cache variable that's causing problems.
If a directory is passed to the command line tool, the directory
includes test files, and those test files specify types that the tool is
interested in (e.g. struct types) then it will trigger a compiler error,
fail to generate, and leave some detritus in the target directory.
We should filter out test files from consideration to prevent this error
from occuring. Future development could include a command line option to
process test files, if anyone wants that (unlikely).
Since doc's can be added on both the generic declaration (GenDecl) as well as on the type declaration (TypeSpec) we need to check both.
In order to check both declaration we copy the GenDecl docs to the TypeSpec docs if the TypeSpec has no documentation.
The `chromedp-gen` tool, which makes use of the raw code, would
occassionally encounter a concurrent map write (on slow systems). This
adds a simple `sync.RWMutex` to the map causing problems.