This might be a bad idea but I'm trying to parse the go.mod file for data as part of my build process - if at all possible I'd like to avoid duplicating the data that is already there in another file.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CACoUkn4MouSb-spFS-NvdYZdC827%2Bx28pXLD0ABd%3D52AHBvfaw%40mail.gmail.com.
The parsing code will eventually be public, see https://github.com/golang/go/issues/31761
When it is done, you would want golang.org/x/mod/modfile, which will be a (possibly modified) copy of the compiler internal package of the same name.
On Tue, Sep 3, 2019 at 3:29 AM Paul Jolly <pa...@myitcv.io> wrote:
> Sorry I left out the details. So far it's two specific properties I need for instructions in my build process:
>
> 1) The full name of the package
go list -f {{.Name}} example.com/blah
> 2) The version of the protobuf dependency for locking the right version protoc-gen-go before running protoc (that has been asked quite a few times, total hack, but works).
go list -f {{.Version}} -m example.com/blah
Note that if you have a replace directive for example.com/blah then
the replace target might have a version.
For more detail on either of the above see:
go help list
>
> Best,
> James
>
> On Monday, September 2, 2019 at 10:58:53 PM UTC-7, Kurtis Rader wrote:
>>
>> On Mon, Sep 2, 2019 at 10:44 PM James Pettyjohn <japet...@gmail.com> wrote:
>>>
>>> This might be a bad idea but I'm trying to parse the go.mod file for data as part of my build process - if at all possible I'd like to avoid duplicating the data that is already there in another file.
>>
>>
>> In this type of situation you should explain why you need to parse a go.mod file. Especially since you seem to be asking something not already asked a thousand times. It is possible, perhaps likely, the reason you want to do this can be solved some other way.
>>
>> --
>> Kurtis Rader
>> Caretaker of the exceptional canines Junior and Hank
>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/8b716cac-0eb6-4e95-bdde-12ee832e06a4%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.
Also note that you can run:
go mod edit -json
and get JSON output.
go help mod edit
will given you the types you can then use to unmarshal the JSON.
Failing that, the code that Dan referenced has been factored out into:
https://godoc.org/github.com/rogpeppe/go-internal/modfile
On Tue, 3 Sep 2019 at 08:21, James Pettyjohn <japet...@gmail.com> wrote:
>
> Thanks. I saw the same being done by vgo - might be viable.
>
> On Monday, September 2, 2019 at 10:52:45 PM UTC-7, kortschak wrote:
>>
>> Not really exposed, but there is code you could copy.
>>
>> https://golang.org/pkg/cmd/go/internal/modfile/#Parse
>>
>> On Mon, 2019-09-02 at 22:44 -0700, James Pettyjohn wrote:
>> > Hi,
>> >
>> > This might be a bad idea but I'm trying to parse the go.mod file for
>> > data
>> > as part of my build process - if at all possible I'd like to avoid
>> > duplicating the data that is already there in another file.
>> >
>> > Is there an exposed package that can be used for this?
>> >
>> > - J
>> >
>>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.