Skip to main content

Creating a project with Golang

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> 

Create a project with Go lang command


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.    

Create a project with Go lang command

now create a main.go file and write the code bellow 

	package main
	import "fmt"
	
	func main() {
		fmt.Println("hello world!!")
	}
    
you can run it in old way. using command bellow 
  • 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>
run go code command



Previous Blog Next Blog
Golang Commands Primitive data type of Golang


Comments

Popular posts from this blog

Primitive data type of Golang

Overview In this blog I am going to talk about the date types and variables in go. and the topics bellow  Declaring and initializing variables   explicit initialization of variables   implicit initialization of variables complex data type list of data type Pointer pointer operator dereferencing operator address of operator Constant Iota and constant expression Declaring and initializing variables there are 2 ways you can declarer and initialize a variable they are explicit initialization variables  implicit initialization variables  Explicit initialization of variables  in this way you have to tell the compiler every thing you need to declare a variable. var i int i = 20 var j int = 3 fmt.Println(i,j) var f float32 = 32.233 fmt.Println(f)  in this way we are explicitly telling what will be the input type for that variable. Implicit initialization of variables  in this way of declaring a variable. we don't have ...

Collections of Golang

  Overview I have discussed data type and other basic stuff on the previous blog. Pleas check that blog by clicking on this link  . in this blog i am going to talk about the topic below Array Slice Map Structs   Array An array is a fixed size collection of similar data type .  In golang you can declare array in two way implicate and explicate. in explicate initialization you need to initialize array as bellow.      var < name> [< size> ] < type> in implicate initialization you need to initialize array as bellow.      <name> := [ <size> ] <type> {} for implicate initialization you don't have to say size of the array if your not sure of the size. compiler will automatically increase the size as you go on farther. Code : var i int package main import ( "fmt" ) func main() { var arr [3]int arrSecond := [3]int{15,45,85} arrthird...