├── .gitignore ├── LICENSE ├── README.md ├── Vagrantfile ├── bootstrap.sh └── dev └── pi.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | 25 | .vagrant 26 | .bash_history 27 | .git 28 | .cache 29 | 30 | dev/pkg 31 | dev/src 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Linda Nichols 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Vagrant Virtual Development Environment for GoLang 2 | 3 | ### Install Vagrant ### 4 | 5 | * Download and install [VirtualBox 5.1.6](https://www.virtualbox.org/wiki/Downloads) 6 | * Download and install [Vagrant 1.8.6](http://www.vagrantup.com/downloads.html) 7 | 8 | #### Windows Users #### 9 | 10 | - Download [Git for Windows](http://msysgit.github.io/): 11 | - Run the installer and "next" through the wizard until the step to adjust your PATH environment. 12 | - Choose the third option, "Run Git and included tools from within the Windows Command prompt" 13 | - **Important**: On the next step, "Configuring the line ending conversions", choose the second option: "Checkout as-is, commit Unix-style line endings". 14 | - Choose "next" through any additional steps to complete the Git for Windows install. 15 | - Open the Windows Command Prompt as **Administrator** 16 | 17 | [Fork](http://github.com/lynnaloo/golang-vagrant/fork) this repository on Github. 18 | 19 | Clone your fork of the `golang-vagrant` respository to a directory on your host machine: 20 | 21 | host $ git clone https://github.com//golang-vagrant.git 22 | host $ cd golang-vagrant 23 | 24 | ### Connect to the Virtual Machine ### 25 | 26 | Start the virtual machine: 27 | 28 | host $ vagrant up 29 | 30 | Connect to the virtual machine via ssh: 31 | 32 | host $ vagrant ssh 33 | 34 | Try it out! 35 | 36 | guest $ cd dev 37 | guest $ go run pi.go 38 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 8 | # All Vagrant configuration is done here. The most common configuration 9 | # options are documented and commented below. For a complete reference, 10 | # please see the online documentation at vagrantup.com. 11 | 12 | # Every Vagrant virtual environment requires a box to build off of. 13 | config.vm.box = "ubuntu/trusty64" 14 | 15 | # Disable automatic box update checking. If you disable this, then 16 | # boxes will only be checked for updates when the user runs 17 | # `vagrant box outdated`. This is not recommended. 18 | # config.vm.box_check_update = false 19 | 20 | # Create a forwarded port mapping which allows access to a specific port 21 | # within the machine from a port on the host machine. In the example below, 22 | # accessing "localhost:8080" will access port 80 on the guest machine. 23 | # config.vm.network "forwarded_port", guest: 80, host: 8080 24 | 25 | # Create a private network, which allows host-only access to the machine 26 | # using a specific IP. 27 | config.vm.network "private_network", ip: "192.168.33.22" 28 | 29 | # Create a public network, which generally matched to bridged network. 30 | # Bridged networks make the machine appear as another physical device on 31 | # your network. 32 | # config.vm.network "public_network" 33 | 34 | # If true, then any SSH connections made will enable agent forwarding. 35 | # Default value: false 36 | # config.ssh.forward_agent = true 37 | 38 | # Share an additional folder to the guest VM. The first argument is 39 | # the path on the host to the actual folder. The second argument is 40 | # the path on the guest to mount the folder. And the optional third 41 | # argument is a set of non-required options. 42 | config.vm.synced_folder "dev", "/home/vagrant/dev" 43 | 44 | config.vm.provision "shell", path: "bootstrap.sh", privileged: true, binary: false 45 | 46 | # Provider-specific configuration so you can fine-tune various 47 | # backing providers for Vagrant. These expose provider-specific options. 48 | # Example for VirtualBox: 49 | # 50 | # config.vm.provider "virtualbox" do |vb| 51 | # # Don't boot with headless mode 52 | # vb.gui = true 53 | # 54 | # # Use VBoxManage to customize the VM. For example to change memory: 55 | # vb.customize ["modifyvm", :id, "--memory", "1024"] 56 | # end 57 | # 58 | end 59 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | # might not need sudo here if you run this as privileged in Vagrantfile 2 | sudo apt-get update 3 | sudo apt-get install git -y 4 | sudo apt-get install golang-go -y 5 | sudo apt-get install mercurial -y 6 | 7 | export PATH=$PATH:/usr/local/go/bin 8 | export GOPATH=/home/vagrant/dev 9 | 10 | go get golang.org/x/tools/cmd/godoc 11 | go get golang.org/x/tools/cmd/vet 12 | go get github.com/golang/lint/golint 13 | go get github.com/go-martini/martini 14 | -------------------------------------------------------------------------------- /dev/pi.go: -------------------------------------------------------------------------------- 1 | // Concurrent computation of pi. 2 | // See http://goo.gl/ZuTZM. 3 | // 4 | // This demonstrates Go's ability to handle 5 | // large numbers of concurrent processes. 6 | // It is an unreasonable way to calculate pi. 7 | package main 8 | 9 | import ( 10 | "fmt" 11 | "math" 12 | ) 13 | 14 | func main() { 15 | fmt.Println(pi(5000)) 16 | } 17 | 18 | // pi launches n goroutines to compute an 19 | // approximation of pi. 20 | func pi(n int) float64 { 21 | ch := make(chan float64) 22 | for k := 0; k <= n; k++ { 23 | go term(ch, float64(k)) 24 | } 25 | f := 0.0 26 | for k := 0; k <= n; k++ { 27 | f += <-ch 28 | } 29 | return f 30 | } 31 | 32 | func term(ch chan float64, k float64) { 33 | ch <- 4 * math.Pow(-1, k) / (2*k + 1) 34 | } 35 | --------------------------------------------------------------------------------