From 42eb43611c846ef86af91f140389243816e866b7 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Sun, 24 Aug 2025 12:58:34 -0700 Subject: [PATCH] Add example --- di_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/di_test.go b/di_test.go index 41104c5441a07d4b14c2820793396c1fa5822381..852b46fb77a457ca4441f0c98814c55117088234 100644 --- a/di_test.go +++ b/di_test.go @@ -2,10 +2,41 @@ package di import ( "errors" + "fmt" "strings" "testing" ) +func ExampleBuild() { + type Username string + type Config struct { + User Username + Age int + Greeting func(Username, int) string + } + + cfg := Config{ + User: "Alice", + Age: 42, + Greeting: func(u Username, age int) string { + return fmt.Sprintf("Hello, %s. You've been around the sun %d times!", string(u), age) + }, + } + + type Result struct { + Greeting string + } + var res Result + err := Build(cfg, &res) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(res.Greeting) + + // Output: Hello, Alice. You've been around the sun 42 times! +} + func TestBuildSuccess(t *testing.T) { type A struct { val string