-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_container_test.go
More file actions
53 lines (43 loc) · 1.15 KB
/
example_container_test.go
File metadata and controls
53 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package pal_test
import (
"context"
"fmt"
"time"
"github.com/zhulik/pal"
)
// SimpleService is a test service interface
type SimpleService interface {
GetMessage() string
}
// SimpleServiceImpl implements SimpleService
type SimpleServiceImpl struct{}
// GetMessage returns a greeting message
func (s *SimpleServiceImpl) GetMessage() string {
return "Hello from SimpleService"
}
// This example demonstrates how to create a Pal instance with services and use it.
func Example_container() {
// Create a Pal instance with the service
p := pal.New(
pal.Provide[SimpleService](&SimpleServiceImpl{}),
).
InitTimeout(time.Second).
HealthCheckTimeout(time.Second).
ShutdownTimeout(3 * time.Second)
// Initialize Pal
ctx := context.Background()
if err := p.Init(ctx); err != nil {
fmt.Printf("Failed to initialize Pal: %v\n", err)
return
}
// Invoke the service
instance, err := p.Invoke(ctx, "github.com/zhulik/pal_test.SimpleService")
if err != nil {
fmt.Printf("Failed to invoke service: %v\n", err)
return
}
// Use the service
service := instance.(SimpleService)
fmt.Println(service.GetMessage())
// Output: Hello from SimpleService
}