diff --git a/toJSON-legacy/go.mod b/toJSON-legacy/go.mod deleted file mode 100644 index 77fd623..0000000 --- a/toJSON-legacy/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module toJSON - -go 1.18 - -require ( - github.com/BurntSushi/toml v1.2.0 - gopkg.in/yaml.v3 v3.0.1 -) diff --git a/toJSON-legacy/go.sum b/toJSON-legacy/go.sum deleted file mode 100644 index 9eb3253..0000000 --- a/toJSON-legacy/go.sum +++ /dev/null @@ -1,6 +0,0 @@ -github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= -github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/toJSON-legacy/main.go b/toJSON-legacy/main.go deleted file mode 100644 index cb3d6ff..0000000 --- a/toJSON-legacy/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "github.com/BurntSushi/toml" - "gopkg.in/yaml.v3" - "os" -) - -func parser(raw []byte) (interface{}, interface{}) { - var object interface{} - if err := json.Unmarshal(raw, &object); err == nil { // try json - return object, nil // json format - } - if err := toml.Unmarshal(raw, &object); err == nil { // try toml - return object, nil // toml format - } - if err := yaml.Unmarshal(raw, &object); err == nil { // try yaml - return object, nil // yaml format - } - return nil, nil // parser error -} - -func main() { - if len(os.Args) < 2 { // without argument - fmt.Printf("usage: toJSON [file]\n") - os.Exit(0) - } - raw, err := os.ReadFile(os.Args[1]) - if err != nil { - os.Exit(2) // file open failed - } - if object, err := parser(raw); err == nil { - ret, _ := json.Marshal(object) - fmt.Println(string(ret)) - os.Exit(0) - } - os.Exit(1) // unmarshal failed -}