Trying to build an Ecommerce Microservice in Golang and Will try to make it Cloud Native - Learning Example extending the project of Nic Jackson


Golang Server Project Best Practices

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 product-go-micro

docker run --network host -d a3faa264fcc3

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.

  • Add JWT Tokens expiration Date

    Add JWT Tokens expiration Date

    I have created my own JWT Tokens and the payload contains an exp field. However, I have not implemented the JWT expiry mechanism. Maybe you can help to add a time check for the JWT and return an error if the current time has passed the expiration timestamp.

    enhancement help wanted good first issue hacktoberfest 
    opened by shadowshot-x 4
  • Add Logging using Zap Logger

    Add Logging using Zap Logger

    Currently, I don't send anything to the Stdout and so when an error occurs, it is impossible to detect the origination of the error. Try to implement the Logging using Uber Zap Logger where the errors are encountered or wherever necessary.

    enhancement help wanted good first issue hacktoberfest 
    opened by shadowshot-x 2
  • Order Validator Service

    Order Validator Service

    Blog Idea :-

    1. Order Validator and Enrichment Application. Data is provided to us in form of a JSON file. We will have 4 functions :- i.) One parses and stores multiple JSON files into a single struct to be processed further. It also takes into account a yaml file which defines the rules to validate the JSON. ii.) Next, based on some yaml rules (taken from a file), we validate this struct. iii.) Based on the same yaml, we perform data enrichment using text templates. iv.) This is sent forward to another backend endpoint.
    2. Understanding Mocks and Functional Testing i.) Write Unit tests for the individual functions. ii.) Show 2 ways we can mock the external http call. Normal Monkey Patching and HTTPMOCKS iii.) Write Functional Tests for the whole application (Only this wrapper code. We can extend this to master after this blog). iv.) Understand more about the domain of unit, integration and functional tests.
    3. Jenkins setup with Docker and connect to Github
    4. Code the CI/CD steps with Jenkins
    5. Continuous Deployment with Minikube, Jenkins and Github.
    6. Cloud Insights : Understanding Hosted Devops Pipelines and their power.

    Keep all the Jenkins files and everything local to a single directory. Make sure Functional tests don't break the current application.

    opened by shadowshot-x 0
  • Monitoring Module

    Monitoring Module

    Add a VERY SIMPLE module to monitor the existing microservices. Some of the main tasks for this issue :-

    1. Modify each microservice to have a function to tell the health of the application. This we can see from the Prometheus points maybe? We can get number of successful metrics and errors.
    2. Implement a new module that will run in parallel inside your main application. It will monitor each microservice application based on a JSON file provided in the config by sending a ping request to the health function after a time interval of some seconds configured in the same JSON.
    3. Module will run purely with GoRoutines, Channels and Sync package. The Module will actually be a data pipeline with a defined architecture taking care of fan-in and fan-out.
    4. The data should be written to a client every 10 seconds. The client will be coded and can have very simple stdout listener using REST API.

    Data Pipeline Steps :-

    • Init function which initiates the GoRoutines based on a JSON file. It syncs the below 3 steps for Data Pipeline.
    • Data Aggregation. Have dedicated GoRoutines to monitor application health and send the results of application in an unbuffered channel.
    • Data Transformation. Output returned by Health functions is in string format. Have multiple GoRoutines read from this 1 unbuffered channel and transform the data to a specific Output struct and Stringify this into a JSON string. Each GoRoutine posts to its own channel.
    • Data Transportation. Have another GoRoutine to aggregate the data using Fan-in mechanism copying data of multiple channels into one channel and post a REST request to the Monitoring Data Ingester.
    opened by shadowshot-x 0
  • ProductService : Adding Database Interaction for CRUD Products using GORM and MySQL

    ProductService : Adding Database Interaction for CRUD Products using GORM and MySQL

    Let's create a tutorial using Gorm with the current repository. This would lead to learning better Database interactions with Golang. We want to create a microservice for Product Interactions.

    The schema will be something like this:-

    1. ProductID
    2. ProductName
    3. ProductVendor
    4. Inventory
    5. ProductDescription
    6. CreateAt

    We will use Object Relational Mapping(ORM) following the best practices. We will try to explore GORM or Squirrel. We will try to document existing tools that deal with this problem. I have seen Mattermost using store in Golang and using this to extract the data schema.

    opened by shadowshot-x 0
  • Add check for jwt token expiry while validating

    Add check for jwt token expiry while validating

    Closes #1


    • Adds check if jwt token is expired in validation function
    • Create struct for ClaimsMap with exported fields
    • Create constants for jwt token related error messages
    • Tests for token validation function for cases - corrupt token, invalid token and expired token
    hacktoberfest hacktoberfest-accepted 
    opened by adzo261 0
  • Correction and Addition of Swagger Documentation

    Correction and Addition of Swagger Documentation

    #3 Correction and Addition of Swagger Documentation i've fixed the swagger documentation and now it's working i've generated the swagger.yaml file too from the docs provided

    hacktoberfest hacktoberfest-accepted 
    opened by manikmmalhotra 0
  • refactor(jwt): get secret from env var

    refactor(jwt): get secret from env var

    Hello! Thank you for letting me contribute to your code.

    This PR adds the functionality to get the JWT secret using an environment variable. I chose to add a function to the jwt package to centralize the variable name.

    Close #8

    hacktoberfest hacktoberfest-accepted 
    opened by vinicio 0
