Created
August 2, 2018 13:04
-
-
Save owainlewis/001ecce56983aaa7a85570ed0d9ab515 to your computer and use it in GitHub Desktop.
Legal deps stuff
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
cat Godeps/Godeps.json | jq '.Deps[] | "\(.ImportPath) \(.Rev)"' |
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 ( | |
"fmt" | |
"io/ioutil" | |
"os" | |
"path/filepath" | |
"strings" | |
) | |
const RESULTS = "results.txt" | |
func writeLicenseFile(path string) error { | |
contents, err := ioutil.ReadFile(path) | |
if err != nil { | |
return err | |
} | |
f, err := os.OpenFile(RESULTS, os.O_APPEND|os.O_WRONLY, 0600) | |
if err != nil { | |
return err | |
} | |
defer f.Close() | |
if _, err = f.WriteString(string(contents) + "\n\n"); err != nil { | |
return err | |
} | |
fmt.Printf("Write File name %s\n", f.Name()) | |
return nil | |
} | |
func walkLicenses(searchdir string) error { | |
err := filepath.Walk(searchdir, func(path string, f os.FileInfo, err error) error { | |
if !f.IsDir() && strings.Contains(f.Name(), "LICENSE") { | |
err := writeLicenseFile(path) | |
if err != nil { | |
fmt.Printf("Error: %s", err) | |
} | |
} | |
return nil | |
}) | |
return err | |
} | |
func main() { | |
walkLicenses("vendor") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment