Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamaney committed Oct 21, 2024
1 parent cd14daf commit 19864db
Show file tree
Hide file tree
Showing 15 changed files with 381 additions and 0 deletions.
14 changes: 14 additions & 0 deletions arrays_slices/main.go
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)

}
14 changes: 14 additions & 0 deletions conitionals/main.go
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")
}
}
38 changes: 38 additions & 0 deletions defer/main.go
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")
}
22 changes: 22 additions & 0 deletions for_each_loops/main.go
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)
}
}
43 changes: 43 additions & 0 deletions for_loops/main.go
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)
}
}
44 changes: 44 additions & 0 deletions functions/main.go
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
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module onevideogo

go 1.23.0
Empty file added go.sum
Empty file.
36 changes: 36 additions & 0 deletions interfaces/a/passwordHashing.go
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")
}
42 changes: 42 additions & 0 deletions interfaces/main.go
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
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {

}
27 changes: 27 additions & 0 deletions maps/main.go
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)
}
29 changes: 29 additions & 0 deletions pointers/main.go
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)

}
21 changes: 21 additions & 0 deletions variable_scopes/main.go
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)
}
43 changes: 43 additions & 0 deletions variables/main.go
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)

}

0 comments on commit 19864db

Please sign in to comment.