Go R1 Day 65

progress

  • Built mage tasks for go formatting and linting.

Using this approach, you can now drop a magefile.go file into a project and set the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// +build mage

package main

import (

	"github.com/magefile/mage/mg"
	"github.com/pterm/pterm"

	// mage:import
	"github.com/sheldonhull/magetools/gotools"
)

Calling this can be done directly now as part of a startup task.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// Init runs multiple tasks to initialize all the requirements for running a project for a new contributor.
func Init() error {
	fancy.IntroScreen(ci.IsCI())
	pterm.Success.Println("running Init()...")
	mg.Deps(Clean, createDirectories)
	if err := (gotools.Golang{}.Init()); err != nil {  // <----- From another package.
		return err
	}

	return nil
}

Additionally, handled some Windows executable path issues by making sure to wrap up the path resolution.

1
2
3
4
5
6
// if windows detected, add the exe to the binary path
var extension string
if runtime.GOOS == "windows" {
  extension = ".exe"
}
toolPath := filepath.Join("_tools", item+extension)

Webmentions

Reposts  (2)
  • xael bot
  • Amanda