Go is an open source programming language, which is statically typed. Although it is statically typed, it is so fast that it feels like an interpreted language

So let's start with the basics. Since Go is a compiled language, its code must be converted into an executable/binary file. Go has a compiler that can translate the code into a binary file

If your file name is helloworld.go and then compile it on the terminal, the command will look like this

go build helloworld.go

This command will create a helloworld file. To perform this operation, call ./helloworld in the terminal

./helloworld

There is a run command to compile and execute the code. Although running the command will not create a binary file.

For example, run the command on the helloworld.go file, it looks like this

go run helloworld.go

Go programs should have a package declaration. After the package declaration, we have import statements under it. look like


package main

import "fmt"

Please note that the package name must be included in double quotes.

Functions in Go are declared with the func keyword, followed by the function name.

Let's look at a basic program: In the main function above, we use fmt to help us call Println for printing.

package main

import "fmt"

func main() {

        fmt.Println(" Hello World! ")

}
go run main.go

This will print the message "Hello World!".

In the Go language, the main package is a special package that is used with executable programs. This package contains the main() function. Go will automatically call the main function, no need to call it explicitly

点赞(0)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部