Skip to content

Commit

Permalink
Repo created
Browse files Browse the repository at this point in the history
Session 2 added
  • Loading branch information
hamed committed May 11, 2022
0 parents commit a2ef365
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/bin/*
**/obj/*
80 changes: 80 additions & 0 deletions 02-Introduction/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Golang-Tutorial

## Session 2

**Tools**:

### Install Go Language 1.18

#### Windows:

[Download here](https://go.dev/dl/go1.18.1.windows-amd64.msi) and then install

#### Linux Method 1:

Run this commands in terminal:

sudo apt update
sudo apt search golang-go
sudo apt search gccgo-go
sudo apt install golang-go

#### Linux Method 2:

1. [Download file](https://go.dev/dl/go1.18.1.linux-amd64.tar.gz)
2. Extract file `tar -xf "go1.18.1.linux-amd64.tar.gz"`
3. Go to go folder `cd go/`
4. Setup permissions `sudo chown -R root:root ./go`
5. Move go binaries to local folder `sudo mv -v go /usr/local`
6. for Setup go path, open profile: `vim ~/.bash_profile`
7. Append following to lines to file:
```
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
```

### Install Visual Studio Code

[Download here](https://code.visualstudio.com/download)

### Install Git

#### Windows:

[Download frome here](https://gitforwindows.org/) and then install

#### Linux:

Run this commands in terminal:

sudo apt update
sudo apt-get install git

### VS Code Extensions

Run this commands in terminal

```
code --install-extension aaron-bond.better-comments
code --install-extension christian-kohler.path-intellisense
code --install-extension ckolkman.vscode-postgres
code --install-extension cweijan.vscode-redis-client
code --install-extension donjayamanne.githistory
code --install-extension eamodio.gitlens
code --install-extension esbenp.prettier-vscode
code --install-extension formulahendry.code-runner
code --install-extension golang.go
code --install-extension HookyQR.beautify
code --install-extension IBM.output-colorizer
code --install-extension mhutchie.git-graph
code --install-extension ms-azuretools.vscode-docker
code --install-extension PKief.material-icon-theme
code --install-extension premparihar.gotestexplorer
code --install-extension rangav.vscode-thunder-client
code --install-extension redhat.vscode-yaml
code --install-extension streetsidesoftware.code-spell-checker
code --install-extension TabNine.tabnine-vscode
code --install-extension VisualStudioExptTeam.vscodeintellicode
code --install-extension vscode-icons-team.vscode-icons
code --install-extension wmaurer.change-case
```
84 changes: 84 additions & 0 deletions 09-structs/06-embeded-structs/CsharpInheritance/BadExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using Newtonsoft;
using Newtonsoft.Json;

namespace Bad
{
public class Example
{
public static void Call()
{

var mobile = new Mobile { Name = "Samsung M510" };
mobile.Brand = "Samsung";
mobile.Color = "Blue";
mobile.Ram = 4;
mobile.OperatingSystem = "Android";
mobile.OperatingSystemVersion = "11";

mobile.CameraCount = 2;
mobile.NetworkType = "5G";
mobile.SimcardType = "Nano";
mobile.SimcardCapacity = 3;

var loptop = new Loptop { Name = "MSI GX4450" };

loptop.Brand = "MSI";
loptop.Color = "Black";
loptop.Ram = 16;
loptop.OperatingSystem = "Ubuntu";
loptop.OperatingSystemVersion = "22.04";

loptop.HasCdRom = false;
loptop.UsbPortCount = 3;
loptop.KeyboardType = "Light";

Console.WriteLine(JsonConvert.SerializeObject(mobile));
Console.WriteLine(JsonConvert.SerializeObject(loptop));

}
}

////////////////////////////////////////////

public class Mobile
{
public string Name { get; set; }
public string Color { get; set; }
public float Length { get; set; }
public float Width { get; set; }
public float Weight { get; set; }
public decimal Price { get; set; }
public string Brand { get; set; }
public string MadeIn { get; set; }
public int Ram { get; set; }
public string Cpu { get; set; }
public float ScreenSize { get; set; }
public string OperatingSystem { get; set; }
public string OperatingSystemVersion { get; set; }
public int SimcardCapacity { get; set; }
public string SimcardType { get; set; }
public string NetworkType { get; set; }
public int CameraCount { get; set; }
}

public class Loptop
{
public string Name { get; set; }
public string Color { get; set; }
public float Length { get; set; }
public float Width { get; set; }
public float Weight { get; set; }
public decimal Price { get; set; }
public string Brand { get; set; }
public string MadeIn { get; set; }
public int Ram { get; set; }
public string Cpu { get; set; }
public float ScreenSize { get; set; }
public string OperatingSystem { get; set; }
public string OperatingSystemVersion { get; set; }
public int UsbPortCount { get; set; }
public string KeyboardType { get; set; }
public bool HasCdRom { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Lang>10</Lang>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
</ItemGroup>
</Project>
81 changes: 81 additions & 0 deletions 09-structs/06-embeded-structs/CsharpInheritance/GoodExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using Newtonsoft.Json;

namespace Good
{
public class Example
{
public static void Call()
{

var mobile = new Mobile { Name = "Samsung M510" };
mobile.Brand = "Samsung";
mobile.Color = "Blue";
mobile.Ram = 4;
mobile.OperatingSystem = "Android";
mobile.OperatingSystemVersion = "11";

mobile.CameraCount = 2;
mobile.NetworkType = "5G";
mobile.SimcardType = "Nano";
mobile.SimcardCapacity = 3;

var loptop = new Loptop { Name = "MSI GX4450" };

loptop.Brand = "MSI";
loptop.Color = "Black";
loptop.Ram = 16;
loptop.OperatingSystem = "Ubuntu";
loptop.OperatingSystemVersion = "22.04";

loptop.HasCdRom = false;
loptop.UsbPortCount = 3;
loptop.KeyboardType = "Light";

Console.WriteLine(JsonConvert.SerializeObject(mobile));
Console.WriteLine(JsonConvert.SerializeObject(loptop));
}
}

////////////////////////////////////////////

public abstract class Product
{
public string Name { get; set; }
public string Color { get; set; }
public float Length { get; set; }
public float Width { get; set; }
public float Weight { get; set; }
public decimal Price { get; set; }
public string Brand { get; set; }
public string MadeIn { get; set; }
}

public abstract class ElectronicProduct : Product
{
public int Ram { get; set; }
public string Cpu { get; set; }
public float ScreenSize { get; set; }
public string OperatingSystem { get; set; }
public string OperatingSystemVersion { get; set; }

}

public class Mobile : ElectronicProduct
{

public int SimcardCapacity { get; set; }
public string SimcardType { get; set; }
public string NetworkType { get; set; }
public int CameraCount { get; set; }

}

public class Loptop : ElectronicProduct
{
public int UsbPortCount { get; set; }
public string KeyboardType { get; set; }
public bool HasCdRom { get; set; }

}
}
14 changes: 14 additions & 0 deletions 09-structs/06-embeded-structs/CsharpInheritance/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace CsharpInheritance
{
public class Program
{
public static void Main(string[] args)
{
if (args.Length > 0 && args?[0] == "good")
Good.Example.Call();
else
Bad.Example.Call();

}
}
}
76 changes: 76 additions & 0 deletions 09-structs/06-embeded-structs/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"encoding/json"
)

type Product struct {
Name string
Color string
Length int
Width int
Weight int
Price int
Brand string
MadeIn string
}

type ElectronicProduct struct {
Product
Ram int
Cpu string
ScreenSize float32
OperatingSystem string
OperatingSystemVersion string
}

type Mobile struct {
ElectronicProduct
SimcardCapacity int
SimcardType string
NetworkType string
CameraCount int
}

type Loptop struct {
ElectronicProduct
UsbPortCount int
KeyboardType string
HasCdRom bool
}

func main() {

mobile := Mobile{}
mobile.Name = "Samsung M4150"
mobile.Brand = "Samsung"
mobile.Color = "Blue"
mobile.Ram = 4
mobile.OperatingSystem = "Android"
mobile.OperatingSystemVersion = "11"

mobile.CameraCount = 2
mobile.NetworkType = "5G"
mobile.SimcardType = "Nano"
mobile.SimcardCapacity = 3

loptop := Loptop{}

loptop.Name = "MSI GX 4570"
loptop.Brand = "MSI"
loptop.Color = "Black"
loptop.Ram = 16
loptop.OperatingSystem = "Ubuntu"
loptop.OperatingSystemVersion = "22.04"

loptop.HasCdRom = false
loptop.UsbPortCount = 3
loptop.KeyboardType = "Light"

mobileJson, _ := json.Marshal(mobile)
loptopJson, _ := json.Marshal(loptop)

println(string(mobileJson))
println(string(loptopJson))

}
20 changes: 20 additions & 0 deletions 09-structs/06-embeded-structs/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestMain(t *testing.T) {
type testCase struct {
Name string
}

validate := func(t *testing.T, tc *testCase) {
t.Run(tc.Name, func(t *testing.T) {
main()
})
}

validate(t, &testCase{})
}
17 changes: 17 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div dir="rtl">

# دوره آموزش Go

<p></p>

# [فصل 1 : معرفی دوره](01)

<p></p>

# [فصل 2 : پیش نیاز ها](02-Introduction)

<p></p>

# [فصل 3 : آشنایی با دیتا تایپ ها](03)

</div>

0 comments on commit a2ef365

Please sign in to comment.