Skip to content

Instantly share code, notes, and snippets.

@ivancorrales
Created June 18, 2015 09:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivancorrales/ed2a958b564a5826894e to your computer and use it in GitHub Desktop.
Save ivancorrales/ed2a958b564a5826894e to your computer and use it in GitHub Desktop.
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