-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,851 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+22.3 KB
...usaurus-plugin-content-docs/current/course/proxima-book/assets/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+136 KB
...en/docusaurus-plugin-content-docs/current/course/proxima-book/assets/coffee.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions
37
i18n/en/docusaurus-plugin-content-docs/current/course/proxima-book/proxima-book.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
slug: '/course/proxima-book' | ||
title: 'Microservice Tutorial - Proxima Book' | ||
hide_title: true | ||
sidebar_position: 1 | ||
keywords: [GoFrame, GoFrame Framework, Proxima Notebook, Microservices, gRPC, etcd, Service Registry, GoFrame Microservices, Golang Microservices, Golang Tutorial, Programming Tips, Project Development, Developer Guide, Tech Stack, Software Development, Computer Science] | ||
description: 'This book uses the Proxima Notebook project as a practical example to help readers quickly master GoFrame microservices development. Perfect for developers who are familiar with GoFrame and want to advance into microservices development.' | ||
--- | ||
|
||
## Introduction | ||
--- | ||
The **Proxima Notebook** is an intermediate-level practical tutorial for GoFrame. Unlike the beginner-level tutorial [Star Notebook](https://goframe.org/course/starbook), this book focuses primarily on **microservices** development. | ||
|
||
## Motivation | ||
--- | ||
Many online tutorials overwhelm readers with technical jargon, complex architectural layers, and intimidating explanations. After spending hours reading through numerous articles, developers often find themselves unable to write a single line of code. | ||
|
||
As the saying goes, "Hearing is not as good as seeing, seeing is not as good as doing." Hands-on practice is the best way to master microservices. This book takes you on a journey from the basics of the `GoFrame` framework to building a real microservices project, demystifying the process along the way. You'll discover that developing microservices isn't as complicated as it seems. The real complexity lies not in the development itself, but in microservices governance. | ||
|
||
Our goal is to share professional, practical programming tips and experiences through a project-based approach, helping you achieve real mastery! | ||
|
||
## Target Audience | ||
--- | ||
This book is designed for developers who are already familiar with `GoFrame` and want to advance their skills in microservices development. | ||
|
||
## Contact the Author | ||
--- | ||
While writing this book, some errors or omissions are inevitable. If you have any questions or suggestions, feel free to leave a comment below or contact me directly. I'll respond as soon as possible! | ||
- Email: `[email protected]` `[email protected]` | ||
- Website: [https://oldme.net](https://oldme.net) | ||
- WeChat: `NobodyIsRight` (Please mention your purpose when adding) | ||
|
||
## Troubleshooting | ||
--- | ||
Encountering problems during development is normal. The key is knowing how to solve them. When facing issues, try to resolve them independently first. Consulting the `GoFrame` documentation and using search engines are excellent problem-solving approaches. If you still can't find a solution, feel free to contact me, and I'll do my best to help. | ||
|
||
import DocCardList from '@theme/DocCardList'; |
37 changes: 37 additions & 0 deletions
37
...docusaurus-plugin-content-docs/current/course/proxima-book/第一章-基础信息/1.1.写作约定.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: '1.1 Writing Conventions' | ||
hide_title: true | ||
slug: '/course/proxima-book/about-convention' | ||
keywords: [GoFrame, proxima-book, writing convention, code examples, command line usage, code simplification, microservices development] | ||
description: "This chapter introduces the writing conventions used in the GoFrame microservices tutorial, including code simplification principles, command line usage standards, and code omission explanations to help readers better understand the tutorial content." | ||
--- | ||
|
||
## Simplified Code Examples | ||
--- | ||
If you're reading this book, you're likely already an experienced developer. Therefore, I'll minimize unnecessary verbosity and skip non-essential code details, **focusing primarily on the microservices development process and its key features.** | ||
|
||
## Command Line Usage | ||
--- | ||
Throughout this book, I'll use the `$` symbol as a command prompt - you don't need to type this symbol. For example, if you see `$ echo "Hello, GoFrame!"`, you should only type `echo "Hello, GoFrame!"`. | ||
|
||
```bash | ||
$ echo "Hello, GoFrame!" | ||
Hello, GoFrame! | ||
``` | ||
|
||
## Code Omissions | ||
--- | ||
To keep the content concise and clean, I'll use `...` to indicate omitted code in vertical code blocks. | ||
|
||
```go | ||
package main | ||
|
||
import "fmt" | ||
|
||
... | ||
|
||
func main() { | ||
fmt.Println("Hello GoFrame") | ||
} | ||
|
||
... |
45 changes: 45 additions & 0 deletions
45
...docusaurus-plugin-content-docs/current/course/proxima-book/第一章-基础信息/1.2.架构介绍.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: '1.2 Architecture Overview' | ||
hide_title: true | ||
slug: '/course/proxima-book/about-arch' | ||
keywords: [GoFrame, microservices, architecture design, API gateway, user service, word service, gRPC, HTTP, load balancing, authentication] | ||
description: "An overview of the Proxima Notebook project's microservices architecture, including the functional separation of user and word services, and the role and responsibilities of the API gateway, detailing inter-service communication methods and core gateway functions." | ||
--- | ||
|
||
|
||
The **Proxima Notebook** is a lightweight application designed to help users learn English vocabulary. It includes the following features: | ||
- User registration | ||
- User login | ||
- User information queries | ||
- Word management (CRUD operations) | ||
|
||
We've organized these features into logical groups, resulting in two microservices: | ||
- User Service: Handles user registration, login, and information queries | ||
- Word Service: Provides word-related functionality, such as CRUD operations | ||
|
||
Rather than exposing microservices directly, all requests are routed through an API gateway. The gateway operates as a web service that doesn't implement business logic directly. Instead, it receives requests, forwards them to appropriate microservices, and aggregates responses to complete business operations. | ||
|
||
The gateway's responsibilities extend beyond protocol translation, including: | ||
- Load balancing | ||
- Authentication and authorization | ||
- Logging | ||
- Monitoring | ||
- Rate limiting | ||
|
||
Microservices typically communicate using either HTTP or gRPC protocols. In this project, we'll be using gRPC. | ||
|
||
![](../assets/architecture.png) | ||
|
||
## Code Repository | ||
--- | ||
When breaking down a monolithic service into microservices, the code naturally separates as well. There are two common approaches to managing the code repository: | ||
|
||
- **Multirepo:** Each microservice has its own repository. | ||
- Advantages: Smaller, more manageable repositories | ||
- Disadvantages: Requires additional tools and processes to coordinate dependencies and versions between services | ||
|
||
- **Monorepo:** All microservices code lives in a single repository. | ||
- Advantages: Unified version and dependency management | ||
- Disadvantages: Repository can become large and complex to manage | ||
|
||
Our project uses the `Monorepo` approach. The `Multirepo` approach, with its one-service-per-directory structure, is straightforward enough to not require further explanation. |
96 changes: 96 additions & 0 deletions
96
...docusaurus-plugin-content-docs/current/course/proxima-book/第一章-基础信息/1.3.环境准备.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--- | ||
title: '1.3 Environment Setup' | ||
hide_title: true | ||
slug: '/course/proxima-book/about-prepare' | ||
keywords: [GoFrame, gRPC, Protocol Buffers, development environment, installation guide, etcd, microservices tools, Go installation] | ||
description: "A comprehensive guide to setting up the development environment for GoFrame microservices projects, including Go language configuration, GoFrame framework installation, gRPC toolchain setup, and installation instructions for related dependencies." | ||
--- | ||
|
||
Don't worry if your versions differ from mine - the principles remain largely the same. | ||
|
||
## GoFrame | ||
--- | ||
We'll skip the basic installation of `Golang` and `GoFrame`. Here are the versions used in this tutorial: | ||
- `go version go1.23.4 windows/amd64` | ||
- `goframe v2.8.2` | ||
|
||
## gRPC | ||
--- | ||
`gRPC` is a Remote Procedure Call (RPC) framework developed by Google, built on top of HTTP/2. It uses Protocol Buffers as its default serialization format. | ||
|
||
Go provides gRPC functionality through the `gRPC-go` plugin. Install it using these commands: | ||
```bash | ||
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | ||
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | ||
``` | ||
|
||
### gRPC Testing Tools | ||
After developing gRPC interfaces, you'll need testing tools to verify their functionality. Popular options include `Postman`, `Apifox`, and `Apipost`. They're all similar - choose the one you prefer. | ||
|
||
Throughout this book, we'll display test results in `json` format, like this: | ||
```json | ||
grpc 127.0.0.1:32001.account.v1.Account.UserRegister | ||
{ | ||
"username": "oldme", | ||
"password": "123456", | ||
"email": "[email protected]" | ||
} | ||
{ | ||
"id": 1 | ||
} | ||
``` | ||
|
||
These represent the request address, request parameters, and response parameters, respectively. | ||
|
||
## Protocol Buffers | ||
--- | ||
Protocol Buffers is Google's data serialization format for structured data. It uses `.proto` files to define message structures, which are then compiled into language-specific code. | ||
|
||
Download the appropriate version for your operating system from [Protocol Buffers Releases](https://github.com/protocolbuffers/protobuf/releases). For MacOS users, you can install dependencies using `brew`: | ||
|
||
```bash | ||
$ brew install grpc protoc-gen-go protoc-gen-go-grpc | ||
``` | ||
|
||
Verify the installation: | ||
```bash | ||
$ protoc --version | ||
libprotoc 26.1 | ||
``` | ||
|
||
## etcd | ||
--- | ||
etcd is a distributed key-value store commonly used for service discovery in distributed systems. There are several ways to install it. Here's a reference `docker-compose.yaml` file: | ||
|
||
```yaml | ||
version: "3.7" | ||
|
||
services: | ||
etcd: | ||
image: "bitnami/etcd:3.5" | ||
container_name: "etcd" | ||
restart: "always" | ||
ports: | ||
- 2379:2379 | ||
environment: | ||
- TZ=Asia/Shanghai | ||
- ALLOW_NONE_AUTHENTICATION=yes | ||
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379 | ||
``` | ||
If installed successfully, visiting [http://IP:2379/version](http://IP:2379/version) in your browser should display: | ||
```json | ||
{"etcdserver": "3.5.17","etcdcluster": "3.5.0"} | ||
``` | ||
|
||
For a more advanced setup, like installing an etcd cluster or learning etcd basics, check out [this article](https://oldme.net/article/32). | ||
|
||
## Database | ||
--- | ||
MySQL installation is straightforward, and you can use other databases if preferred. | ||
|
||
Important: In a microservices architecture, each service should have its own database. We'll need to create two databases named `user` and `word`: | ||
|
||
```sql | ||
CREATE DATABASE user; | ||
CREATE DATABASE word; |
70 changes: 70 additions & 0 deletions
70
...ocusaurus-plugin-content-docs/current/course/proxima-book/第一章-基础信息/1.4.项目初始化.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: '1.4 Project Initialization' | ||
hide_title: true | ||
slug: '/course/proxima-book/about-init' | ||
keywords: [GoFrame, project initialization, Monorepo, project structure, dependency management, go.mod, microservices setup] | ||
description: "A detailed guide on initializing a microservices project using the GoFrame CLI tool, including creating a Monorepo repository, configuring dependencies, and setting up the project structure." | ||
--- | ||
|
||
## Repository Initialization | ||
--- | ||
Use the following command to initialize a Monorepo repository named `proxima`: | ||
|
||
```bash | ||
$ gf init proxima -m | ||
``` | ||
|
||
Update the minimum Go version in your environment to be compatible with GoFrame's requirements. | ||
|
||
*go.mod* | ||
```text | ||
module proxima | ||
go 1.23.4 | ||
``` | ||
|
||
Upgrade GoFrame to the latest version: | ||
```bash | ||
$ cd proxima | ||
gf up | ||
``` | ||
|
||
Remove unnecessary example files: | ||
```bash | ||
$ rm -rf app/* | ||
``` | ||
|
||
The resulting project structure will look like this: | ||
```text | ||
app | ||
hack | ||
hack.mk | ||
hack-cli.mk | ||
utility | ||
go.mod | ||
go.sum | ||
``` | ||
|
||
In Monorepo mode, the root directory only manages project dependencies and doesn't contain a `main.go` file. | ||
|
||
The `app` directory stores code for each microservice, such as `app/user/main.go` and `app/word/main.go`. | ||
|
||
## Installing Microservice Components | ||
--- | ||
Install the `grpcx` component to enable microservice development with GoFrame: | ||
```bash | ||
$ go get -u github.com/gogf/gf/contrib/rpc/grpcx/v2 | ||
``` | ||
|
||
## Installing Database Drivers | ||
--- | ||
Like monolithic applications, you'll need to install the appropriate database driver. Here we'll demonstrate using MySQL: | ||
```bash | ||
$ go get -u github.com/gogf/gf/contrib/drivers/mysql/v2 | ||
``` | ||
|
||
## Installing etcd Components | ||
--- | ||
Install the `etcd` component for service registration: | ||
```bash | ||
$ go get -u github.com/gogf/gf/contrib/registry/etcd/v2 |
33 changes: 33 additions & 0 deletions
33
...docusaurus-plugin-content-docs/current/course/proxima-book/第一章-基础信息/1.5.本书源码.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: '1.5 Source Code' | ||
hide_title: true | ||
slug: '/course/proxima-book/about-source' | ||
keywords: [GoFrame, source code, GitHub repository, MIT license, open source, proxima project] | ||
description: "Access the tutorial project's source code, including the GitHub repository link and detailed information about the MIT open source license." | ||
--- | ||
|
||
The source code for this book is available on [https://github.com/oldme-git/proxima](https://github.com/oldme-git/proxima). | ||
|
||
The project is licensed under the `MIT` License: | ||
```text | ||
MIT License | ||
Copyright (c) 2024 oldme | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
10 changes: 10 additions & 0 deletions
10
...docusaurus-plugin-content-docs/current/course/proxima-book/第一章-基础信息/第一章-基础信息.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: 'Chapter 1 - Basic Information' | ||
hide_title: true | ||
sidebar_position: 1 | ||
slug: '/course/proxima-book/about' | ||
--- | ||
|
||
import DocCardList from '@theme/DocCardList'; | ||
|
||
<DocCardList /> |
Oops, something went wrong.