Go language
https://github.com/KeKe-Li/book/tree/master/Go
https://golang.org/doc/install?download=go1.11.1.darwin-amd64.pkg
-runuje na wielu korach
-jest szybki
1 Getting Started
1.1 Files and Folders
1.2 The Terminal
1.3 Text Editors
1.4 Go Tools
2 Your First Program
2.1 How to Read a Go Program
3 Types
3.1 Numbers
3.2 Strings
3.3 Booleans
4 Variables
4.1 How to Name a Variable
4.2 Scope
4.3 Constants
4.4 Defining Multiple Variables
4.5 An Example Program
5 Control Structures
5.1 For
5.2 If
5.3 Switch
6 Arrays, Slices and Maps
6.1 Arrays
6.2 Slices
6.3 Maps
7 Functions
7.1 Your Second Function
7.2 Returning Multiple Values
7.3 Variadic Functions
7.4 Closure
7.5 Recursion
7.6 Defer, Panic & Recover
8 Pointers
8.1 The * and & operators
8.2 new
9 Structs and Interfaces
9.1 Structs
9.2 Methods
9.3 Interfaces
10 Concurrency
10.1 Goroutines
10.2 Channels
11 Packages
11.1 Creating Packages
11.2 Documentation
12 Testing
13 The Core Packages
13.1 Strings
13.2 Input / Output
13.3 Files & Folders
13.4 Errors
13.5 Containers & Sort
13.6 Hashes & Cryptography
13.7 Servers
13.8 Parsing Command Line Arguments
13.9 Synchronization Primitives
14 Next Steps
14.1 Study the Masters
14.2 Make Something
14.3 Team Up
https://www.golang-book.com/public/pdf/gobook.0.pdf
///////////////
https://play.golang.org/p/g75BhKoLTwx jak chcesz challenge, zwroc w wyniku ilosc wystapien danego slowa w piosence
jak napiszesz to na gorze share robi link do wysharowania danego stanu edytora - po kazdej zmianie trzba robic nowy share
a najlepiej kopiuj sobie na bok bo potrafi zginac czasem
//////////
package main
import (
"fmt"
"strings"
)
const song = `
Elsa?
Do you want to build a snowman?
Come on, let's go and play!
I never see you anymore
Come out the door
It's like you've gone away
We used to be best buddies
And now we're not
I wish you would tell me why!
Do you want to build a snowman?
It doesn't have to be a snowman
Go away, Anna
Okay, bye
Do you want to build a snowman?
Or ride our bike around the halls?
I think some company is overdue
I've started talking to
The pictures on the walls!
It gets a little lonely
All these empty rooms
Just watching the hours tick by
(tick-tock tick-tock tick-tock tick-tock)
Elsa, please I know you're in there
People are asking where you've been
They say, have courage and I'm trying to
I'm right out here for you
Just let me in
We only have each other
It's just you and me
What are we gonna do?
Do you want to build a snowman?
`
func main() {
words := strings.Fields(song) // words to []string
fmt.Println(len(words))
}
///////////////////
package main
import (
"fmt"
"strings"
)
const song = `
Elsa?
Do you want to build a snowman?
Come on, let's go and play!
I never see you anymore
Come out the door
It's like you've gone away
We used to be best buddies
And now we're not
I wish you would tell me why!
Do you want to build a snowman?
It doesn't have to be a snowman
Go away, Anna
Okay, bye
Do you want to build a snowman?
Or ride our bike around the halls?
I think some company is overdue
I've started talking to
The pictures on the walls!
It gets a little lonely
All these empty rooms
Just watching the hours tick by
(tick-tock tick-tock tick-tock tick-tock)
Elsa, please I know you're in there
People are asking where you've been
They say, have courage and I'm trying to
I'm right out here for you
Just let me in
We only have each other
It's just you and me
What are we gonna do?
Do you want to build a snowman?
`
func WordCount(s string) map[string]int {
strs := strings.Fields(s)
res := make(map[string]int)
fmt.Println(res)
for key, value := range strs {
fmt.Println(key, value)
res[strings.ToLower(value)]++
}
fmt.Println(res)
return res
}
func main() {
words := strings.Fields(song) // words to []string
fmt.Println(len(words))
fmt.Println(WordCount("Word count test count Word"))
fmt.Println(WordCount("CAT CAt CaT Cat cAT Word cAt caT cat"))
}
/////////////////////////////////////////
https://github.com/queertypes/learn2go
https://tour.golang.org/welcome/1
https://blog.golang.org/go-maps-in-action
https://gobyexample.com/range
https://golang.org/doc/install?download=go1.11.1.darwin-amd64.pkg
Go is a static-typed language (as opposed to dynamic typing with something like Python), and has concepts like concurrency baked in right from the start. For me personally, my main interest in Go is for web development, but I can see it being useful for a variety of high-volume types of tasks and just systems in general. Not only does Go have web frameworks, the language itself comes out of the gate with full web support, a built in web server, and could be considered already a low-level web framework.
To begin, we need Go. You can download Go here. In Windows, you can just grab a simple installer, a .pkg for Mac, or a tarball for Linux. If you are on Linux, make sure you add Go to your path. You can do that by:
nano ~/.profile
And then add the following to the end of the file:
export PATH=$PATH:/usr/local/go/bin
Save, exit and then do:
$ source ~/.profile
A simple Go program will just consist of a single
.go file. You can make and edit this file with whatever you want. I will personally be using Sublime Text. On Windows, it's a simple .exe installer, on Linux you can get Sublime with:$ sudo add-apt-repository ppa:webupd8team/sublime-text-3 $ sudo apt-get update $ sudo apt-get install sublime-text-installer
To run your files, you use your terminal / cmd.exe and use the syntax:
go run YOURFILE.go
Let's write a quick basic Go program to see if we've got everything setup and ready to go:
gointro.gopackage main import "fmt" func main() { fmt.Println("Welcome to Go!") }
To run this, we can do
go run gointro.go, and you should see:Welcome to Go!
If you made it this far, congratulations on your first Go program! Let's cover briefly what each line is doing. I will do this by commenting above or beside the lines what they do. If you do not know what comments are in programming, they are ways to write notes and such in your code that will not be run as actual code when your program runs. In Go, the way you can do single-line comments is with
// and you can do multi-line comments with /* and end with */package main //go programs consist of packages, and start with main // import a library/package. In this case we import fmt, which brings in // standard formatted I/O strings from C import "fmt" // syntax for a function in Go. // define, name, parms, and your code goes in curly braces. func main() { //print line just outputs what you mass. // Println is a function from the fmt library // we can reference other packages from fmt with . fmt.Println("Welcome to Go!") } //we'll talk more on some other specifics in the next tutorial, such as how or why this main function even runs.
https://pythonprogramming.net/go/introduction-go-language-programming-tutorial/
-runuje na wielu korach
-jest szybki
1 Getting Started
1.1 Files and Folders
1.2 The Terminal
1.3 Text Editors
1.4 Go Tools
2 Your First Program
2.1 How to Read a Go Program
3 Types
3.1 Numbers
3.2 Strings
3.3 Booleans
4 Variables
4.1 How to Name a Variable
4.2 Scope
4.3 Constants
4.4 Defining Multiple Variables
4.5 An Example Program
5 Control Structures
5.1 For
5.2 If
5.3 Switch
6 Arrays, Slices and Maps
6.1 Arrays
6.2 Slices
6.3 Maps
7 Functions
7.1 Your Second Function
7.2 Returning Multiple Values
7.3 Variadic Functions
7.4 Closure
7.5 Recursion
7.6 Defer, Panic & Recover
8 Pointers
8.1 The * and & operators
8.2 new
9 Structs and Interfaces
9.1 Structs
9.2 Methods
9.3 Interfaces
10 Concurrency
10.1 Goroutines
10.2 Channels
11 Packages
11.1 Creating Packages
11.2 Documentation
12 Testing
13 The Core Packages
13.1 Strings
13.2 Input / Output
13.3 Files & Folders
13.4 Errors
13.5 Containers & Sort
13.6 Hashes & Cryptography
13.7 Servers
13.8 Parsing Command Line Arguments
13.9 Synchronization Primitives
14 Next Steps
14.1 Study the Masters
14.2 Make Something
14.3 Team Up
https://www.golang-book.com/public/pdf/gobook.0.pdf
///////////////
https://play.golang.org/p/g75BhKoLTwx jak chcesz challenge, zwroc w wyniku ilosc wystapien danego slowa w piosence
jak napiszesz to na gorze share robi link do wysharowania danego stanu edytora - po kazdej zmianie trzba robic nowy share
a najlepiej kopiuj sobie na bok bo potrafi zginac czasem
//////////
package main
import (
"fmt"
"strings"
)
const song = `
Elsa?
Do you want to build a snowman?
Come on, let's go and play!
I never see you anymore
Come out the door
It's like you've gone away
We used to be best buddies
And now we're not
I wish you would tell me why!
Do you want to build a snowman?
It doesn't have to be a snowman
Go away, Anna
Okay, bye
Do you want to build a snowman?
Or ride our bike around the halls?
I think some company is overdue
I've started talking to
The pictures on the walls!
It gets a little lonely
All these empty rooms
Just watching the hours tick by
(tick-tock tick-tock tick-tock tick-tock)
Elsa, please I know you're in there
People are asking where you've been
They say, have courage and I'm trying to
I'm right out here for you
Just let me in
We only have each other
It's just you and me
What are we gonna do?
Do you want to build a snowman?
`
func main() {
words := strings.Fields(song) // words to []string
fmt.Println(len(words))
}
///////////////////
package main
import (
"fmt"
"strings"
)
const song = `
Elsa?
Do you want to build a snowman?
Come on, let's go and play!
I never see you anymore
Come out the door
It's like you've gone away
We used to be best buddies
And now we're not
I wish you would tell me why!
Do you want to build a snowman?
It doesn't have to be a snowman
Go away, Anna
Okay, bye
Do you want to build a snowman?
Or ride our bike around the halls?
I think some company is overdue
I've started talking to
The pictures on the walls!
It gets a little lonely
All these empty rooms
Just watching the hours tick by
(tick-tock tick-tock tick-tock tick-tock)
Elsa, please I know you're in there
People are asking where you've been
They say, have courage and I'm trying to
I'm right out here for you
Just let me in
We only have each other
It's just you and me
What are we gonna do?
Do you want to build a snowman?
`
func WordCount(s string) map[string]int {
strs := strings.Fields(s)
res := make(map[string]int)
fmt.Println(res)
for key, value := range strs {
fmt.Println(key, value)
res[strings.ToLower(value)]++
}
fmt.Println(res)
return res
}
func main() {
words := strings.Fields(song) // words to []string
fmt.Println(len(words))
fmt.Println(WordCount("Word count test count Word"))
fmt.Println(WordCount("CAT CAt CaT Cat cAT Word cAt caT cat"))
}
/////////////////////////////////////////
https://github.com/queertypes/learn2go
https://tour.golang.org/welcome/1
https://blog.golang.org/go-maps-in-action
https://gobyexample.com/range
Komentarze
Prześlij komentarz