-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathREADME.md.template
More file actions
40 lines (35 loc) · 1.52 KB
/
README.md.template
File metadata and controls
40 lines (35 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<$
import (
"fmt"
"io/ioutil"
)
func printFile(f string) {
buf, err := ioutil.ReadFile(f)
if err != nil {
panic(err)
}
fmt.Print(string(buf))
}
$># go-convert [](https://github.com/Eun/go-convert/actions) [](https://coveralls.io/github/Eun/go-convert?branch=master) [](https://pkg.go.dev/github.com/Eun/go-convert) [](https://godoc.org/github.com/Eun/go-convert) [](https://goreportcard.com/report/github.com/Eun/go-convert)
Convert a value into another type.
```bash
go get -u github.com/Eun/go-convert
```
## Usage
```go
<$ printFile("./examples/usage/usage.go") $>
```
## Recipe system
_go-convert_ uses a recipe system that defines how and which types should be converted in which type.
A lot of recipes are already builtin (see [recipes.go](recipes.go)), however you can add your own or overwrite the builtin ones.
```go
<$ printFile("./examples/recipes/recipes.go") $>
```
## Adding inline recipes
You can also add recipes inline by implementing a `ConvertRecipes() []Recipe` function.
Example:
```go
<$ printFile("./examples/inline_recipes/inline_recipes.go") $>
```
### Notice
This library is using reflection so be aware it might be slow in your usecase.