forked from figui/golang-tutorial-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 48e9f29
Showing
73 changed files
with
1,473 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Golang Tutorial | ||
|
||
<p align="center"> | ||
<img src="https://howtolearn.me/wp-content/uploads/2015/05/golang-logo.png"/> | ||
</p> | ||
|
||
##Questions? | ||
|
||
Ask [email protected] | ||
|
||
Ask [email protected] |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Hello, 世界") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
var i int | ||
var f float64 | ||
var b bool | ||
var s string | ||
|
||
func init(){ | ||
fmt.Println("Se ejecuta init") | ||
} | ||
|
||
func main() { | ||
fmt.Printf("%v %v %v %q\n", i, f, b, s) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
var s string | ||
|
||
args:=[]string{"arg1","arg2","arg3","arg4"} | ||
|
||
for i := 0; i < len(args); i++ { | ||
s += args[i] + " " | ||
} | ||
|
||
fmt.Println("Result 1: " + s) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
var s string | ||
args:=[]string{"arg1","arg2","arg3","arg4"} | ||
|
||
i := 0 | ||
for i < len(args) { | ||
s += args[i] + " " | ||
i++ | ||
} | ||
|
||
fmt.Println("Result 2: " + s) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
var s string | ||
args:=[]string{"arg1","arg2","arg3","arg4"} | ||
|
||
i := 0 | ||
for { | ||
if i >= len(args) { | ||
break | ||
} | ||
s += args[i] + " " | ||
i++ | ||
} | ||
fmt.Println("Result 3: " + s) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
var s string | ||
args:=[]string{"arg1","arg2","arg3","arg4"} | ||
|
||
for _, value := range args { | ||
s += value + " " | ||
} | ||
fmt.Println("Result 4: " + s) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
func main() { | ||
fmt.Print("Go runs on ") | ||
|
||
switch os := runtime.GOOS; os { | ||
case "darwin": | ||
fmt.Println("OS X.") | ||
case "linux": | ||
fmt.Println("Linux.") | ||
default: | ||
fmt.Printf("%s.", os) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func swap(x, y string) (string, string) { | ||
return y, x | ||
} | ||
|
||
func main() { | ||
a, b := swap("hello", "world") | ||
fmt.Println(a, b) | ||
a, b = b,a | ||
fmt.Println(a, b) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/rodriguezgustavo/go-talks/2016-10-BsAs/resources/src/4_packages/math" | ||
) | ||
|
||
func main() { | ||
var result int | ||
args:=[]int{1,2,3,4} | ||
for _, val := range args { | ||
result = math.Add(result, val) | ||
} | ||
fmt.Printf("Suma: %d\n", result) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package math | ||
|
||
func Add(x, y int) int { | ||
return x + y | ||
} |
13 changes: 13 additions & 0 deletions
13
go-talks/resources/src/05_variables_type_convertion/main.go
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
func main() { | ||
var x, y int = 3, 4 | ||
var f float64 = math.Sqrt(float64(x*x + y*y)) | ||
var z uint = uint(f) | ||
fmt.Println(x, y, z) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
func main() { | ||
x := 4 | ||
fmt.Println("X Value:" + strconv.Itoa(x)) | ||
y := new(int) | ||
fmt.Println("Y Value:" + strconv.Itoa(*y)) | ||
*y = 4 | ||
fmt.Println("Y Value:" + strconv.Itoa(*y)) | ||
if y == &x { | ||
fmt.Println("X & Y are equals") | ||
} else { | ||
fmt.Println("X & Y are not equals") | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
var n = flag.Bool("n", false, "Omitir tailing") | ||
|
||
var sep = flag.String("s", " ", "Separador") | ||
|
||
func main() { | ||
flag.Parse() | ||
fmt.Print(strings.Join(flag.Args(), *sep)) | ||
if !*n { | ||
fmt.Println() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
|
||
// START OMIT | ||
|
||
type Celsius float64 | ||
type Fahrenheit float64 | ||
|
||
const AbsoluteZeroC Celsius = -273.15 | ||
const FreezingC Celsius = 0 | ||
const BoilingC Celsius = 100 | ||
|
||
func (c Celsius) String() string { | ||
return fmt.Sprintf("%g°C", c) | ||
} | ||
|
||
func (f Fahrenheit) String() string { | ||
return fmt.Sprintf("%g°F", f) | ||
} | ||
|
||
func CToF(c Celsius) Fahrenheit { | ||
return Fahrenheit(c*9/5 + 32) | ||
} | ||
|
||
func FToC(f Fahrenheit) Celsius { | ||
return Celsius((f - 32) * 5 / 9) | ||
} | ||
|
||
// END OMIT | ||
|
||
func main() { | ||
args:= []float64{15,2, 20, 100, 120} | ||
for _, t := range args { | ||
f := Fahrenheit(t) | ||
c := Celsius(t) | ||
fmt.Printf("%s = %s, %s = %s\n", | ||
f, FToC(f).String(), c, CToF(c).String()) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sort | ||
|
||
type tree struct { | ||
value int | ||
left, right *tree | ||
} | ||
|
||
func Sort(values []int) { | ||
var root *tree | ||
for _, v := range values { | ||
root = add(root, v) | ||
} | ||
appendValues(values[:0], root) | ||
} | ||
|
||
func appendValues(values []int, t *tree) []int { | ||
if t != nil { | ||
values = appendValues(values, t.left) | ||
values = append(values, t.value) | ||
values = appendValues(values, t.right) | ||
} | ||
return values | ||
} | ||
|
||
func add(t *tree, value int) *tree { | ||
if t == nil { | ||
// Equivalent to return &tree{value: value}. | ||
t = new(tree) | ||
t.value = value | ||
return t | ||
} | ||
if value < t.value { | ||
t.left = add(t.left, value) | ||
} else { | ||
t.right = add(t.right, value) | ||
} | ||
return t | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package sort | ||
|
||
import ( | ||
"math/rand" | ||
"sort" | ||
"testing" | ||
) | ||
|
||
func TestSort(t *testing.T) { | ||
data := make([]int, 50) | ||
for i := range data { | ||
data[i] = rand.Int() % 50 | ||
} | ||
Sort(data) | ||
if !sort.IntsAreSorted(data) { | ||
t.Errorf("not sorted: %v", data) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
a := [2]string{"1", "2"} | ||
b := [...]string{"1", "2"} | ||
c := [2]string{"1","3"} | ||
|
||
fmt.Println(c[0], c[len(a)-1] ) | ||
fmt.Println( a == b, a==c) | ||
|
||
for _, value := range a { | ||
fmt.Print(value+" ") | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
a1 := [...]int{1,2,3} | ||
|
||
s1 := a1[0:2] // same as s1:=a1[:2] | ||
var s2 []int // len(s2) == 0 , s2== nil | ||
s3 := make([]int, 2) //len(s3) ==2 , cap==2. Same as make([]int,2,2) | ||
|
||
s1 = append(s1, 5) | ||
s2 = append(s2, 5) | ||
s3 = append(s3, 5) | ||
|
||
fmt.Println(s1 , s2 , s3) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
m := make(map[int]int) | ||
var m2 map[int]int | ||
|
||
m[1] = 1 | ||
m[2] = 2 | ||
m[3] = 3 | ||
delete(m,3) | ||
|
||
fmt.Println(m2==nil) //panic if m2[0]=1 | ||
for key, value := range m { | ||
fmt.Printf("Key: %d, Value: %d \n", key, value) | ||
} | ||
} |
Oops, something went wrong.