Skip to content

Commit 86e0075

Browse files
authored
More changes regarding hasura config (#5)
* check hasura for nil * Make DatabaseUrl interface{} again * add ReadCustomConfigs * fix AddSource: DatabaseUrl is string
1 parent 0409720 commit 86e0075

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

hasura/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (api *API) AddSource(ctx context.Context, hasura *config.Hasura, cfg config
130130
"name": hasura.Source,
131131
"configuration": Configuration{
132132
ConnectionInfo: ConnectionInfo{
133-
DatabaseUrl: DatabaseUrl(fmt.Sprintf("postgresql://%s:%s@%s:%d/%s", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Database)),
133+
DatabaseUrl: fmt.Sprintf("postgresql://%s:%s@%s:%d/%s", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Database),
134134
UsePreparedStatements: true,
135135
IsolationLevel: "read-committed",
136136
},

hasura/hasura.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,33 @@ func mergeQueries(a []Query, b []Query) []Query {
340340
}
341341
return b
342342
}
343+
344+
func ReadCustomConfigs(ctx context.Context, database config.Database, hasuraConfigDir string) ([]Request, error) {
345+
files, err := ioutil.ReadDir(hasuraConfigDir)
346+
if err != nil {
347+
return nil, err
348+
}
349+
350+
custom_configs := make([]Request, 0)
351+
for i := range files {
352+
if files[i].IsDir() || strings.HasPrefix(files[i].Name(), ".") {
353+
continue
354+
}
355+
356+
path := fmt.Sprintf("%s/%s", hasuraConfigDir, files[i].Name())
357+
raw, err := ioutil.ReadFile(path)
358+
if err != nil {
359+
return nil, err
360+
}
361+
362+
conf := Request{}
363+
364+
err = json.Unmarshal([]byte(raw), &conf)
365+
if err != nil {
366+
return nil, err
367+
}
368+
custom_configs = append(custom_configs, conf)
369+
}
370+
371+
return custom_configs, nil
372+
}

0 commit comments

Comments
 (0)