mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-01-21 17:32:50 +08:00
ec723b2112
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. sample-controller: add example CRD controller **What this PR does / why we need it**: Adds a sample-controller example repository fixes #52752 **Special notes for your reviewer**: This is currently based on the sttts:sttts-codegen-scripts branch and should not be merged until that is (ref https://github.com/kubernetes/kubernetes/pull/52186) **Release note**: ``` Add sample-controller repository ``` /cc @sttts @nikhita @colemickens Kubernetes-commit: 9a7800f7d2efb88b397674672ac56f898826cf7c
69 lines
2.7 KiB
Markdown
69 lines
2.7 KiB
Markdown
# Mergo
|
|
|
|
A helper to merge structs and maps in Golang. Useful for configuration default values, avoiding messy if-statements.
|
|
|
|
Also a lovely [comune](http://en.wikipedia.org/wiki/Mergo) (municipality) in the Province of Ancona in the Italian region Marche.
|
|
|
|
![Mergo dall'alto](http://www.comune.mergo.an.it/Siti/Mergo/Immagini/Foto/mergo_dall_alto.jpg)
|
|
|
|
## Status
|
|
|
|
It is ready for production use. It works fine although it may use more of testing. Here some projects in the wild using Mergo:
|
|
|
|
- [EagerIO/Stout](https://github.com/EagerIO/Stout)
|
|
- [lynndylanhurley/defsynth-api](https://github.com/lynndylanhurley/defsynth-api)
|
|
- [russross/canvasassignments](https://github.com/russross/canvasassignments)
|
|
- [rdegges/cryptly-api](https://github.com/rdegges/cryptly-api)
|
|
- [casualjim/exeggutor](https://github.com/casualjim/exeggutor)
|
|
- [divshot/gitling](https://github.com/divshot/gitling)
|
|
- [RWJMurphy/gorl](https://github.com/RWJMurphy/gorl)
|
|
|
|
[![Build Status][1]][2]
|
|
[![GoDoc](https://godoc.org/github.com/imdario/mergo?status.svg)](https://godoc.org/github.com/imdario/mergo)
|
|
|
|
[1]: https://travis-ci.org/imdario/mergo.png
|
|
[2]: https://travis-ci.org/imdario/mergo
|
|
|
|
## Installation
|
|
|
|
go get github.com/imdario/mergo
|
|
|
|
// use in your .go code
|
|
import (
|
|
"github.com/imdario/mergo"
|
|
)
|
|
|
|
## Usage
|
|
|
|
You can only merge same-type structs with exported fields initialized as zero value of their type and same-types maps. Mergo won't merge unexported (private) fields but will do recursively any exported one. Also maps will be merged recursively except for structs inside maps (because they are not addressable using Go reflection).
|
|
|
|
if err := mergo.Merge(&dst, src); err != nil {
|
|
// ...
|
|
}
|
|
|
|
Additionally, you can map a map[string]interface{} to a struct (and otherwise, from struct to map), following the same restrictions as in Merge(). Keys are capitalized to find each corresponding exported field.
|
|
|
|
if err := mergo.Map(&dst, srcMap); err != nil {
|
|
// ...
|
|
}
|
|
|
|
Warning: if you map a struct to map, it won't do it recursively. Don't expect Mergo to map struct members of your struct as map[string]interface{}. They will be just assigned as values.
|
|
|
|
More information and examples in [godoc documentation](http://godoc.org/github.com/imdario/mergo).
|
|
|
|
Note: if test are failing due missing package, please execute:
|
|
|
|
go get gopkg.in/yaml.v1
|
|
|
|
## Contact me
|
|
|
|
If I can help you, you have an idea or you are using Mergo in your projects, don't hesitate to drop me a line (or a pull request): [@im_dario](https://twitter.com/im_dario)
|
|
|
|
## About
|
|
|
|
Written by [Dario Castañé](http://dario.im).
|
|
|
|
## License
|
|
|
|
[BSD 3-Clause](http://opensource.org/licenses/BSD-3-Clause) license, as [Go language](http://golang.org/LICENSE).
|