Skip to content

Commit 66b9ea8

Browse files

File tree

8 files changed

+83
-2
lines changed

8 files changed

+83
-2
lines changed

client/task.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func _RunTask(ctx RuntimeContext, runtime RuntimeSupport, event Event) (evt *Tas
6969
ctx: ctx,
7070
sessionId: event.Context.SessionId,
7171
serviceClient: getServiceClient(),
72+
config: runtime.GetRuntime().AppConfig(),
7273
}
7374
ret, err := runtime.InvokeWorkflow(workflowCtx, event.TaskInput)
7475
if err != nil {
@@ -106,13 +107,15 @@ func _RunTask(ctx RuntimeContext, runtime RuntimeSupport, event Event) (evt *Tas
106107
ctx: ctx,
107108
sessionId: event.Context.SessionId,
108109
serviceClient: getServiceClient(),
110+
config: runtime.GetRuntime().AppConfig(),
109111
}
110112
ret, err = service.ExecuteWorkflow(workflowCtx, event.Context.EntryPoint, inputObj)
111113
} else {
112114
srvCtx := ServiceContext{
113115
ctx: ctx,
114116
sessionId: event.Context.SessionId,
115117
db: db,
118+
config: runtime.GetRuntime().AppConfig(),
116119
}
117120
ret, err = service.ExecuteService(srvCtx, event.Context.EntryPoint, inputObj)
118121
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ require (
44
github.com/apex/gateway v1.1.2
55
github.com/aws/aws-lambda-go v1.47.0
66
github.com/gin-gonic/gin v1.10.0
7+
gopkg.in/yaml.v2 v2.2.2
78
)
89

910
require (

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFW
9898
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
9999
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
100100
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
101+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
101102
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
102103
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
103104
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

polycode/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type AppConfig map[string]interface{}
1010
func FromAppConfig(ctx context.Context, configObj any) {
1111
srvCtx, ok := ctx.(ServiceContext)
1212
if ok {
13-
ret := srvCtx.Config()
13+
ret := srvCtx.AppConfig()
1414
b, err := json.Marshal(configObj)
1515
if err != nil {
1616
panic(err)
@@ -23,7 +23,7 @@ func FromAppConfig(ctx context.Context, configObj any) {
2323
}
2424
wkfCtx, ok := ctx.(WorkflowContext)
2525
if ok {
26-
ret := wkfCtx.Config()
26+
ret := wkfCtx.AppConfig()
2727
b, err := json.Marshal(configObj)
2828
if err != nil {
2929
panic(err)

polycode/runtime.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var currentRuntime Runtime = nil
1717

1818
type Runtime interface {
1919
Name() string
20+
AppConfig() AppConfig
2021
Start(params []any) error
2122
}
2223

polycode/util.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,20 @@ func GetTypeNameWithPkg[T any](value T) (string, string) {
6060
func IsPointer(data interface{}) bool {
6161
return reflect.TypeOf(data).Kind() == reflect.Ptr
6262
}
63+
64+
// Helper function to convert map[interface{}]interface{} to map[string]interface{}
65+
func ConvertMap(m interface{}) interface{} {
66+
switch x := m.(type) {
67+
case map[interface{}]interface{}:
68+
converted := make(map[string]interface{})
69+
for k, v := range x {
70+
converted[k.(string)] = ConvertMap(v) // Recursively convert values
71+
}
72+
return converted
73+
case []interface{}:
74+
for i, v := range x {
75+
x[i] = ConvertMap(v)
76+
}
77+
}
78+
return m
79+
}

runtime/aws/runtime.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import (
1111
"github.com/aws/aws-lambda-go/events"
1212
"github.com/aws/aws-lambda-go/lambda"
1313
"github.com/gin-gonic/gin"
14+
"gopkg.in/yaml.v2"
15+
"log"
1416
"net/http"
17+
"os"
1518
"reflect"
1619
)
1720

@@ -20,6 +23,32 @@ type Runtime struct {
2023
dbClient *db.Client
2124
}
2225

26+
func (l *Runtime) AppConfig() polycode.AppConfig {
27+
// Load the YAML file
28+
yamlFile := "application.yml" // The path to your YAML file
29+
var yamlData interface{}
30+
31+
data, err := os.ReadFile(yamlFile)
32+
if os.IsNotExist(err) {
33+
log.Println("application.yml not found. Generating empty config...")
34+
yamlData = make(map[string]interface{}) // Create an empty config
35+
} else if err != nil {
36+
fmt.Printf("Error reading YAML file: %v\n", err)
37+
os.Exit(1)
38+
} else {
39+
// Parse the YAML file into a map
40+
err = yaml.Unmarshal(data, &yamlData)
41+
if err != nil {
42+
fmt.Printf("Error unmarshalling YAML: %v\n", err)
43+
os.Exit(1)
44+
}
45+
}
46+
47+
// Convert map[interface{}]interface{} to map[string]interface{}
48+
yamlData = polycode.ConvertMap(yamlData)
49+
return yamlData.(map[string]interface{})
50+
}
51+
2352
func (l *Runtime) GetRuntime() polycode.Runtime {
2453
return l
2554
}

runtime/local/runtime.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import (
88
"github.com/CloudImpl-Inc/next-coder-sdk/client/db"
99
"github.com/CloudImpl-Inc/next-coder-sdk/polycode"
1010
"github.com/gin-gonic/gin"
11+
"gopkg.in/yaml.v2"
1112
"io"
13+
"log"
14+
"os"
1215
)
1316

1417
//var runtime *Runtime = nil
@@ -17,6 +20,32 @@ type Runtime struct {
1720
dbClient *db.Client
1821
}
1922

23+
func (r *Runtime) AppConfig() polycode.AppConfig {
24+
// Load the YAML file
25+
yamlFile := "application.yml" // The path to your YAML file
26+
var yamlData interface{}
27+
28+
data, err := os.ReadFile(yamlFile)
29+
if os.IsNotExist(err) {
30+
log.Println("application.yml not found. Generating empty config...")
31+
yamlData = make(map[string]interface{}) // Create an empty config
32+
} else if err != nil {
33+
fmt.Printf("Error reading YAML file: %v\n", err)
34+
os.Exit(1)
35+
} else {
36+
// Parse the YAML file into a map
37+
err = yaml.Unmarshal(data, &yamlData)
38+
if err != nil {
39+
fmt.Printf("Error unmarshalling YAML: %v\n", err)
40+
os.Exit(1)
41+
}
42+
}
43+
44+
// Convert map[interface{}]interface{} to map[string]interface{}
45+
yamlData = polycode.ConvertMap(yamlData)
46+
return yamlData.(map[string]interface{})
47+
}
48+
2049
func (r *Runtime) GetRuntime() polycode.Runtime {
2150
return r
2251
}

0 commit comments

Comments
 (0)