Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Dec 16, 2024
1 parent 01e94bc commit ebd3da3
Show file tree
Hide file tree
Showing 29 changed files with 137 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '1.1.写作约定'
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: "本章介绍了 GoFrame 微服务教程的写作约定,包括代码示例的简化原则、命令行使用规范和代码省略说明,帮助读者更好地理解教程内容。"
---

## 代码从简
Expand Down Expand Up @@ -33,4 +35,3 @@ func main() {
}

...
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '1.2.架构介绍'
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: "介绍比邻英语本项目的微服务架构设计,包括用户服务和单词服务的功能拆分,以及API网关的角色和功能,详细说明了微服务间的通信方式和网关的核心职责。"
---


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '1.3.环境准备'
hide_title: true
slug: '/course/proxima-book/about-prepare'
keywords: [GoFrame, gRPC, Protocol Buffers, development environment, installation guide, etcd, microservices tools, Go installation]
description: "详细介绍了开发 GoFrame 微服务项目所需的环境准备工作,包括 Go 语言环境配置、GoFrame 框架安装、gRPC 工具链配置以及相关依赖组件的安装说明。"
---

如果您的版本和我不一致,也无需担心,他们基本是共通的。
Expand Down Expand Up @@ -29,12 +31,12 @@ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
```json
grpc 127.0.0.1:32001.account.v1.Account.UserRegister
{
    "username": "oldme",
    "password": "123456",
    "email": "[email protected]"
  "username": "oldme",
  "password": "123456",
  "email": "[email protected]"
}
{
    "id": 1
  "id": 1
}
```

Expand Down Expand Up @@ -92,5 +94,4 @@ services:

```sql
CREATE DATABASE user;
CREATE DATABASE word;
```
CREATE DATABASE word;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '1.4.项目初始化'
hide_title: true
slug: '/course/proxima-book/about-init'
keywords: [GoFrame, project initialization, Monorepo, project structure, dependency management, go.mod, microservices setup]
description: "详细说明了如何使用 GoFrame CLI 工具初始化微服务项目,包括创建 Monorepo 仓库、配置依赖版本、设置项目结构等关键步骤。"
---

