Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.18
go-version: "1.25"

- name: Build
run: go build -v ./...
Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetResultFromCtx(ctx context.Context) Result {
// this function enables optional access to data, your code should not rely on
// values being present, if you have explicit dependency please add them to your
// function parameters
func GetFromResult(ctx context.Context, obj interface{}) interface{} {
func GetFromResult(ctx context.Context, obj any) any {
r := GetResultFromCtx(ctx)
if r == nil {
return nil
Expand Down
19 changes: 9 additions & 10 deletions databuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,31 @@ import (
"reflect"
"runtime"

"k8s.io/apimachinery/pkg/util/sets"
)

/*
* Before going throught this code please read - https://go.dev/blog/laws-of-reflection
*/

type builder struct {
Builder interface{}
Builder any
In []string
Out string
Name string
}

type db struct {
builders map[string]*builder
outSet sets.String
outSet stringSet
}

func (d *db) AddBuilders(builders ...interface{}) error {
func (d *db) AddBuilders(builders ...any) error {
// initialize
if d.builders == nil {
d.builders = make(map[string]*builder)
}
if d.outSet == nil {
d.outSet = sets.NewString()
d.outSet = newStringSet()
}

// go through all builders and add them
Expand All @@ -46,7 +45,7 @@ func (d *db) AddBuilders(builders ...interface{}) error {
return nil
}

func (d *db) add(bldr interface{}) error {
func (d *db) add(bldr any) error {
b, err := getBuilder(bldr)
if err != nil {
return err
Expand All @@ -67,7 +66,7 @@ func (d *db) add(bldr interface{}) error {
return nil
}

func (d *db) Compile(init ...interface{}) (Plan, error) {
func (d *db) Compile(init ...any) (Plan, error) {
initialialData := make([]string, 0, len(init))
for _, inter := range init {
if inter == nil {
Expand All @@ -88,7 +87,7 @@ func (d *db) Compile(init ...interface{}) (Plan, error) {
}

// IsValidBuilder checks if the given function is valid or not
func IsValidBuilder(builder interface{}) error {
func IsValidBuilder(builder any) error {
t := reflect.TypeOf(builder)
if t.Kind() != reflect.Func {
// Input can only be a function
Expand Down Expand Up @@ -135,7 +134,7 @@ func IsValidBuilder(builder interface{}) error {
return nil
}

func getBuilder(bldr interface{}) (*builder, error) {
func getBuilder(bldr any) (*builder, error) {
if err := IsValidBuilder(bldr); err != nil {
return nil, err
}
Expand All @@ -156,7 +155,7 @@ func getBuilder(bldr interface{}) (*builder, error) {
return b, nil
}

func getFuncName(bldr interface{}) string {
func getFuncName(bldr any) string {
return runtime.FuncForPC(reflect.ValueOf(bldr).Pointer()).Name()
}

Expand Down
11 changes: 5 additions & 6 deletions dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package databuilder
import (
"fmt"

"k8s.io/apimachinery/pkg/util/sets"
)

// resolveDependencies resolves the dependencies between the builders
Expand All @@ -17,19 +16,19 @@ func resolveDependencies(mapping map[string]*builder, initData ...string) ([][]*
* dependency resolution is NP problem, lets see what we can do
*/
outputMap := make(map[string]string) // mapping between function return and function
structMap := make(map[string]sets.String) // mapping between output struct and input struct
structMap := make(map[string]stringSet) // mapping between output struct and input struct
for _, v := range mapping {
outputMap[v.Out] = v.Name
if _, ok := structMap[v.Out]; !ok {
structMap[v.Out] = sets.NewString()
structMap[v.Out] = newStringSet()
}
structMap[v.Out].Insert(v.In...)
}

readyset := sets.NewString(initData...)
readyset := newStringSet(initData...)
order := make([][]*builder, 0)
for len(structMap) > 0 {
blocked := sets.NewString()
blocked := newStringSet()
for k, v := range structMap {
if v.Len() == 0 {
Comment on lines +28 to 33
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching from sets.String to stringSet removes the String() implementation that k8s sets provide. Later in this function, blocked is formatted with %s, which will now produce a %!s(...) formatting error instead of a readable list of missing fields. Add a String() method on stringSet (to preserve existing error text behavior) or update the error formatting to use blocked.List() / %v.

Copilot uses AI. Check for mistakes.
readyset.Insert(k)
Expand All @@ -55,7 +54,7 @@ func resolveDependencies(mapping map[string]*builder, initData ...string) ([][]*
diff := v.Difference(readyset)
structMap[k] = diff
}
readyset = sets.NewString()
readyset = newStringSet()
}
return order, nil
}
Loading
Loading