- The installation script is basically made for Linux operating system.
- All source code contains under
github/ashish041/directory - Project is implemented by Golang programming language.
-
make allcommand to install the whole project. make all command will do following operations.- Install go
- Build application
- Run application on port 3333
- Run unit test
- Call api endpoint
make all
-
make upcommand to run the project without installing go, in case go already installed in the operating system.make upcommand will do following operations.- Build application
- Run app on port 3333
- Run unit test
- Call api endpoint
make up
-
make buildcommand to build the application.make build
-
make runcommand to run the application on port 3333.make run
-
make testcommand to run unit test.make test
-
make callApicommand to call the endpoint.make callApi
-
make docker-allcommand to build a image and run the application on docker.make docker-build
-
make docker-buildcommand to build a image on docker for the application.make docker-build
-
make docker-runcommand to run application on dockermake docker-run
- What does each line do?
export CGO_ENABLED=0 CGO_ENABLED=0 means the flag is disabled to compile cgo (C and GO mixing code) code. CGO_ENABLED is by default enabled means CGO_ENABLED=1. So if we turn off the flag which rebuilds all pre-build packages.
export GO111MODULE=on GO111MODULE=on enable to use GO module, which means GOPATH is no longer supported. The GO module installs packages by specific version and keeps track of each package's version in go.mod.
build: go build -o www This command builds GO code to generate an executable binary by name www.
- What do you expect to happen if you type make?
make command will execute the first target of the Makefile. For my case, make all.
- How can you improve the encryption/decryption algorithm?
To optimize the encryption/decryption algorithm I declare two global variables containing a-z lowercase alphabet and A-Z uppercase alphabet. I convert the input string to byte slice. Then I check if the input string is uppercase or lowercase by a loop. And based on that I calculate the position of the new 32 shift character in the global declaration variable. By this position I get the byte value of the new 32 shift character. Then replace the input character by a new 32 shift character. End the loop when all input characters are replaced. And finally we convert the byte slice to string to get the final output.
Formula I use to calculate the position of the new 32 shift character: (26 + (inputvalue - 'a') + (shift % 26)) % 26
For example if the input character is d.
alphabetLowerCase "abcdefghijklmnopqrstuvwxyz"
byte value of a is 97
byte value of d is 100
shift 32
new position = (26 + (100 - 97) + (shift % 26)) % 26
= (29 + 6) % 26
= 35 % 26
= 9
= j
If we count from 0, the value of position 9 is j in the global variable alphabetLowerCase.
- How can you reduce the Docker image size?
I use a multi-stage build which divides Dockerfile into multiple stages. In The first stage I install Go tools and build Go code which generates an executable binary file and copies the binary file in the second stage. In this way final docoker image won’t have any unnecessary content except required executable binary.