Skip to content

Commit

Permalink
Add docs for GOPATH and GOROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
omidraha committed Oct 28, 2018
1 parent 57b81e8 commit 91a854b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 81 deletions.
5 changes: 2 additions & 3 deletions src/go/go.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Go
====
Go-Lang
=======


Contents:
Expand All @@ -8,5 +8,4 @@ Contents:
:maxdepth: 2

tips
intro

78 changes: 0 additions & 78 deletions src/go/intro.rst
Original file line number Diff line number Diff line change
@@ -1,78 +0,0 @@
Introduction to go programming language
=======================================

Builtin function
----------------




Define slice
------------

.. code-block:: go
package main
import "fmt"
func main() {
var slice_1 []int
slice_2 := []int {}
slice_3 := make([]int, 0)
var slice_4 = []int {1, 2, 3, 4}
slice_5 := []int {1, 2, 3, 4}
slice_6 := make([]int, 0)
slice_6 = append(slice_6, 1, 2, 3, 4)
slice_7 := slice_4[:]
slice_8 := slice_5[0:4]
slice_9 := make([]int, 4) // [0 0 0 0]
copy(slice_9, slice_4)
fmt.Println(slice_1, slice_2, slice_3, slice_4, slice_5, slice_6, slice_7, slice_8, slice_9)
}
// [] [] [] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4]
Notes:

* The first argument of ``make``, ``append`` and ``copy`` functions must be slice.

* The second argument of ``copy`` function also must be slice. (As a special case, it also will copy bytes from a string to a slice of bytes.)

* The ``copy`` function returns the number of elements copied, which will be the minimum of len(src) and len(dst).


.. code-block:: go
package main
import "fmt"
func main() {
slice_1 := []int {1, 2, 3, 4, 5}
slice_2 := []int {11, 22}
slice_3 := []int {111}
slice_4 := []int {}
count := copy(slice_1, slice_2)
fmt.Println(count, slice_1)
count = copy(slice_3, slice_2)
fmt.Println(count, slice_3)
count = copy(slice_4, slice_2)
fmt.Println(count, slice_4)
}
// 2 [11 22 3 4 5]
// 1 [11]
// 0 []
90 changes: 90 additions & 0 deletions src/go/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,94 @@ Tips
====


Builtin function
----------------

http://golang.org/pkg/builtin/


Introduction to go programming language
---------------------------------------


Define slice
++++++++++++


.. code-block:: go
package main
import "fmt"
func main() {
var slice_1 []int
slice_2 := []int {}
slice_3 := make([]int, 0)
var slice_4 = []int {1, 2, 3, 4}
slice_5 := []int {1, 2, 3, 4}
slice_6 := make([]int, 0)
slice_6 = append(slice_6, 1, 2, 3, 4)
slice_7 := slice_4[:]
slice_8 := slice_5[0:4]
slice_9 := make([]int, 4) // [0 0 0 0]
copy(slice_9, slice_4)
fmt.Println(slice_1, slice_2, slice_3, slice_4, slice_5, slice_6, slice_7, slice_8, slice_9)
}
// [] [] [] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4] [1 2 3 4]
Notes:

* The first argument of ``make``, ``append`` and ``copy`` functions must be slice.

* The second argument of ``copy`` function also must be slice. (As a special case, it also will copy bytes from a string to a slice of bytes.)

* The ``copy`` function returns the number of elements copied, which will be the minimum of len(src) and len(dst).


.. code-block:: go
package main
import "fmt"
func main() {
slice_1 := []int {1, 2, 3, 4, 5}
slice_2 := []int {11, 22}
slice_3 := []int {111}
slice_4 := []int {}
count := copy(slice_1, slice_2)
fmt.Println(count, slice_1)
count = copy(slice_3, slice_2)
fmt.Println(count, slice_3)
count = copy(slice_4, slice_2)
fmt.Println(count, slice_4)
}
// 2 [11 22 3 4 5]
// 1 [11]
// 0 []
SET the GOPATH and GOROOT environments
--------------------------------------

.. code-block:: bash
$ export GOROOT=/usr/lib/go
$ export GOPATH=$HOME/go
$ export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
https://stackoverflow.com/a/43553857

0 comments on commit 91a854b

Please sign in to comment.