Skip to content

Commit

Permalink
Update writing-go-programs.md
Browse files Browse the repository at this point in the history
  • Loading branch information
p00gz committed May 26, 2014
1 parent 24935f8 commit 6630789
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion go/writing-go-programs.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,66 @@ $ go install

<h4>Run Program</h4>
<pre>
$ $GOPATH/bin/hello
$ hello
</pre>


<h4>Create package directory</h4>
<pre>
$ cd $GOPATH/src/github.com/your_username
$ mkdir formula
$ cd formula
$ nano sqrt.go
# add to the file:

package formula

func Sqrt(x float64) float64 {
z := 1.0
for i := 0; i < 1000; i++ {
z -= (z*z - x) / (2 * z)
}
return z
}

</pre>

<h4>Build Package</h4>
<pre>
$ go build github.com/your_username/formula
</pre>

<h4>Add Package to existing program</h4>
<pre>
package main
import (
"fmt"
"github.com/user/newmath"
)
func main() {
fmt.Printf("Hello, world. Sqrt(2) = %v\n", newmath.Sqrt(2))
}

</pre>

<h4>Build Program w/ package dependency</h4>
<pre>
$ go install github.com/your_username/hello_world
</pre>

<h4>Run Program w/ package dependency</h4>
<pre>
$ hello
</pre>












0 comments on commit 6630789

Please sign in to comment.