![FreeCar](img/FreeCar.png) [English](README.md) | ä¸æ FreeCar æ¯ä¸ä¸ªåºäº [Hertz](https://github.com/cloudwego/hertz) ä¸ [Kitex](https://github.com/cloudwego/kitex) çäºåçåæ¶æ±½è½¦ç§èµç³»ç»å¥ä»¶ã ## 项ç®æ¶æ ### è°ç¨å ³ç³» ![call_relations.png](img/call_relation.png) ### ææ¯æ¶æ ![tech_arch](img/tech_arch.png) ### æå¡å ³ç³» ![service_relations.png](img/service_relations.png) ## ææ¯æ | åè½ | å®ç° | |---------|---------------------| | HTTP æ¡æ¶ | Hertz | | RPC æ¡æ¶ | Kitex | | æ°æ®åº | MongoDBãMySQLãRedis | | 身份é´æ | Paseto | | æå¡ä¸é ç½®ä¸å¿ | Consul | | æ¶æ¯éå | RabbitMQ | | æå¡æ²»ç | OpenTelemetry | | ææ çæ§ | Prometheus | | é¾è·¯è¿½è¸ª | Jaeger | | éæµçæ | Sentinel | | 对象åå¨ | MinIO | | å¾åè¯å« | ç¾åº¦ OCR | | CI | GitHub Actions | ## 页é¢å±ç¤º ### å°ç¨åºç«¯ å°ç¨åºç«¯å°å [FreeCar-MP](https://github.com/CyanAsterisk/FreeCar-MP) ![display.png](img/display.png) ### åå°ç®¡çç³»ç» åå°ç®¡çç³»ç»å°å [FreeCar-Admin](https://github.com/CyanAsterisk/FreeCar-Admin) ![data-analize.png](img/data-analize.png) ![back.png](img/back.png) ## ç®å½ä»ç» | ç®å½ | ä»ç» | |--------|----------------| | Cmd | 项ç®æ ¸å¿é¨å | | Idl | 项ç®æææå¡ç IDL æ件 | | Shared | å¯å¤ç¨ä»£ç | ## æå¡ä»ç» | ç®å½ | ä»ç» | |---------|----------------------| | API | åºäº Hertz çç½å ³æå¡ | | User | ç¨æ·è®¤è¯æå¡ | | Blob | ä¸å¾çå MinIO 对象åå¨ç¸å ³çæå¡ | | Car | 汽车æå¡ | | Profile | 主页ä¸å¾çè¯å«æå¡ | | Trip | è¡ç¨æå¡ | ## å¿«éå¼å§ ### å¯å¨åºç¡ç¯å¢ ```shell make start ``` ### é ç½® Consul > é»è®¤ Consul å°åä¸ KV é ç½®ç请åèå个 `config.yaml` é ç½®æ件ã ![consul_service.png](img/consul_service.png) ![consul_kv.png](img/consul_kv.png) å ³äº KV é®å¼å¯¹ç详ç»é ç½®ï¼[详è§](docs/CONSUL_CONFIG.md)ã ### å¯å¨ HTTP æå¡ ```shell make api ``` ### å¯å¨ RPC æå¡ ```shell make user make blob make car make profile make trip ``` ### Jaeger > å¨æµè§å¨ä¸è®¿é® `http://127.0.0.1:16686/` ![jaeger.jpg](img/jaeger.png) ![jaeger2.png](img/jaeger2.png) ### Prometheus > å¨æµè§å¨ä¸è®¿é® `http://127.0.0.1:3000/` ![prometheus.jpg](img/prometheus.png) ### MinIO > å¨æµè§å¨ä¸è®¿é® `http://127.0.0.1:9000/` ![minio.jpg](img/minio.png) ## K8s é¨ç½² ```shell cd deployment/freecar-k8s make all ``` ### Pod ![pod.png](img/pod.png) ### PVC ![pvc.png](img/pvc.png) ### Service ![service.png](img/service.png) ## å¼åæå éè¿ç´æ¥é 读æºç æ¥äºè§£æ¤é¡¹ç®æ¯é常å°é¾çï¼å¨æ¤æä¾å¼åæåæ¹ä¾¿å¼åè å¿«éäºè§£å¹¶ä¸ææ¤é¡¹ç®å æ¬ KitexãHertz çæ¡æ¶ã ### åç½®åå¤ éè¿å¿«éå¼å§ä¸çå½ä»¤å¿«éå¯å¨æéçå·¥å ·ä¸ç¯å¢ï¼è¥éè¦ç¹æ®å®å¶è¯·ä¿®æ¹ `docker-compose.yaml` ä¸ Nacos é ç½®ä¸çå 容ã ### IDL å¨å¼åä¹åæ们éè¦å®ä¹å¥½ IDL æ件ï¼å ¶ä¸ hz 为å¼åè æä¾äºè®¸å¤å®å¶åç [api 注解](https://www.cloudwego.io/zh/docs/hertz/tutorials/toolkit/usage/annotation/#%E6%94%AF%E6%8C%81%E7%9A%84-api-%E6%B3%A8%E8%A7%A3)ã 示ä¾ä»£ç ï¼ ```thrift namespace go user struct LoginRequest { 1: string code } struct LoginResponse { 1: i64 accountID } service UserService { LoginResponse Login(1: LoginRequest req) } ``` ### 代ç çæ #### Kitex é¦å å¨ `shared` æ件夹ä¸çæ `kitex_gen`ï¼åå¨ç¸å¯¹åºæå¡æ件夹ä¸ä¾èµ `kitex_gen` è¿è¡çæãå¨æ°å¢æå¡ç®å½ä¸æ§è¡ï¼æ¯æ¬¡ä» éæ´æ¹æå¡åä¸ IDL è·¯å¾ã ```shell kitex -module github.com/CyanAsterisk/FreeCar ./../idl/rpc/user.thrift kitex -service user -module github.com/CyanAsterisk/FreeCar -use github.com/CyanAsterisk/FreeCar/server/shared/kitex_gen ./../../idl/rpc/user.thrift ``` 注æé¡¹ï¼ - ç¨ `-module github.com/CyanAsterisk/FreeCar` 该åæ°ç¨äºæå®çæ代ç æå±ç Go 模åï¼é¿å è·¯å¾é®é¢ã - å½åæå¡éè¦è°ç¨å ¶ä»æå¡æ¶éä¾èµ `kitex_gen`ã #### Hertz ##### åå§å ```shell hz new -idl ./../../idl/api.proto -mod github.com/CyanAsterisk/FreeCar/server/cmd/api ``` 注æé¡¹ï¼ - ç¨ `-module github.com/CyanAsterisk/FreeCar/server/cmd/api` 该åæ°ç¨äºæå®çæ代ç æå±ç Go 模åï¼é¿å è·¯å¾é®é¢ã ### ä¸å¡å¼å å¨ä»£ç çæå®æ¯åéè¦å å°ä¸äºå¿ é¡»ç»ä»¶æ·»å å°é¡¹ç®ä¸ãç±äº api å±ä¸å¿ å次添å ï¼å æ¤ä»¥ä¸ä¸»è¦è®²è§£å ³äº Kitex-Server é¨åï¼ä»£ç ä½äº `server/cmd` ä¸ã #### Config åè `server/cmd/user/config`ï¼ä¸ºå¾®æå¡çé ç½®ç»æä½ã #### Initialize åè `server/cmd/user/initialize`ï¼æä¾å¿ è¦ç»ä»¶çåå§ååè½ï¼å ¶ä¸ `config.go` `registry.go` `flag.go` `logger.go` ä¸ºå¿ é¡»é¡¹ã #### Pkg åè `server/cmd/user/pkg`ï¼æä¾å¾®æå¡çè°ç¨å½æ°ï¼ä¸»è¦ç¨äºå®ç° `handler.go` ä¸å®ä¹çæ¥å£ã #### API å¨åç½å ³å±çä¸å¡é»è¾æ¶ï¼ä» éè¦æ¯æ¬¡æ´æ° IDL ä¸æ°çå¾®æå¡å®¢æ·ç«¯ä»£ç ï¼è¥éè¦æ·»å æ°çç»ä»¶ç´æ¥æ·»å å³å¯ï¼é¡¹ç®é«åº¦å¯ææï¼æ¶æä¸å¾®æå¡å±ç¸ä¼¼ã ç½å ³å±çä¸å¡é»è¾å¨ `server/cmd/api/biz` ä¸ï¼å¤§é¨å代ç ä¼èªå¨çæãè¥éè¦åç¬æ°å¢è·¯ç±éè¦å° `server/cmd/api/router.go` ä¸ã å ³äºä¸é´ä»¶ç使ç¨ï¼åªéè¦å¨ `server/cmd/api/biz/router/api/middleware.go` ä¸æ·»å ä¸é´ä»¶é»è¾ã ## 许å¯è¯ FreeCar å¨ GNU General Public 许å¯è¯ 3.0 çä¸å¼æºã