## 初始化仓库
Expand Down Expand Up @@ -36,8 +38,8 @@ $ rm -rf app/*
```text
app
hack
hack.mk
hack-cli.mk
hack.mk
hack-cli.mk
utility
go.mod
go.sum
Expand Down Expand Up @@ -66,4 +68,3 @@ $ go get -u github.com/gogf/gf/contrib/drivers/mysql/v2
安装`etcd`组件,提供服务注册功能。
```bash
$ go get -u github.com/gogf/gf/contrib/registry/etcd/v2
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '1.5.本书源码'
hide_title: true
slug: '/course/proxima-book/about-source'
keywords: [GoFrame, source code, GitHub repository, MIT license, open source, proxima project]
description: "提供了本教程项目的源代码获取方式,包括 GitHub 仓库地址和 MIT 开源许可证的详细说明。"
---

本书的源码开源在 [https://github.com/oldme-git/proxima](https://github.com/oldme-git/proxima)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '3.1.前置准备'
hide_title: true
slug: '/course/proxima-book/word-prepare'
keywords: [GoFrame, word service setup, microservice initialization, database configuration, project structure, service preparation]
description: "详细介绍了单词服务的初始化过程,包括使用 GoFrame CLI 创建服务、配置数据库连接、设置项目结构等基础准备工作。"
---

搞定了第一个微服务后,第二个微服务开发起来自然轻车熟路。
Expand Down Expand Up @@ -83,4 +85,3 @@ gfcli:
$ gf gen pbentity
generated: D:\project\proxima\app\word\manifest\protobuf\pbentity\words.proto
done!
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: 3.2.业务逻辑
hide_title: true
slug: /course/proxima-book/word-logic
keywords: [GoFrame, business logic, word management, CRUD operations, microservices logic, vocabulary service]
description: "介绍了单词服务的核心业务逻辑实现,包括单词的创建、查询等基本功能的代码实现。"
---

和前文一样,这里简单做个样子
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
title: '3.3.协议文件'
hide_title: true
slug: '/course/proxima-book/word-protocol'
keywords: [GoFrame, Protocol Buffers, gRPC, API definition, word service protocol, microservices communication]
description: "介绍了单词服务的 Protocol Buffers 协议文件定义,包括创建和获取单词等接口的协议设计和实现。"
---

这里我就从简了,省略了更新,删除等操作,只写了`Create``Get`,用作示例。

*app/word/manifest/protobuf/words/v1/words.proto*
```proto
```go
syntax = "proto3";

package words.v1;
Expand Down Expand Up @@ -37,5 +39,4 @@ message GetReq {

message GetRes {
pbentity.Words words = 1;
}
```
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: "3.4.控制器"
hide_title: true
slug: '/course/proxima-book/word-controller'
keywords: [GoFrame, controller generation, gRPC controller, word service controller, protobuf generation, service implementation]
description: "详细介绍了如何生成和实现单词服务的控制器,包括使用 GoFrame 的代码生成工具和实现具体的业务逻辑。"
---

执行命令,生成控制器:
Expand Down
49 changes: 25 additions & 24 deletions docs/course/proxima-book/第三章-单词服务/3.5.启动运行.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '3.5.启动运行'
hide_title: true
slug: '/course/proxima-book/word-run'
keywords: [GoFrame, gRPC service, word service startup, microservices deployment, service registration, etcd integration]
description: "详细说明了如何启动和运行单词微服务,包括配置服务注册、gRPC 服务设置和健康检查等关键步骤。"
---

## cmd引入控制器
Expand Down Expand Up @@ -49,7 +51,7 @@ var (
package main

import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"

"github.com/gogf/gf/v2/os/gctx"

Expand Down Expand Up @@ -97,35 +99,34 @@ build running pid: 2416
```json
grpc 127.0.0.1:32002.words.v1.Words.Create
{
    "uid": 1,
    "word": "hello",
    "definition": "used as a greeting when you meet somebody."
  "uid": 1,
  "word": "hello",
  "definition": "used as a greeting when you meet somebody."
}
{
    "id": 1
  "id": 1
}

grpc 127.0.0.1:32002.words.v1.Words.Get
{
    "id": 1
  "id": 1
}
{
    "words": {
        "Id": 1,
        "Uid": 1,
        "Word": "hello",
        "Definition": "used as a greeting when you meet somebody.",
        "ExampleSentence": "Hello, I am oldme!",
        "ChineseTranslation": "你好",
        "Pronunciation": "həˈləʊ",
        "CreatedAt": {
            "seconds": "1733407200",
            "nanos": 0
        },
        "UpdatedAt": {
            "seconds": "1733407200",
            "nanos": 0
        }
    }
  "words": {
  "Id": 1,
  "Uid": 1,
  "Word": "hello",
  "Definition": "used as a greeting when you meet somebody.",
  "ExampleSentence": "Hello, I am oldme!",
  "ChineseTranslation": "你好",
  "Pronunciation": "həˈləʊ",
  "CreatedAt": {
  "seconds": "1733407200",
  "nanos": 0
  },
  "UpdatedAt": {
  "seconds": "1733407200",
  "nanos": 0
  }
  }
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '3.6.服务注册'
hide_title: true
slug: '/course/proxima-book/word-etcd-register'
keywords: [GoFrame, etcd, service registration, word service discovery, microservices registry, configuration]
description: "介绍了如何将单词微服务注册到 etcd 服务注册中心,包括配置文件设置和注册逻辑的实现。"
---

添加配置文件:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: '第三章-单词服务'
hide_title: true
sidebar_position: 3
slug: '/course/proxima-book/word'
keywords: [GoFrame, word service, vocabulary management, microservices, CRUD operations, English learning]
description: "本章详细介绍了基于 GoFrame 框架的单词服务实现,包括单词的增删改查等核心功能,以及与其他微服务的集成。"
---

import DocCardList from '@theme/DocCardList';

<DocCardList />
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '2.1.前置准备'
hide_title: true
slug: '/course/proxima-book/user-overview'
keywords: [GoFrame, microservice setup, user service initialization, database configuration, project structure, service preparation]
description: "本节介绍了用户服务的前置准备工作,包括使用 GoFrame CLI 初始化服务、配置数据库连接、设置项目结构等基础内容。"
---

微服务开发的大部分内容,都和单体服务一致,甚至比单体服务简单许多。本章是一些基础准备,想必各位都驾轻就熟。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '2.2.业务逻辑'
hide_title: true
slug: '/course/proxima-book/user-logic'
keywords: [GoFrame, business logic, user registration, account management, microservices logic, user service implementation]
description: "详细说明了用户服务中的业务逻辑实现,包括用户注册等核心功能的代码实现和最佳实践。"
---

微服务的业务逻辑存放在`*/internal/logic`下,和单体业务一样。大家都是久经沙场的老将了,作者也不献丑,就简单做个样子。
Expand Down Expand Up @@ -36,5 +38,4 @@ func Info(ctx context.Context, token string) (user *entity.Users, err error) {
CreatedAt: gtime.New("2024-12-05 22:00:00"),
UpdatedAt: gtime.New("2024-12-05 22:00:00"),
}, nil
}
```
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '2.3.协议文件'
hide_title: true
slug: '/course/proxima-book/user-protocol'
keywords: [GoFrame, Protocol Buffers, gRPC, API definition, microservices communication, proto files, user service protocol]
description: "介绍了用户服务中的 Protocol Buffers 协议文件定义,包括用户注册、登录等接口的协议设计,以及 gRPC 服务定义的最佳实践。"
---

