func ExtractBaseAndOverlayParts(bd *BundleData) (base, overlay *BundleData, err error) {
	base = cloneBundleData(bd)
	_ = visitField(&visitorContext{
		structVisitor:          clearOverlayFields,
		dropNonRequiredMapKeys: false,
	}, base)

	overlay = cloneBundleData(bd)
	_ = visitField(&visitorContext{
		structVisitor:          clearNonOverlayFields,
		dropNonRequiredMapKeys: true,
	}, overlay)

	return base, overlay, nil
}
// ExtractBaseAndOverlayParts splits the bundle data into a base and
// overlay-specific bundle so that their union yields bd. To decide whether a
// field is overlay-specific, the implementation uses reflection and
// recursively scans the BundleData fields looking for fields annotated with
// the "overlay-only: true" tag.
//
// To produce the base bundle, the original bundle is filtered and all
// overlay-specific values are set to the zero value for their type. To produce
// the overlay-specific bundle, we once again filter the original bundle but
// this time zero out fields that do not contain any descendant fields that are
// overlay-specific.
//
// To clarify how this method works let's consider a bundle created via the
// yaml blob below:
//
//   applications:
//     apache2:
//       charm: cs:apache2-26
//       offers:
//         my-offer:
//           endpoints:
//           - apache-website
//           - website-cache
//         my-other-offer:
//           endpoints:
//           - apache-website
//   series: bionic
//
// The "offers" and "endpoints" attributes are overlay-specific fields. If we
// were to run this method and then marshal the results back to yaml we would
// get:
//
// The base bundle:
//
//   applications:
//     apache2:
//       charm: cs:apache2-26
//   series: bionic
//
// The overlay-specific bundle:
//
//   applications:
//     apache2:
//       offers:
//         my-offer:
//           endpoints:
//           - apache-website
//           - website-cache
//         my-other-offer:
//           endpoints:
//           - apache-website
//
// The two bundles returned by this method are copies of the original bundle
// data and can thus be safely manipulated by the caller.
ExtractBaseAndOverlayParts splits the bundle data into a base and
overlay-specific bundle so that their union yields bd. To decide whether a
field is overlay-specific, the implementation uses reflection and
recursively scans the BundleData fields looking for fields annotated with
the "overlay-only: true" tag.

To produce the base bundle, the original bundle is filtered and all
overlay-specific values are set to the zero value for their type. To produce
the overlay-specific bundle, we once again filter the original bundle but
this time zero out fields that do not contain any descendant fields that are
overlay-specific.

To clarify how this method works let's consider a bundle created via the
yaml blob below.

apache2-26
offers:
my-offer:
endpoints:
- apache-website
- website-cache
my-other-offer:
endpoints:
- apache-website
series: bionic

The "offers" and "endpoints" attributes are overlay-specific fields. If we
were to run this method and then marshal the results back to yaml we would
get.

The base bundle.

apache2-26
series: bionic

The overlay-specific bundle.

my-offer:
endpoints:
- apache-website
- website-cache
my-other-offer:
endpoints:
- apache-website

The two bundles returned by this method are copies of the original bundle
data and can thus be safely manipulated by the caller.
// ExtractBaseAndOverlayParts splits the bundle data into a base and // overlay - specific bundle so that their union yields bd . To decide whether a // field is overlay - specific the implementation uses reflection and // recursively scans the BundleData fields looking for fields annotated with // the " overlay - only : true " tag . // // To produce the base bundle the original bundle is filtered and all // overlay - specific values are set to the zero value for their type . To produce // the overlay - specific bundle we once again filter the original bundle but // this time zero out fields that do not contain any descendant fields that are // overlay - specific . // // To clarify how this method works let ' s consider a bundle created via the // yaml blob below : // // applications : // apache2 : // charm : cs : apache2 - 26 // offers : // my - offer : // endpoints : // - apache - website // - website - cache // my - other - offer : // endpoints : // - apache - website // series : bionic // // The " offers " and " endpoints " attributes are overlay - specific fields . If we // were to run this method and then marshal the results back to yaml we would // get : // // The base bundle : // // applications : // apache2 : // charm : cs : apache2 - 26 // series : bionic // // The overlay - specific bundle : // // applications : // apache2 : // offers : // my - offer : // endpoints : // - apache - website // - website - cache // my - other - offer : // endpoints : // - apache - website // // The two bundles returned by this method are copies of the original bundle // data and can thus be safely manipulated by the caller .
func ExtractBaseAndOverlayParts(bd *BundleData) (base, overlay *BundleData, err error) {
	base = cloneBundleData(bd)
	_ = visitField(&visitorContext{
		structVisitor:          clearOverlayFields,
		dropNonRequiredMapKeys: false,
	}, base)
	overlay = cloneBundleData(bd)
	_ = visitField(&visitorContext{
		structVisitor:          clearNonOverlayFields,
		dropNonRequiredMapKeys: true,
	}, overlay)
	return base, overlay, nil
}
func ExtractBaseAndOverlayParts ( bd * BundleData ) ( base , overlay * BundleData , err error ) { base = cloneBundleData ( bd ) _ = visitField ( & visitorContext { structVisitor : clearOverlayFields , dropNonRequiredMapKeys : false , } , base ) overlay = cloneBundleData ( bd ) _ = visitField ( & visitorContext { structVisitor : clearNonOverlayFields , dropNonRequiredMapKeys : true , } , overlay ) return base , overlay , nil }
ExtractBaseAndOverlayParts splits the bundle data into a base and
overlay-specific bundle so that their union yields bd.
ExtractBaseAndOverlayParts splits the bundle data into a base and overlay - specific bundle so that their union yields bd .