Posts

Showing posts from March, 2022

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