Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mbrt/melting
Go package allowing to melt two heterogeneous structures
https://github.com/mbrt/melting
Last synced: about 1 month ago
JSON representation
Go package allowing to melt two heterogeneous structures
- Host: GitHub
- URL: https://github.com/mbrt/melting
- Owner: mbrt
- License: mit
- Created: 2015-04-19T13:12:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-24T01:58:07.000Z (about 6 years ago)
- Last Synced: 2024-10-16T11:07:08.209Z (3 months ago)
- Language: Go
- Size: 184 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
melting
=========================================================[![GoDoc](https://godoc.org/github.com/mbrt/melting?status.png)](https://godoc.org/github.com/mbrt/melting) [![Build Status](https://travis-ci.org/mbrt/melting.svg)](https://travis-ci.org/mbrt/melting) [![Coverage Status](https://coveralls.io/repos/mbrt/melting/badge.svg)](https://coveralls.io/r/mbrt/melting)
Go package allowing to melt two heterogeneous structures. This is useful for merge configuration structures coming from different sources (e.g. command line vs. configuration file). You can override the configuration file options with the command line flags, even if the types (and so the number and positioning of the fields) are different.
For example:
```go
type Source struct {
F1 int
F2 string
}
type Dest struct {
F1 int
F3 float32
F2 string
}s := Source{F1: 3, F2: "a"}
d := Dest{F1: 4, F2: "b", F3: 3.1}// Source will override Dest for fields 'F1', 'F2';
// field 'F3' will be ignored.
// Note that fields order does not count.
err := Melt(s, &d)
if err != nil {
log.Fatalf("cannot assign source to dest, error %v", err)
}fmt.Printf("Source%v\nDest%v\n", s, d)
```will output:
```
Source{3 a}
Dest{3 3.1 a}
```