Pattern Repository Golang

Tram Ho

Models in web projects

3-layer model

  • The User Interface is a part of the user interface such as web browser, winform, etc. This is where the user sends RESTful requests to the system.
  • The Controller Layer, similar to the one above, is an entry point of the service, which receives request packets and responses about the User Interface. The layer is responsible for routing logic, parameter checking, forwarding requests, etc.
  • Business Logic Layer is the main business layer of the system. When receiving requests from Controller layer, depending on the type of request will have different handling and calculation. Requirements that require data or change data will be pushed down by this layer into the Data Access Layer.
  • Data Access Layer is the only layer that can query the database of the service, the layer performs data related operations such as (select, insert, update, delete, …)
  • Benefit:
    • Easy system development and maintenance.
    • Reduced dependency between classes as the system grows, reusable, saving construction time.

Repository Pattern

Design Pattern

  • As a technique in object-oriented programming, providing us with:
    • Design patterns, ways of thinking in the situations of object-oriented programming.
    • Optimal solutions to common problems encountered in programming as well as in the analysis of software design and development.

Repository

  • The middle layer between the Business Logic and Data Access layer, which makes data access tighter and more secure.
  • Serves as a connection layer between the Business layer and the Model of the application.
  • Reasons to use repository pattern :
    • The only place to change data access as well as data processing.
    • Increase the security and clarity of the code.
    • Easy to replace.

Go-kit

  • Go-kit is divided into three main layers:
    • Transport layer
    • Endpoint layer
    • Service layer
  • The service layer is where the application domains are located as well as all the application logic.
  • The transport layer is linked to specific protocols such as Http, gRPC, Pub / Sub to retrieve requests from clients and encoding / decoding requests.
  • In go-kit, each service method in go-kit will be converted into an endpoint to communicate between client and server. Each endpoint expose a service method out using the transport associated with a specific protocol such as http, rest / gRPC or pub / sub.
Share the news now

Source : Viblo