-
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
Showing
15 changed files
with
381 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,14 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
|
||
// fixed array. sabit boyutlu | ||
var names = []string{"Omer", "Faruk", "Aydin"} | ||
|
||
names = append(names, "Faruk") | ||
|
||
fmt.Println(names) | ||
|
||
} |
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 main() { | ||
|
||
var age int8 = 17 | ||
|
||
if age >= 18 { | ||
fmt.Println("You can vote") | ||
} else { | ||
fmt.Println("You can't vote") | ||
} | ||
} |
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 main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
//stack var lifo var | ||
defer fmt.Println("1.defer") | ||
defer fmt.Println("2.defer") | ||
defer fmt.Println("3.defer") | ||
|
||
x := 10 | ||
y := 20 | ||
defer fmt.Println(x + y) | ||
|
||
fmt.Println("Main started") | ||
|
||
x = 100 | ||
y = 200 | ||
|
||
fmt.Println(x + y) | ||
|
||
var condition = true | ||
defer cleanUp() | ||
|
||
if condition { | ||
panic("Something went wrong") | ||
} | ||
|
||
defer fmt.Println("4.defer") | ||
if condition { | ||
return | ||
} | ||
defer fmt.Println("5.defer") | ||
} | ||
|
||
func cleanUp() { | ||
fmt.Println("Cleaning up") | ||
} |
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,22 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
|
||
var numbers = []int{1, 2, 3, 4} | ||
|
||
/*for index := 0; index < len(numbers); index++ { | ||
fmt.Println(numbers[index]) | ||
}*/ | ||
|
||
for _, value := range numbers { | ||
fmt.Println(value) | ||
} | ||
|
||
var language = "Golang" | ||
|
||
for _, v := range language { | ||
fmt.Printf("%c\n", v) | ||
} | ||
} |
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" | ||
|
||
func main() { | ||
|
||
/*index := 1 | ||
for index <= 10 { | ||
fmt.Println(index) | ||
index++ | ||
}*/ | ||
/*total := 0 | ||
for index := 1; index <= 10; index++ { | ||
total += index | ||
fmt.Println(total) | ||
}*/ | ||
|
||
/*index := 0 | ||
var names = [3]string{"Omer", "Faruk", "Aydin"} | ||
for index < len(names) { | ||
fmt.Print(names[index]) | ||
index++ | ||
}*/ | ||
|
||
/*for index := 0; index <= 10; index++ { | ||
if index == 3 || index == 5 { | ||
continue | ||
} | ||
fmt.Println(index) | ||
}*/ | ||
|
||
var names = map[string]int{ | ||
"Omer": 10, | ||
"Faruk": 20, | ||
"Aydin": 30, | ||
} | ||
|
||
for key, value := range names { | ||
fmt.Printf("Key: %s, Value: %d\n", key, 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,44 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
/*total := add(10, 20) | ||
fmt.Println(total)*/ | ||
//total, diffrence := calculation(30, 20) | ||
//fmt.Println(total, diffrence) | ||
//var numbers = []int{10, 20, 2, 3, 5} | ||
//fmt.Println(sumArray(numbers)) | ||
|
||
fmt.Println(sum(3, 5, 6, 22, 4, 5, 6, 78, 3, 2, 4)) | ||
|
||
} | ||
|
||
//like c# params | ||
func sum(numbers ...int) int { | ||
|
||
sum := 0 | ||
for _, value := range numbers { | ||
sum += value | ||
} | ||
return sum | ||
} | ||
|
||
func sumArray(numbers []int) int { | ||
sum := 0 | ||
|
||
for _, value := range numbers { | ||
sum += value | ||
} | ||
|
||
return sum | ||
} | ||
|
||
func add(x int, y int) int { | ||
return x + y | ||
} | ||
|
||
//like c# tupples | ||
func calculation(x int, y int) (int, int) { | ||
return x + y, x - y | ||
} |
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,3 @@ | ||
module onevideogo | ||
|
||
go 1.23.0 |
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,36 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type IEncoder interface { | ||
Encode(value string) | ||
Decode(value string) | ||
} | ||
|
||
type XEncoder struct { | ||
} | ||
|
||
type YEncoder struct { | ||
} | ||
|
||
func (x *XEncoder) Encode(value string) { | ||
fmt.Println("Encoding by xencoder") | ||
} | ||
|
||
func (x *XEncoder) Decode(value string) { | ||
fmt.Println("Decoding by xencoder") | ||
} | ||
|
||
func (x *YEncoder) Encode(value string) { | ||
fmt.Println("Encoding by Yencoder") | ||
} | ||
|
||
func (x *YEncoder) Decode(value string) { | ||
fmt.Println("Decoding by Yencoder") | ||
} | ||
|
||
func main() { | ||
var encoder IEncoder = &XEncoder{} | ||
|
||
encoder.Encode("123456") | ||
} |
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,42 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type IShippable interface { | ||
ShippingCost() int | ||
} | ||
|
||
type Book struct { | ||
desi int | ||
} | ||
|
||
type Electronic struct { | ||
desi int | ||
} | ||
|
||
func (b *Book) ShippingCost() int { | ||
return b.desi + 5*2 | ||
} | ||
|
||
func (e *Electronic) ShippingCost() int { | ||
return e.desi + 10*2 | ||
} | ||
|
||
func main() { | ||
|
||
var products []IShippable = []IShippable{ | ||
&Book{desi: 10}, | ||
&Electronic{desi: 20}, | ||
&Book{desi: 30}, | ||
} | ||
|
||
fmt.Println(CalculateShippingCost(products)) | ||
} | ||
|
||
func CalculateShippingCost(products []IShippable) int { | ||
cost := 0 | ||
for _, product := range products { | ||
cost += product.ShippingCost() | ||
} | ||
return cost | ||
} |
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 main | ||
|
||
func main() { | ||
|
||
} |
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,27 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
/*var names map[string]int | ||
names = make(map[string]int, 0) | ||
names["Omer"] = 1 | ||
names["Faruk"] = 2 | ||
names["Aydin"] = 3 | ||
fmt.Println(names)*/ | ||
|
||
names := map[string]int{ | ||
"Omer": 1, | ||
"Faruk": 2, | ||
"Aydin": 3, | ||
} | ||
|
||
fmt.Println(names) | ||
|
||
delete(names, "Recep") | ||
|
||
fmt.Println(names) | ||
} |
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,29 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
/*var a int | ||
a = 10 | ||
var p *int | ||
fmt.Println(a) | ||
p = &a | ||
*p = 20 | ||
fmt.Println(a)*/ | ||
|
||
var a = 10 | ||
var b int | ||
var p *int | ||
|
||
b = a | ||
p = &a | ||
*p = 20 | ||
|
||
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,21 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
var x = 10 | ||
|
||
func main() { | ||
var condition = true | ||
|
||
if condition { | ||
//block scope | ||
var x = 10 | ||
fmt.Println(x) | ||
} | ||
|
||
//function scope | ||
fmt.Println(condition) | ||
|
||
//globla scope | ||
fmt.Println(x) | ||
} |
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" | ||
) | ||
|
||
func main() { | ||
|
||
/*var productName string | ||
var quantity int | ||
var discount float32 | ||
var isInStock bool | ||
productName = "Golang" | ||
quantity = 10 | ||
discount = 0.38 | ||
isInStock = false | ||
fmt.Println(productName, reflect.TypeOf(productName)) | ||
fmt.Println(quantity, reflect.TypeOf(quantity)) | ||
fmt.Println(discount, reflect.TypeOf(discount)) | ||
fmt.Println(isInStock, reflect.TypeOf(isInStock))*/ | ||
/*var productName string = "Golang" | ||
fmt.Println(productName, reflect.TypeOf(productName));*/ | ||
|
||
/*productName := "Golang" | ||
fmt.Println(productName)*/ | ||
|
||
var productName string | ||
var quantity int | ||
var discount float32 | ||
var isInStock bool | ||
|
||
productName = "Golang" | ||
quantity = 10 | ||
discount = 0.38 | ||
isInStock = false | ||
|
||
fmt.Println("product name:", productName, "Quantity:", quantity, "Discount:", discount, "IsInStock:", isInStock) | ||
fmt.Printf("Product Name: %s, Quantity: %d, Discount %f, IsInStock %t", productName, quantity, discount, isInStock) | ||
|
||
} |