DEV Community

Jacob Hummer
Jacob Hummer

Posted on • Updated on

πŸ“¦ Put dev dependencies in tools.go

TL;DR: Use a tools.go file with //go:build tools to list import _ "github.com/octocat/somedevtool" to stop go mod tidy from removing them.

//go:build tools

package tools

import (
    _ "github.com/melbahja/got/cmd/got"
    _ "github.com/arkady-emelyanov/go-shellparse"
)
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ go mod tidy doesn't care if the package is cmd or lib

Then you can use whatever you list in tools.go in //go:generate and task.go!

package mylib

//go:generate -command got go run github.com/melbahja/got/cmd/got

import (
  "fmt"
  _ "embed"
)
//go:generate got https://example.org/image.png -o image.png
//go:embed image.png
var imagePNG []byte
Enter fullscreen mode Exit fullscreen mode
// task.go
//go:build ignore

package main

import "github.com/arkady-emelyanov/go-shellparse"

func main() {
  // ...
}
Enter fullscreen mode Exit fullscreen mode

🏎 Use task.go for your Go project scripts

Other resources

Top comments (0)