Ujjwal Sharma
Intern at Intuit | Getting started with Open Source | Student
Ujjwal Sharma
Customer-microservice - Microservice of customer built with golang and gRPC

?? Building microservices to manage customer data using Go and gRPC Command to g

Isaque Veras Labs 3 Sep 8, 2022
Microservice - Microservice golang & nodejs

Microservice Gabungan service dari bahasa pemograman go, nodejs Demo API ms-auth

Didin Tri Anggoro 2 May 21, 2022
Microservice - A sample architecture of a microservice in go

#microservice Folder structure required. service certs config config.yaml loggin

null 0 Feb 3, 2022
An example microservice demo using kubernetes concepts like deployment, services, persistent volume and claims, secrets and helm chart

Docker vs Kubernetes Docker Kubernetes container tech, isolated env for apps infra management, multiple containers automated builds and deploy apps -

abhijit wakchaure 0 Dec 13, 2021
TinyHat.Me: Microservices deployed with Kubernetes that enable users to propose hat pictures and try on hats from a user-curated database.

Click here to see the "buggy" version ?? The Scenario TinyHat.Me is an up and coming startup that provides an API to allow users to try on tiny hats v

Bit Project 5 Jun 17, 2022
String Service. Microservice example using gokit library

Example of Microservices using go-kit Go kit is a collection of Go (golang) packages (libraries) that help you build robust, reliable, maintainable mi

Gabriel Camps 0 Dec 6, 2021
Build simple microservice with static data

microservice-static-go So this is just example build microservice with static data, i hope this repo will help you learning golang installation 1. clo

Farhan Fatur Rozzi 2 Feb 11, 2022
Golang Caching Microservice ( test project to get hired)

bequant test project How to use: Simply type docker-compose up -d --build db warden distributor in terminal while in project's directory. MySQL, Warde

Nikita Nikonov 4 May 14, 2022
Go microservice tutorial project using Domain Driven Design and Hexagonal Architecture!

"ToDo API" Microservice Example Introduction Welcome! ?? This is an educational repository that includes a microservice written in Go. It is used as t

Mario Carrion 616 Jan 4, 2023
Cloud-native and easy-to-use application management platform | 云原生且易用的应用管理平台

Website • Documentation What is NEW! August 24, 2020 ,Rainbond 5.2 Stable version is officially released View Release Rainbond Introduction Cloud nati

好雨科技 3.7k Dec 29, 2022
Sample cloud-native application with 10 microservices showcasing Kubernetes, Istio, gRPC and OpenCensus.

Online Boutique is a cloud-native microservices demo application. Online Boutique consists of a 10-tier microservices application. The application is

Google Cloud Platform 13.5k Dec 31, 2022
CudeX: a cloud native intelligent operation and maintenance engine that provides service measurement, index quantification

简介 CudgX是星汉未来推出的面向云原生时代的AIOps智能运维引擎,它通过各类服务的多维度、大数据量的数据收集及机器学习训练分析,对各种服务进行指标化、数字

Galaxy-Future 66 Oct 13, 2022
Assignment2 - A shared project making use of microservice architecture

This project is a shared project making use of microservice architecture, API's and a simple frontend to implement a start-up new concept called EduFi. The concept combines education and financial systems to create profit from studying.

Gabriel Goh 1 Jan 26, 2022
Micro is a platform for cloud native development

Micro Overview Micro addresses the key requirements for building services in the cloud. It leverages the microservices architecture pattern and provid

Micro 11.5k Dec 29, 2022
Blue is a lightweight cloud-native gateway solution to handle millions of routing endpoints with a large number of connections.

Blue is a lightweight cloud-native gateway solution to handle millions of routing endpoints with a large number of connections.

null 456 Jan 19, 2022
Box is an incrementally adoptable tool for building scalable, cloud native, microservices.

Box is a tool for building scalable microservices from predefined templates. Box is currently in Beta so if you find any issues or have some ideas

null 1 Feb 3, 2022
Online Boutique: a cloud-native microservices demo application

This is an application forked from the GCP Microservice demo. Online Boutique is

null 0 Jan 5, 2022
A microservice gateway developed based on golang.With a variety of plug-ins which can be expanded by itself, plug and play. what's more,it can quickly help enterprises manage API services and improve the stability and security of API services.

Goku API gateway is a microservice gateway developed based on golang. It can achieve the purposes of high-performance HTTP API forwarding, multi tenant management, API access control, etc. it has a powerful custom plug-in system, which can be expanded by itself, and can quickly help enterprises manage API services and improve the stability and security of API services.

Eolink 378 Dec 29, 2022
MadeiraMadeira boilerplate project to build scalable, testable and high performance Go microservices.

MadeiraMadeira boilerplate project to build scalable, testable and high performance Go microservices.

Madeira Madeira 11 Sep 21, 2022