Sample Go
Created
August 11, 2015 04:22
-
-
Save tanjo/cb585e027887ee33aa80 to your computer and use it in GitHub Desktop.
Go Sample
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func main() { | |
fmt.Println(math.Pi) | |
} |
This file contains hidden or 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
package main | |
import "fmt" | |
func add(x int, y int) int { | |
return x + y | |
} | |
func main() { | |
fmt.Println(add(42, 13)) | |
} |
This file contains hidden or 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
package main | |
import "fmt" | |
func add(x, y int) int { | |
return x + y | |
} | |
func main() { | |
fmt.Println(add(42, 13)) | |
} |
This file contains hidden or 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
package main | |
import "fmt" | |
func main() { | |
fmt.Printf("hello, world\n") | |
} |
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"net" | |
"os" | |
"time" | |
) | |
func main() { | |
fmt.Println("Welcome to the playground!") | |
fmt.Println("The time is", time.Now()) | |
fmt.Println("And if you try to open a file:") | |
fmt.Println(os.Open("filename")) | |
fmt.Println("Or access the network:") | |
fmt.Println(net.Dial("tcp", "google.com")) | |
} |
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func main() { | |
fmt.Printf("Now you have %g problems.", math.Nextafter(2, 3)) | |
} | |
This file contains hidden or 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
package main | |
import "fmt" | |
func swap(x, y string) (string, string) { | |
return x, y | |
} | |
func main() { | |
a, b := swap("hello", "world") | |
fmt.Println(a, b) | |
} |
This file contains hidden or 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
package main | |
import "fmt" | |
func split(sum int) (x, y int) { | |
x = sum * 4 / 9 | |
y = sum - x | |
return | |
} | |
func main() { | |
fmt.Println(split(17)) | |
} |
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
) | |
func main() { | |
rand.Seed(30) | |
fmt.Println("My favorite number is", rand.Intn(10)) | |
} |
This file contains hidden or 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
package main | |
import "fmt" | |
func main() { | |
var i, j int = 1, 2 | |
k := 3 | |
c, python, java := true, false, "no!" | |
fmt.Println(i, j, k, c, python, java) | |
} |
This file contains hidden or 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
package main | |
import "fmt" | |
var i int | |
var c, python, java bool | |
func main() { | |
fmt.Println(i, c, python, java) | |
} |
This file contains hidden or 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
package main | |
import "fmt" | |
var i, j int = 1, 2 | |
var c, python, java = true, false, "no!" | |
func main() { | |
fmt.Println(i, j, c, python, java) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment