Skip to content

Commit b7534b3

Browse files
authored
Add files via upload
1 parent b34be61 commit b7534b3

File tree

56 files changed

+3798
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3798
-0
lines changed

01hello/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/Aniket762/hello
2+
3+
go 1.17

01hello/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("Hello from Golang")
7+
}

02variables/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/Aniket762/variables
2+
3+
go 1.17

02variables/main.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import "fmt"
4+
5+
// when first letter is capital it is public
6+
// variable
7+
8+
// defining immutable variables
9+
// capital L means public variable
10+
const LoginToken string = "awhnswhjbnshwbnsh"
11+
12+
func main() {
13+
var username string = "Aniket762"
14+
fmt.Println(username)
15+
// %T for type
16+
fmt.Printf("Variable is of type: %T \n",username)
17+
18+
var isLoggedIn bool = false
19+
fmt.Println(isLoggedIn)
20+
fmt.Printf("Variable is of type: %T \n",isLoggedIn)
21+
22+
var smallVal uint8 = 12
23+
fmt.Println(smallVal)
24+
fmt.Printf("Variable is of type: %T \n",smallVal)
25+
26+
// default value of an int is 0
27+
28+
// implicit type: not defining type also works
29+
var dob = 672001
30+
fmt.Println(dob)
31+
32+
// no var style - can only be defined under a method or func
33+
// := is volorous operator
34+
numberOfUser := 3000
35+
fmt.Println(numberOfUser)
36+
}

03userinput/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module userinput
2+
3+
go 1.17

03userinput/main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
)
8+
9+
func main() {
10+
a :="aloo"
11+
fmt.Println(a)
12+
13+
reader := bufio.NewReader(os.Stdin)
14+
fmt.Println("Enter")
15+
16+
// comma ok || err ok
17+
// it's like try catch where we take
18+
// the input or error or both.
19+
// incase we wanna ignore one we put _
20+
21+
// ReadString('char') shows till when
22+
// the input will read. Here when enter
23+
// is pressed it will stop taking in the
24+
// input
25+
input , _ := reader.ReadString('\n')
26+
fmt.Println("Entered val:",input)
27+
28+
// over here reader is a pointer
29+
}

04conversion/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module conversion
2+
3+
go 1.17

04conversion/main.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"strconv"
8+
"strings"
9+
)
10+
11+
func main() {
12+
fmt.Println("Please rate our pizza between 1 and 5")
13+
14+
reader := bufio.NewReader(os.Stdin)
15+
input,errors := reader.ReadString('\n')
16+
17+
fmt.Println("Thanks for rating, ", input)
18+
// fmt.Printf("The type of rating %T,",input) // string
19+
if errors != nil {
20+
fmt.Println(errors)
21+
}
22+
23+
// coverting string to number
24+
25+
// strings.TrimSpace is needed to remove the trailing character \n
26+
numRating,errors2 := strconv.ParseFloat(strings.TrimSpace(input),64)
27+
28+
if errors2 != nil {
29+
fmt.Println(errors2)
30+
}
31+
32+
numRating2 := numRating+1
33+
fmt.Println(numRating2)
34+
}

05time/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module times
2+
3+
go 1.17

05time/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func main() {
9+
fmt.Println("Welcome to time study of go")
10+
presentTime := time.Now()
11+
fmt.Println(presentTime)
12+
13+
// the time mentioned below is the std format as in docs
14+
fmt.Println(presentTime.Format("01-02-2006 15:04:05 Monday"))
15+
16+
createdDate := time.Date(2021,time.November,6,21,51,10,6,time.UTC)
17+
fmt.Println(createdDate)
18+
fmt.Println(createdDate.Format("01-02-2006 Monday"))
19+
20+
}
21+
22+
/*
23+
Extras:
24+
To build exes for different os, say I am using MAC
25+
i> Windows build: GOOS="windows" go build
26+
ii> Mac build: go build
27+
iii> Linux build: GOOS="linux" go build
28+
*/

0 commit comments

Comments
 (0)