Posts

GO111Module environment variable?

 At very first go release we do not have any kind of package versioning. That means if you import any third party package then it always gets its latest version and stores in its GOPATH . Why it is a problem? When developers build the applications , they may use older version or latest version of a package at the time of development. When  a package gets updated then functions behavior changes or the inputs that a updated function may require gets changed , this leads to application breakdown. Why GO111Module is named like that? It is named after the version of the go release 1.11 ,from this version go designers included version controlling for packages. What does GO111Module environment variable is used for? GO111Module env variable has 3 values: auto on off the default value depends on version of go you are using and it also depends on where you project is located, whether in GOPATH or not, whether the working directory contains go.mod file or not. In the latest versions of go ,where

What is go package?

 After we start a project and try to write a new go code, we start with  package < package name > What does this line would do? lets' explore :-) It is used to organize the code into multiple files ,we knew that every package resides in its directory and .go files in this directory should have a package name same as that of directory name. With in this package each .go file can access every other function and variable with in the same package.This makes your code modular and maintainable. In simpler words we can say that, - instead of writing all the code in one source file it can be splitted into multiple source files. directory p1:- package p1 import "fmt" func hello(){ fmt.Println("hello") } directory p2:- package p2 import "fmt" func hello(){ fmt.Println("hello") } If we need a function or a variable to use in another package then we have to export that function or variable ,we can do that by making first

What is go.mod?

For every project in Go we create a directory with the name of the project. With in this directory we initialise with go mod init <name of the module> . What it actually do is, it creates a file named go.mod in the project directory. What it contains? It contains the name of the module and also version of go you are using and also the names of the package along with their version. What is its use? It automatically logs all the go packages and their version that are imported in the project. Why is it required? In order to answer this question one should actually know the drawbacks of other programming languages.Let's have a high level understanding. When ever an import is done, the compiler places the code of the imported file in the source code file this means that the imported file goes under compilation. So what is wrong in that? Think about what if we do not use any feature from the imported file? It is just compiling of no use. As compilation takes times ,having a few us