GoTextReplace is a powerful Go package designed to facilitate bulk text replacement, making it effortless to find and replace content in multiple files. Whether you're managing configuration files, templating, or any other text-based document manipulation, GoTextReplace has you covered.
Minimum Go Version Requirement: 1.15
To quickly get started with GoTextReplace, follow these simple steps:
-
Import the package:
import "github.com/Saranyan-98/GoTextReplace"
-
Initialize the TextReplace struct with your configuration:
replacer := GoTextReplace.TextReplace{
Filename: "sample.txt",
YAMLfile: "tags.yaml",
}
- Use the TextReplace method to execute bulk text replacement:
err := replacer.Run()
if err != nil {
fmt.Println(err)
}
Here's an example of a YAML configuration file (tags.yaml):
name: saranyan
company: XYZ
The source file (sample.txt) contains handlebar tags that need replacement:
My name is {{name}} and I work at {{company}}
You can also specify a custom output file and path for the modified content:
replacer := GoTextReplace.TextReplace{
Filename: "sample.txt",
YAMLfile: "tags.yaml",
OutputFileName: "final.txt",
OutputPath: "./output",
}
err := replacer.Run()
if err != nil {
fmt.Println(err)
}