GO PROGRAMMING LANGUAGE — 2

Didem Kış
2 min readNov 6, 2023

Hello, I started to learn the very popular Go language, and as a result of a lot of training and research, I share my Go language knowledge with you in parts. Have a good read.

PACKAGE LOGIC

  • The GO language is a module logic system.
  • The logic is as follows, we have our modules and we create our packages in these modules. Within these packages we have functions. We create all these according to our own theme and use them where necessary. There are also examples below.
  • Each source file starts with a package declaration, indicating which package the file belongs to. Package names are always in lower case.
  • All .go files of a package are located in a single directory. Also, only one package can reside in a directory.
  • The main package is special because it defines an executable instead of a library. Each executable must contain a main package and a main function with an entry point.
  • Imported packages are added when linking the script.
  • Imported packages can be renamed (e.g. importing format “fmt” will rename package “fmt” to “format”).

To call our other files in our main;
First we create a model in our terminal, I called it golesson, something else can be put in it. We switch to our main file and call it by writing the next code.

go mod init golessson 
package main 

import "golesson/Variables"
func main(){
Variables.variables //Folder name and the name of the file in it
}

VARIABLE IDENTIFICATION

Usevar to define a variable. This is followed by the name and type of the variable. You can define variables by grouping them together instead of defining them individually.

var metin string = "Go dilinde değişken tanımlamayı öğreniyorum. "  
fmt.Print(metin) //We print our variable.

Output:

Go dilinde değişken tanımlamayı öğreniyorum.
hesap := 100 // Closed variable assignment.
fmt.Println(hesap)

// If we want to learn data type
fmt.Printf("veri tipi : %T", hesap)

Output:

100
veri tipi : int

“:=” means both definition and assignment of the variable.
It goes to the bottom line with the \n character.
Printf = tells us the format, i.e. the data type.
The percentage sign “%T” prints the first after it and the T sign prints the type.

See you in my next GO language article. 👋 . At the same time, I will be adding Go language projects to my githup account, you can follow me there. Githup

Please contact me if I am wrong. 😇

--

--