https://github.com/rstudio-tech/micro_go_ecommerce
Go ecommerce backend with microservice
https://github.com/rstudio-tech/micro_go_ecommerce
ecommerce-website golang microservices
Last synced: 12 months ago
JSON representation
Go ecommerce backend with microservice
- Host: GitHub
- URL: https://github.com/rstudio-tech/micro_go_ecommerce
- Owner: rstudio-tech
- License: mit
- Created: 2024-12-11T20:57:26.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-11T21:05:23.000Z (over 1 year ago)
- Last Synced: 2025-07-02T17:55:28.760Z (12 months ago)
- Topics: ecommerce-website, golang, microservices
- Language: Go
- Homepage:
- Size: 3.5 MB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Golang Server Project Best Practices
### PS. Each Directory is a microservice and has its own Readme and each directory uses some new tech. So, do check it out.
## Dependency Injection :-
In simple words, we want our functions and packages to receive the objects they depend on ie. We dont want to declare new instances inside packages to have control over them. For Eg :- Using Structs to declare the private methods and save logger as a variables. The methods can access the value of logger using `g.logger` in their domain.
## Handle Timeouts :-
This is to prevent DOS attacks. Dont make requests make infinitely if your server crashes.
## Graceful Shutdown :-
Wait until current requests are handled and then shutdown the server. We use signal interrupts for this with channels
## Using JSON Encoder :-
Sometimes it is better to use Encoder than json.Marshal as we dont have to use additional buffer. This will matter when there are a lot of concurrent go routines being processed. It is also a bit faster.
## Validation of Data is very Important :-
Middleware ensures Connectivity between 2 or more types applications or components. You can write your validation code in middleware to make sure data is validated and then only goes to your handlers
## Running using Docker Image
`docker build . -t shadowshotx/product-go-micro`
`docker run --network host -d `
## Using CORS
Cross Origin Resource Sharing. Good security measure to protect the websites from malicious calls. It defines origins allowed to talk to the API. If source is not allowed, we reject the request.If we need to pass authentication headers like cookies the Origin Source should NOT be *. Like in this case where authentication using JWT is happening.
## File Handling
To Handle files usign a Golang server, we should not store them on our disk but on some cloud storage facility like S3. We can use our code to retrieve and send them. Golang's HTTP Fileserver helps to deal with sending the files from server. It provides a Handler for this.
To deal with very large files to make the data transfer efficient, we use GZipping. Time to compress and decompress is less than time taken for the unzipped file to be transferred.