Skip to content

Latest commit

 

History

History

fsmodtime

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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