Skip to content

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:

// +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.

// 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.

// 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)