Skip to content

Commit 48f16a3

Browse files
committed
docs: add doc about gomod and goenv
1 parent 2ecc99d commit 48f16a3

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

gomod/gomod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package gomod A function to get information about module (go list).
1+
// Package gomod A set of functions to get information about module (go list).
22
package gomod
33

44
import (

readme.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ A collection of small helpers around Go proxy, Go meta information, etc.
1010

1111
A small Go proxy client to get information about a module from a Go proxy.
1212

13+
<details><summary>Example</summary>
14+
1315
```go
1416
package main
1517

@@ -31,10 +33,14 @@ func main() {
3133
}
3234
```
3335

36+
</details>
37+
3438
## metago
3539

3640
A small lib to fetch meta information (`go-import`, `go-source`) for a module.
3741

42+
<details><summary>Example</summary>
43+
3844
```go
3945
package main
4046

@@ -54,10 +60,14 @@ func main() {
5460
}
5561
```
5662

63+
</details>
64+
5765
## Version
5866

5967
Gets information about releases and build.
6068

69+
<details><summary>Examples</summary>
70+
6171
```go
6272
package main
6373

@@ -97,6 +107,121 @@ func main() {
97107
}
98108
```
99109

110+
</details>
111+
100112
## SumDB
101113

102114
- I recommend using the package [sumdb](https://pkg.go.dev/golang.org/x/mod/sumdb?tab=doc)
115+
116+
117+
## gomod
118+
119+
A set of functions to get information about module (`go list`/`go env`).
120+
121+
<details><summary>Examples</summary>
122+
123+
```go
124+
package main
125+
126+
import (
127+
"fmt"
128+
129+
"github.com/ldez/grignotin/gomod"
130+
)
131+
132+
func main() {
133+
info, err := gomod.GetModuleInfo()
134+
if err != nil {
135+
panic(err)
136+
}
137+
138+
fmt.Println(info)
139+
}
140+
```
141+
142+
```go
143+
package main
144+
145+
import (
146+
"fmt"
147+
148+
"github.com/ldez/grignotin/gomod"
149+
)
150+
151+
func main() {
152+
modpath, err := gomod.GetModulePath()
153+
if err != nil {
154+
panic(err)
155+
}
156+
157+
fmt.Println(modpath)
158+
}
159+
160+
```
161+
162+
</details>
163+
164+
## goenv
165+
166+
A set of functions to get information from `go env`.
167+
168+
<details><summary>Examples</summary>
169+
170+
```go
171+
package main
172+
173+
import (
174+
"fmt"
175+
176+
"github.com/ldez/grignotin/goenv"
177+
)
178+
179+
func main() {
180+
value, err := goenv.GetOne(goenv.GOMOD)
181+
if err != nil {
182+
panic(err)
183+
}
184+
185+
fmt.Println(value)
186+
}
187+
```
188+
189+
```go
190+
package main
191+
192+
import (
193+
"fmt"
194+
195+
"github.com/ldez/grignotin/goenv"
196+
)
197+
198+
func main() {
199+
values, err := goenv.Get(goenv.GOMOD, goenv.GOMODCACHE)
200+
if err != nil {
201+
panic(err)
202+
}
203+
204+
fmt.Println(values)
205+
}
206+
```
207+
208+
```go
209+
package main
210+
211+
import (
212+
"fmt"
213+
214+
"github.com/ldez/grignotin/goenv"
215+
)
216+
217+
func main() {
218+
values, err := goenv.GetAll()
219+
if err != nil {
220+
panic(err)
221+
}
222+
223+
fmt.Println(values)
224+
}
225+
```
226+
227+
</details>

0 commit comments

Comments
 (0)