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

CRUD with Golang

  Overview this blog will be about a  basic crud app with golang .   this app will provide API to store, update, delete information . you need to know the basics of golang to understand this project. if you do not have the basics knowledge  about golang I would suggest you to read my previous blog.  I have uploaded my code in  GitHub. click the link to clone or download this project  I am going to talk about the topic below. Project setup Data handling controller Project setup  Initiate mod and set up project as per golang. if you don't know how to setup golang project i would suggest you to have a look at my blog  Creating a project with golang . this is a really short blog. you will have a quick over view of how to setup a project with golang.  so now that you have setup the project then the folder structure will be as below. Data Handling data store, delete and update will be handled in the user module. code is given below  ...

List of data types in Golang

  index Description 1 Type: int8 8-bit signed integer 2 Type:  int16 16-bit signed integer 3 Type:  int32 32-bit signed integer 4 Type:  int64 64-bit signed integer 5 Type:  uint8 8-bit unsigned integer 6 Type:  uint16 16-bit unsigned integer 7 Type:  uint32 32-bit unsigned integer 8 Type:  uint64 64-bit unsigned integer 9 Type:  int Both in and uint contain same size, either 32 or 64 bit. 10   Type:  uint Both in and uint contain same size, either 32 or 64 bit. 11 Type:  rune It is a synonym of int32 and also represent Unicode code points. 12 Type:  byte It is a synonym of int8 . 13 ...