Installation
Requirements
Section titled “Requirements”- Go 1.26 or later
- An active Go module (
go.mod)
Install
Section titled “Install”Run this in your project directory:
go get github.com/larsartmann/go-atomic-write@latestQuick Usage
Section titled “Quick Usage”package main
import ( "errors" "fmt" "os"
atomicwrite "github.com/larsartmann/go-atomic-write")
func main() { path := "/path/to/config.json"
data, err := os.ReadFile(path) if err != nil && !os.IsNotExist(err) { panic(err) } fp := atomicwrite.FingerprintFromBytes(data)
newData := []byte(`{"updated": true}`)
err = atomicwrite.Write(path, newData, fp) if errors.Is(err, atomicwrite.ErrConcurrentModification) { fmt.Println("file was modified concurrently — re-read and retry") return } if err != nil { panic(err) }}Verify Installation
Section titled “Verify Installation”go list -m github.com/larsartmann/go-atomic-writeNext Steps
Section titled “Next Steps”- Follow the Quick Start for complete examples
- Learn about Error Handling for concurrent modification detection
- See Platform Support for OS-specific behavior