Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 4184

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T09:38:09+00:00 2024-11-26T09:38:09+00:00

Go microservice project based multiple technology stacks | Recommended open source projects

  • 61k

FreeCar

FreeCar is a full-stack microservice project based on Hertz and Kitex, welcome Star.

Project address: CyanAsterisk/FreeCar

Hertz

Hertz is an ultra-large-scale enterprise-level microservice HTTP framework, featuring high ease of use, easy expansion, and low latency etc.

Hertz uses the self-developed high-performance network library Netpoll by default. In some special scenarios, Hertz has certain advantages in QPS and latency compared to go net.

In internal practice, some typical services, such as services with a high proportion of frameworks, gateways and other services, after migrating Hertz, compared to the Gin framework, the resource usage is significantly reduced, CPU usage is reduced by 30%-60% with the size of the traffic.

For more details, see cloudwego/hertz.

technology stack

Function Implementation
HTTP Framework Hertz
RPC Framework Kitex
Database MongoDB, MySQL
Configuration Center Nacos
Service Discovery Center Nacos
Message Queue RabbitMQ
Link Tracking Jaeger
Cluster Monitoring Prometheus
Current limiting middleware hertz-contrib/limiter
Deployment docker-compose
Object Storage Tencent Cloud COS
CI GitHub Actions

Project Architecture

Call relationship

Image description

Technology Architecture

Image description

Service Relationship

Image description

Display

image.png

Directory Introduction

Catalog Introduction
Server Core part of the project
Shared Reusable Code
Static WeChat applet code

Service Introduce

Catalog Introduce
API Hertz-based Gateway Service
Auth User Authentication Service
Blob Services Related to Pictures and Tencent Cloud COS
Car Car Service
Profile Profile and Picture Recognition Services
Trip Trip Service

Quick Start

Start dependence

make start 
Enter fullscreen mode Exit fullscreen mode

Configure Nacos

Access http://127.0.0.1:8848/nacos/index.html#/login on the browser to log in.

For the default namespace and configuration groups, please refer to each config.yaml configuration file.

Image description

Image description

For detailed configuration of the configuration center, see.

Generate data table

make migrate 
Enter fullscreen mode Exit fullscreen mode

Start HTTP service

make api 
Enter fullscreen mode Exit fullscreen mode

Start the microservice

make auth make blobs make a car make profile make a trip 
Enter fullscreen mode Exit fullscreen mode

Jaeger

Visit http://127.0.0.1:16686/ on your browser

Image description

Prometheus

Visit http://127.0.0.1:3000/ on your browser

Image description

API requests

The project's API request example see details.

Development Guide

It is very difficult to understand this project by directly reading the source code. Here is a development guide for developers to quickly understand and get started with this project, including frameworks such as Kitex and Hertz.

Preparation

Use the commands in the quick start to quickly start the required tools and environment. If you need special customization, please modify the contents of docker-compose.yaml and Nacos configuration.

IDL

Before development, we need to define the IDL file, where hz
Provides developers with many customized api annotations.

Sample code:

namespace go auth  struct LoginRequest {      1: string code }  struct LoginResponse {      1: i64 accountID }  service AuthService {      LoginResponse Login(1: LoginRequest req) } 
Enter fullscreen mode Exit fullscreen mode

Code Generation

Kitex

Execute under the new service directory, only need to change the service name and IDL path each time.

Server
kitex -service auth -module github.com/CyanAsterisk/FreeCar ./../../idl/auth.thrift 
Enter fullscreen mode Exit fullscreen mode

client
kitex -module github.com/CyanAsterisk/FreeCar ./../../idl/auth.thrift 
Enter fullscreen mode Exit fullscreen mode

Note:

  • Use -module github.com/CyanAsterisk/FreeCar This parameter is used to specify the Go module to which the generated code belongs to avoid path problems.
  • When the current service needs to call other services, a client file needs to be generated.

Hertz

Initialization
hz new -idl ./../../idl/api.proto -mod github.com/CyanAsterisk/FreeCar/server/cmd/api 
Enter fullscreen mode Exit fullscreen mode

renew
hz update -I -idl ./../../idl/api.proto 
Enter fullscreen mode Exit fullscreen mode

Note:

  • Use -module github.com/CyanAsterisk/FreeCar/server/cmd/api This parameter is used to specify the Go module to which the generated code belongs to avoid path problems.

Business Development

After the code is generated, some necessary components need to be added to the project. Since the api layer does not need to be added again, the following mainly explains about Kitex-Server
section, the code is located under server/cmd.

Config

Refer to server/cmd/auth/config for the configuration structure of microservices.

Global

Refer to server/cmd/auth/global to provide globally callable methods for microservices.

Initialize

Refer to server/cmd/auth/initialize to provide the initialization function of the necessary components, among which nacos.go flag.go logger.go are required.

Tool

Refer to server/cmd/auth/tool to provide tool functions for microservices, where port.go is required.

API

When writing the business logic of the gateway layer, you only need to update the IDL and the new microservice client code each time. If you need to add new components, you can add them directly. The project is highly pluggable, and the architecture is similar to the microservice layer.

The business logic of the gateway layer is under server/cmd/api/biz, and most of the code will be automatically generated. If you need to add a new route separately, you need to go to server/cmd/api/router.go.

Regarding the use of middleware, you only need to add middleware logic in server/cmd/api/biz/router/api/middleware.go.

License

FreeCar is open source under the GNU General Public License version 3.0.

Summarize

This project still takes a lot of time, everyone is welcome to learn, if Star is our greatest encouragement!

Reference

  • CyanAsterisk/FreeCar
  • cloudwego/hertz
  • cloudwego/kitex

beginnersgoprogrammingwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.