https://github.com/zain-ul-din/go-fundamentals
Go lang programming fundamentals
https://github.com/zain-ul-din/go-fundamentals
Last synced: 6 months ago
JSON representation
Go lang programming fundamentals
- Host: GitHub
- URL: https://github.com/zain-ul-din/go-fundamentals
- Owner: Zain-ul-din
- Created: 2023-05-17T13:28:59.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-17T13:41:54.000Z (over 2 years ago)
- Last Synced: 2025-03-29T04:47:07.562Z (6 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## GO fundamentals
- fundamentals
- standard libraries
- Go Routines
- fmt Package
- http Package
- Templating
- Web Servers & Services### Run Go Code
- create go file `index.go`
- add following code```go
package main// entry point
func main () {
print("hello world")
}
```
- run command from terminal```bash
go run .go
```### Create Modules
- create module
```bash
go mod init
```- run the code
```bash
go run .
```### Workspaces and CLI
```bash
go work init
```### Variables
```go
//
// !variables are nil by default
//
var x int // syntax: var var_name type
var name string// constants
const z int = 2//
// !string uses double quotes and backticks ``
//
var text string
text = "hello!" // assigning values to a variable// variable initialization shortcut
otherText := "bye!"```
### DataTypes
- some common data types in GO
```go
string
int int8 int16 int32 int64
uint uint8 uint16 uint32 uint64
float32 float64
bool
pointers
```### Operators
```go
== != < > <= >= && || !
```### Packages
```go
package mainimport "fmt" // standard package | custom package
...
```> In go, packages are like partial classes or an assembly in c#.
All files with in same package can access all functions and variables defined in that package.**`index.go`**
```go
package main
/*
Note! packages don't share imports globally.
Other files with in main package must import fmt
package to access it.
*/
import "fmt"...
```
### [fundamental Source Code](https://github.com/Zain-ul-din/go-fundamentals/tree/master/fundamentals)