Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 946 Bytes

README.adoc

File metadata and controls

29 lines (23 loc) · 946 Bytes

fsmodtime

Go Reference fsmodtime - Provides functions to determine if you want to build targets from sources based on modification time.

Example

Build a binary if any of the source files have been modified or if the binary does not yet exist.

import (
	"github.com/DavidGamba/dgtools/fsmodtime"
	"github.com/DavidGamba/dgtools/run"
)

		files, modified, err := fsmodtime.Target(os.DirFS("."), []string{"binary_name"}, []string{"go.mod", "go.sum", "*.go"})
		if err != nil {
			return fmt.Errorf("failed to detect changes: %w", err)
		}
		if !modified {
			return nil
		}
		Logger.Printf("Modified files: %v\n", files)

		err = run.CMD("go", "build", "-o", "binary_name").Log().Run()
		if err != nil {
			return fmt.Errorf("failed to build go project: %w", err)
		}