Created
June 18, 2015 09:40
-
-
Save ivancorrales/ed2a958b564a5826894e to your computer and use it in GitHub Desktop.
Go script to create workspace structure
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" | |
"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