-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature: YAML<->JSON transformation
- Loading branch information
Mercurio
committed
Oct 15, 2021
1 parent
cbe3400
commit 8fd90a3
Showing
16 changed files
with
328 additions
and
43 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,40 @@ | ||
package transformer | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/SignorMercurio/limner/util" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type JsonTransformer struct { | ||
Type string | ||
obj util.Obj | ||
} | ||
|
||
func (jt *JsonTransformer) Transform(input []byte) ([]byte, error) { | ||
// fill the obj if the type is already enforced | ||
switch jt.Type { | ||
case "yaml": | ||
if err := yaml.Unmarshal(input, &jt.obj); err == nil { | ||
return json.MarshalIndent(jt.obj, "", " ") | ||
} | ||
default: | ||
// otherwise, try to determine the type | ||
switch { | ||
case util.ShouldYaml(string(input)): | ||
if err := yaml.Unmarshal(input, &jt.obj); err == nil { | ||
return json.MarshalIndent(jt.obj, "", " ") | ||
} | ||
} | ||
} | ||
|
||
unknownInput() | ||
return input, nil | ||
} | ||
|
||
func NewJsonTransformer(Type string) *JsonTransformer { | ||
return &JsonTransformer{ | ||
Type: Type, | ||
} | ||
} |
Oops, something went wrong.