协议文件指的是`*.proto`文件,`proto``gRPC`协议通讯的标准,可以类比为`json``HTTP`。但是千万不要理解`proto`就是`json`,他们还是有一定区别的:`proto`同时定义“接口”信息和响应参数,请求参数,而`json`就单纯的保存数据。
Expand Down Expand Up @@ -48,11 +50,11 @@ message UserRegisterRes {
- 设置了`Go`代码生成的包路径选项`go_package``proxima/app/user/api/account/v1`
- 定义了一个`Account`服务,包含一个`RPC`方法`UserRegister`,它接受`UserRegisterReq`消息并返回`UserRegisterRes`消息;
- 定义了一个消息类型`UserRegisterReq`,包含三个字段:
- `username` (string类型,编号为1)
- `password` (string类型,编号为2)
- `email` (string类型,编号为3)
- `username` (字符串类型,编号为1)
- `password` (字符串类型,编号为2)
- `email` (字符串类型,编号为3)
- 定义了一个消息类型`UserRegisterRes`,包含一个字段:
- `id` (int32类型,编号为1)
- `id` (整型,编号为1)

## 用户登录/查询
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: "2.4.控制器"
hide_title: true
slug: '/course/proxima-book/user-controller'
keywords: [GoFrame, controller generation, gRPC controller, protobuf generation, microservices controller, service implementation]
description: "详细介绍了如何使用 GoFrame 的代码生成工具生成 gRPC 控制器,以及如何实现用户服务的各项功能接口。"
---

`HTTP`服务的控制器由`gf gen ctrl`生成,微服务也有控制器,由`gf gen pb`生成。
Expand Down Expand Up @@ -70,4 +72,3 @@ func (*Controller) UserInfo(ctx context.Context, req *v1.UserInfoReq) (res *v1.U
},
}, nil
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: '2.5.启动运行'
hide_title: true
slug: '/course/proxima-book/user-run'
keywords: [GoFrame, gRPC service, service startup, microservices deployment, service registration, etcd integration]
description: "详细说明了如何启动和运行用户微服务,包括服务注册、gRPC 服务配置、与 etcd 的集成以及服务健康检查等关键步骤。"
---

## cmd引入控制器
Expand Down Expand Up @@ -149,4 +151,3 @@ grpc 127.0.0.1:32001.account.v1.Account.UserInfo
        }
    }
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: 2.6.服务注册
hide_title: true
slug: /course/proxima-book/user-etcd-register
keywords: [GoFrame, etcd, service registration, service discovery, microservices registry, configuration management]
description: "介绍了如何将用户微服务注册到 etcd 服务注册中心,包括配置文件设置、注册逻辑实现以及服务发现机制的配置。"
---

接下来,我们将用户微服务注册到`etcd`,供其他服务调用。
Expand All @@ -21,14 +23,14 @@ etcd:
package main

import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
"github.com/gogf/gf/contrib/registry/etcd/v2"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"proxima/app/user/internal/cmd"
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
"github.com/gogf/gf/contrib/registry/etcd/v2"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"proxima/app/user/internal/cmd"
)

func main() {
Expand Down
Loading

0 comments on commit ebd3da3

Please sign in to comment.