-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove tinygo incompatible packages from core
- Loading branch information
Showing
20 changed files
with
235 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package core | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/dosco/graphjin/plugin" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type configInfo struct { | ||
Inherits string | ||
} | ||
|
||
func NewConfig(fs plugin.FS, configFile string) (*Config, error) { | ||
var c Config | ||
var ci configInfo | ||
|
||
if err := readConfig(fs, configFile, &ci); err != nil { | ||
return nil, err | ||
} | ||
|
||
if ci.Inherits != "" { | ||
pc := ci.Inherits | ||
|
||
if filepath.Ext(pc) == "" { | ||
pc += filepath.Ext(configFile) | ||
} | ||
|
||
if err := readConfig(fs, pc, &c); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
if err := readConfig(fs, configFile, &c); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &c, nil | ||
} | ||
|
||
func readConfig(fs plugin.FS, configFile string, v interface{}) (err error) { | ||
format := filepath.Ext(configFile) | ||
|
||
b, err := fs.ReadFile(configFile) | ||
if err != nil { | ||
return fmt.Errorf("error reading config: %w", err) | ||
} | ||
|
||
switch format { | ||
case ".json": | ||
err = json.Unmarshal(b, v) | ||
case ".yml", ".yaml": | ||
err = yaml.Unmarshal(b, v) | ||
default: | ||
err = fmt.Errorf("invalid format %s", format) | ||
} | ||
|
||
if err != nil { | ||
err = fmt.Errorf("error reading config: %w", err) | ||
} | ||
return | ||
} |
Oops, something went wrong.