mirror of
https://github.com/mudler/luet.git
synced 2025-09-05 17:20:29 +00:00
Use goreleaser to build and release (#244)
Instead of using gox on one side and an action to release, we can merge them together with goreleaser which will build for extra targets (arm, mips if needed in the future) and it also takes care of creating checksums, a source archive, and a changelog and creating a release with all the artifacts. All binaries should respect the old naming convention, so any scripts out there should still work. Signed-off-by: Itxaka <igarcia@suse.com>
This commit is contained in:
93
vendor/github.com/mitchellh/copystructure/copystructure.go
generated
vendored
93
vendor/github.com/mitchellh/copystructure/copystructure.go
generated
vendored
@@ -8,7 +8,30 @@ import (
|
||||
"github.com/mitchellh/reflectwalk"
|
||||
)
|
||||
|
||||
const tagKey = "copy"
|
||||
|
||||
// Copy returns a deep copy of v.
|
||||
//
|
||||
// Copy is unable to copy unexported fields in a struct (lowercase field names).
|
||||
// Unexported fields can't be reflected by the Go runtime and therefore
|
||||
// copystructure can't perform any data copies.
|
||||
//
|
||||
// For structs, copy behavior can be controlled with struct tags. For example:
|
||||
//
|
||||
// struct {
|
||||
// Name string
|
||||
// Data *bytes.Buffer `copy:"shallow"`
|
||||
// }
|
||||
//
|
||||
// The available tag values are:
|
||||
//
|
||||
// * "ignore" - The field will be ignored, effectively resulting in it being
|
||||
// assigned the zero value in the copy.
|
||||
//
|
||||
// * "shallow" - The field will be be shallow copied. This means that references
|
||||
// values such as pointers, maps, slices, etc. will be directly assigned
|
||||
// versus deep copied.
|
||||
//
|
||||
func Copy(v interface{}) (interface{}, error) {
|
||||
return Config{}.Copy(v)
|
||||
}
|
||||
@@ -28,6 +51,19 @@ type CopierFunc func(interface{}) (interface{}, error)
|
||||
// this map as well as to Copy in a mutex.
|
||||
var Copiers map[reflect.Type]CopierFunc = make(map[reflect.Type]CopierFunc)
|
||||
|
||||
// ShallowCopiers is a map of pointer types that behave specially
|
||||
// when they are copied. If a type is found in this map while deep
|
||||
// copying, the pointer value will be shallow copied and not walked
|
||||
// into.
|
||||
//
|
||||
// The key should be the type, obtained using: reflect.TypeOf(value
|
||||
// with type).
|
||||
//
|
||||
// It is unsafe to write to this map after Copies have started. If you
|
||||
// are writing to this map while also copying, wrap all modifications to
|
||||
// this map as well as to Copy in a mutex.
|
||||
var ShallowCopiers map[reflect.Type]struct{} = make(map[reflect.Type]struct{})
|
||||
|
||||
// Must is a helper that wraps a call to a function returning
|
||||
// (interface{}, error) and panics if the error is non-nil. It is intended
|
||||
// for use in variable initializations and should only be used when a copy
|
||||
@@ -50,6 +86,11 @@ type Config struct {
|
||||
// Copiers is a map of types associated with a CopierFunc. Use the global
|
||||
// Copiers map if this is nil.
|
||||
Copiers map[reflect.Type]CopierFunc
|
||||
|
||||
// ShallowCopiers is a map of pointer types that when they are
|
||||
// shallow copied no matter where they are encountered. Use the
|
||||
// global ShallowCopiers if this is nil.
|
||||
ShallowCopiers map[reflect.Type]struct{}
|
||||
}
|
||||
|
||||
func (c Config) Copy(v interface{}) (interface{}, error) {
|
||||
@@ -65,6 +106,12 @@ func (c Config) Copy(v interface{}) (interface{}, error) {
|
||||
if c.Copiers == nil {
|
||||
c.Copiers = Copiers
|
||||
}
|
||||
w.copiers = c.Copiers
|
||||
|
||||
if c.ShallowCopiers == nil {
|
||||
c.ShallowCopiers = ShallowCopiers
|
||||
}
|
||||
w.shallowCopiers = c.ShallowCopiers
|
||||
|
||||
err := reflectwalk.Walk(v, w)
|
||||
if err != nil {
|
||||
@@ -93,10 +140,12 @@ func ifaceKey(pointers, depth int) uint64 {
|
||||
type walker struct {
|
||||
Result interface{}
|
||||
|
||||
depth int
|
||||
ignoreDepth int
|
||||
vals []reflect.Value
|
||||
cs []reflect.Value
|
||||
copiers map[reflect.Type]CopierFunc
|
||||
shallowCopiers map[reflect.Type]struct{}
|
||||
depth int
|
||||
ignoreDepth int
|
||||
vals []reflect.Value
|
||||
cs []reflect.Value
|
||||
|
||||
// This stores the number of pointers we've walked over, indexed by depth.
|
||||
ps []int
|
||||
@@ -263,6 +312,20 @@ func (w *walker) PointerExit(v bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *walker) Pointer(v reflect.Value) error {
|
||||
if _, ok := w.shallowCopiers[v.Type()]; ok {
|
||||
// Shallow copy this value. Use the same logic as primitive, then
|
||||
// return skip.
|
||||
if err := w.Primitive(v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return reflectwalk.SkipEntry
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *walker) Interface(v reflect.Value) error {
|
||||
if !v.IsValid() {
|
||||
return nil
|
||||
@@ -356,7 +419,7 @@ func (w *walker) Struct(s reflect.Value) error {
|
||||
w.lock(s)
|
||||
|
||||
var v reflect.Value
|
||||
if c, ok := Copiers[s.Type()]; ok {
|
||||
if c, ok := w.copiers[s.Type()]; ok {
|
||||
// We have a Copier for this struct, so we use that copier to
|
||||
// get the copy, and we ignore anything deeper than this.
|
||||
w.ignoreDepth = w.depth
|
||||
@@ -396,9 +459,29 @@ func (w *walker) StructField(f reflect.StructField, v reflect.Value) error {
|
||||
return reflectwalk.SkipEntry
|
||||
}
|
||||
|
||||
switch f.Tag.Get(tagKey) {
|
||||
case "shallow":
|
||||
// If we're shallow copying then assign the value directly to the
|
||||
// struct and skip the entry.
|
||||
if v.IsValid() {
|
||||
s := w.cs[len(w.cs)-1]
|
||||
sf := reflect.Indirect(s).FieldByName(f.Name)
|
||||
if sf.CanSet() {
|
||||
sf.Set(v)
|
||||
}
|
||||
}
|
||||
|
||||
return reflectwalk.SkipEntry
|
||||
|
||||
case "ignore":
|
||||
// Do nothing
|
||||
return reflectwalk.SkipEntry
|
||||
}
|
||||
|
||||
// Push the field onto the stack, we'll handle it when we exit
|
||||
// the struct field in Exit...
|
||||
w.valPush(reflect.ValueOf(f))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user