Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Go script to create workspace structure
package main
import(
"fmt"
"os"
"runtime"
"path/filepath"
)
var directories = []string{"src", "pkg", "bin"}
var requiredFiles = []string{"README.md", ".gitignore"}
func main(){
arguments := os.Args[1:]
workspaceRootPath := arguments[0]
fmt.Println("Creating workspace: "+workspaceRootPath)
createStructure(workspaceRootPath,directories)
createFiles(workspaceRootPath,requiredFiles)
os := runtime.GOOS
fmt.Println("Operating system:"+os)
// err := exec.Command("bash","cd "+workspaceRootPath).Run()
// if err != nil {
// panic(err)
// }
fmt.Println("Pending to run command 'go get github.com/tools/godep'")
}
func createStructure(root string,directories []string){
os.Mkdir(root,0777)
for _,element := range directories {
os.Mkdir(root + string(filepath.Separator) + element,0777)
}
}
func createFiles(root string, files []string){
for _,fileName := range files {
fo, err := os.Create(root + string(filepath.Separator) + fileName)
if err != nil {
panic(err)
}
defer func() {
if err := fo.Close(); err != nil {
panic(err)
}
}()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment