Created
January 24, 2013 13:56
-
-
Save HoffmannP/4621876 to your computer and use it in GitHub Desktop.
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
# using the instructions from http://golang.org/doc/code.html | |
# either use the first command line argument or read the test directory | |
if [ $# -gt 0 ]; then | |
dir=$1; | |
else | |
read -p "test directory: " dir | |
fi | |
############################### | |
# minimal example starts here # | |
############################### | |
# if not existent create test directory | |
if [ ! -d $dir ]; then | |
mkdir -p $dir; | |
fi | |
cd $dir | |
# don't forget to export | |
export GOPATH="$(pwd)" | |
# create the packages directory inside the "src" directory | |
mkdir -p src/newmath; | |
# create an example package file | |
echo '// Package newmath is a trivial example package. | |
package newmath | |
// Sqrt returns an approximation to the square root of x. | |
func Sqrt(x float64) float64 { | |
// This is a terrible implementation. | |
// Real code should import "math" and use math.Sqrt. | |
z := 0.0 | |
for i := 0; i < 1000; i++ { | |
z -= (z*z - x) / (2 * x) | |
} | |
return z | |
} | |
' > src/example/newmath/sqrt.go | |
# This should give an return value of zero and no output at all | |
go install example/newmath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment