Created
August 11, 2021 09:20
-
-
Save mehmetron/2e21703a9942ff66552ad87772ac26e5 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"os/exec" | |
) | |
type GoPackage struct { | |
Path string `json:"Path"` | |
Version string `json:"Version"` | |
Indirect bool `json:"Indirect"` | |
} | |
type AllPackages struct { | |
Go string `json:"Go"` | |
Require []GoPackage `json:"Require"` | |
} | |
func GetCmdOutput(cmd []string) []byte { | |
command := exec.Command(cmd[0], cmd[1:]...) | |
command.Stderr = os.Stderr | |
output, err := command.Output() | |
if err != nil { | |
fmt.Println(err) | |
} | |
return output | |
} | |
func main() { | |
depList := GetCmdOutput([]string{"go", "mod", "edit", "-json"}) | |
fmt.Println("32 ", depList) | |
fmt.Println("33 ", string(depList)) | |
dynamic := AllPackages{} | |
json.Unmarshal(depList, &dynamic) | |
fmt.Println("37 ", dynamic) | |
fmt.Printf("39 %+v\n", dynamic) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment