Documentation ¶
Overview ¶
Package draft provides a service for resolving the priority of buildpack plan entries as well as consilidating build and launch requirements.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Planner ¶
type Planner struct { }
A Planner sorts buildpack plan entries using a given list of priorities. A Planner can also give the OR merged state of launch and build fields that are defined in the buildpack plan entries metadata field.
func (Planner) MergeLayerTypes ¶
MergeLayerTypes takes the name of buildpack plan entries that you want and the list buildpack plan entries you want merged layered types from. It returns the OR result of the launch and build keys for all of the buildpack plan entries with the specified name. The first return is the value of the OR launch the second return value is OR build.
Example ¶
buildpackPlanEntries := []packit.BuildpackPlanEntry{ { Name: "fred", }, { Name: "clint", Metadata: map[string]interface{}{ "build": false, }, }, { Name: "fred", Metadata: map[string]interface{}{ "build": true, }, }, { Name: "fred", Metadata: map[string]interface{}{ "launch": true, }, }, } planner := draft.NewPlanner() launch, build := planner.MergeLayerTypes("fred", buildpackPlanEntries) fmt.Printf("launch => %t; build => %t", launch, build)
Output: launch => true; build => true
func (Planner) Resolve ¶
func (p Planner) Resolve(name string, entries []packit.BuildpackPlanEntry, priorities []interface{}) (packit.BuildpackPlanEntry, []packit.BuildpackPlanEntry)
Resolve takes the name of buildpack plan entries that you want to sort, the buildpack plan entries that you want to be sorted, and a priority list of version-sources where the 0th index is the highest priority. Priorities can either be a string, in which case an exact string match with the version-source wil be required, or it can be a regular expression. It returns the highest priority entry as well as the sorted and filtered list of buildpack plan entries that were given. Entries with no given version-source are the lowest priority.
If nil is passed for the value of the priority list then the function will just return the first filtered entry from the list of the entries that were passed into the function initially.
Example ¶
buildpackPlanEntries := []packit.BuildpackPlanEntry{ { Name: "fred", }, { Name: "clint", Metadata: map[string]interface{}{ "version-source": "high", }, }, { Name: "fred", Metadata: map[string]interface{}{ "version-source": "high", }, }, { Name: "fred", Metadata: map[string]interface{}{ "version-source": "some-low-priority", }, }, } priorities := []interface{}{"high", regexp.MustCompile(`.*low.*`)} planner := draft.NewPlanner() entry, entries := planner.Resolve("fred", buildpackPlanEntries, priorities) printEntry := func(e packit.BuildpackPlanEntry) { var source string source, ok := e.Metadata["version-source"].(string) if !ok { source = "" } fmt.Printf("%s => %q\n", e.Name, source) } fmt.Println("Highest Priority Entry") printEntry(entry) fmt.Println("Buildpack Plan Entry List Priority Sorted") for _, e := range entries { printEntry(e) }
Output: Highest Priority Entry fred => "high" Buildpack Plan Entry List Priority Sorted fred => "high" fred => "some-low-priority" fred => ""