https://github.com/imkira/go-interpol
interpol is a Go package for doing format-string like string interpolation using named parameters.
https://github.com/imkira/go-interpol
go interpolation template
Last synced: 5 months ago
JSON representation
interpol is a Go package for doing format-string like string interpolation using named parameters.
- Host: GitHub
- URL: https://github.com/imkira/go-interpol
- Owner: imkira
- License: mit
- Created: 2016-02-24T10:25:17.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-12-15T14:40:21.000Z (over 7 years ago)
- Last Synced: 2024-06-18T14:59:29.310Z (about 2 years ago)
- Topics: go, interpolation, template
- Language: Go
- Size: 11.7 KB
- Stars: 42
- Watchers: 2
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# interpol
[](https://github.com/imkira/go-interpol/blob/master/LICENSE.txt)
[](https://godoc.org/github.com/imkira/go-interpol)
[](https://travis-ci.org/imkira/go-interpol)
[](https://codecov.io/gh/imkira/go-interpol)
[](https://codebeat.co/projects/github-com-imkira-go-interpol)
[](https://goreportcard.com/report/github.com/imkira/go-interpol)
interpol is a [Go](http://golang.org) package for doing format-string like
string interpolation using named parameters.
Currently, a template only accepts variable placeholders delimited by brace
characters (eg. "Hello {foo} {bar}").
## Install
First, you need to install the package:
```go
go get -u github.com/imkira/go-interpol
```
## Documentation
For advanced usage, make sure to check the
[available documentation here](http://godoc.org/github.com/imkira/go-interpol).
## Example
The following code should use `interpol.WithMap` function, which simply
replaces every key with the corresponding value of the specified map.
When run, it should output `Hello World!!!`.
```go
package main
import (
"fmt"
"github.com/imkira/go-interpol"
)
func main() {
m := map[string]string{
"foo": "Hello",
"bar": "World",
}
str, err := interpol.WithMap("{foo} {bar}!!!", m)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(str)
}
```
## Contribute
Found a bug? Want to contribute and add a new feature?
Please fork this project and send me a pull request!
## License
go-interpol is licensed under the MIT license:
www.opensource.org/licenses/MIT
## Copyright
Copyright (c) 2016 Mario Freitas. See
[LICENSE](http://github.com/imkira/go-interpol/blob/master/LICENSE)
for further details.