Overview
You can run a go file with out making a project. But the standard way to use go is to create a project or you can call it a space where you will be putting your go code, on the other hand it is a work space, but in Go Lang we call it module. In Go Lang modules are the official way of organize go code.
in this blog I am going to explain the way you create a model and first hello world with that project.
Explanation
To Module you need to run the command bellow
go mod init <module name>
If you can see I have named my module github.com/TahimFaisal/golang. the name of the module is called module initializer. this is the standard way of initialization. And for the go get command it will
it will know where to go and get the mod if it cannot find the mod locally.
Okay, soon after you ran the command you will get a file named go.mod in your working directory
it will be having module initializer and the version of go your using.
now create a main.go file and write the code bellow
you can run it in old way. using command bellow
package main
import "fmt"
func main() {
fmt.Println("hello world!!")
}
- go run .
- go run main.go
but now have initialize the project so you can run it from anywhere in your local pc by using the module initializer. By using the command bellow.
go run <module initializer>
Previous Blog | Next Blog |
---|---|
Golang Commands | Primitive data type of Golang |
Comments
Post a Comment