Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into improve/star
Browse files Browse the repository at this point in the history
  • Loading branch information
oldme-git committed Jan 8, 2025
2 parents dcb94ca + 6feaf2b commit 5830371
Show file tree
Hide file tree
Showing 37 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
slug: '/docs/install-go'
title: '准备工作'
title: '准备开发环境'
sidebar_position: 0
hide_title: true
keywords: [GoFrame,GoFrame框架,安装GoFrame,GoFrame快速开始,GoFrame教程,GoFrame文档,开发环境配置,安装指南,Go语言,GoFrame开发]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ $ main http my-http-server -p 8199
| `root` | - | 指定子级命令名称是父级命令,其他方法是它的子级命令 | 仅用于 **主命令** 对象结构体 `Meta` 标签 |
| `strict` | - | 表示该命令严格解析参数/选项,当输入不支持的参数/选项时,返回错误 | 仅用于对象结构体 `Meta` 标签 |
| `config` | - | 表示该命令的选项数据支持从指定的配置读取,配置来源于默认的全局单例配置对象 | 仅用于方法输入结构体 `Meta` 标签 |
| `default` | `d` | 表示该输入参数不传递时使用默认值 | 仅用于属性标签 |

## 高级特性

Expand All @@ -236,4 +237,4 @@ $ main http my-http-server -p 8199

### 从配置读取数据

当命令行中没有传递对应的数据时,输入参数的结构体数据支持从配置组件中自动获取,只需要在 `Meta` 中设置 `config` 标签即可,配置来源于默认的全局单例配置对象。具体示例可以参考 `GoFrame` 框架开发工具源码: [https://github.com/gogf/gf/tree/master/cmd/gf](https://github.com/gogf/gf/tree/master/cmd/gf)
当命令行中没有传递对应的数据时,输入参数的结构体数据支持从配置组件中自动获取,只需要在 `Meta` 中设置 `config` 标签即可,配置来源于默认的全局单例配置对象。具体示例可以参考 `GoFrame` 框架开发工具源码: [https://github.com/gogf/gf/tree/master/cmd/gf](https://github.com/gogf/gf/tree/master/cmd/gf)
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ database:
:::note
使用该配置方式时, **为保证数据库安全,默认底层不支持多行 `SQL` 语句执行**。为了得到更多配置项控制,请参考推荐的`link`简化配置,并了解清楚简化配置项中每个连接参数的功能作用,以及对应驱动的官方额外配置参数。
:::

配置示例:
```yaml
database:
default:
link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
extra: "charset=utf8mb4&parseTime=True&loc=Local"
mysql:
type: "mysql"
host: "127.0.0.1"
port: "3306"
user: "root"
pass: "12345678"
name: "test"
charset: "utf8mb4"
timezone: "Local"
maxIdle: "10"
maxOpen: "100"
maxLifetime: "30s"
extra: "parseTime=True"
```

## 集群模式

`gdb` 的配置支持集群模式,数据库配置中每一项分组配置均可以是多个节点,支持负载均衡权重策略,例如:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (

```go
type User struct {
g.Meta `table:"uer" orm:"do:true"`
g.Meta `table:"user" orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
Expand Down
2 changes: 1 addition & 1 deletion docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const config: Config = {
position: 'left',
label: '开发手册',
sidebarId: 'mainSidebar',
to: '/docs/cli',
to: '/docs/core',
},
{
sidebarId: 'courseSidebar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (

```go
type User struct {
g.Meta `table:"uer" orm:"do:true"`
g.Meta `table:"user" orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (

```go
type User struct {
g.Meta `table:"uer" orm:"do:true"`
g.Meta `table:"user" orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (

```go
type User struct {
g.Meta `table:"uer" orm:"do:true"`
g.Meta `table:"user" orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (

```go
type User struct {
g.Meta `table:"uer" orm:"do:true"`
g.Meta `table:"user" orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func main() {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN")))
r.SetCtx(gi18n.WithLanguage(r.Context(), r.Get("lang", "zh-CN").String()))
r.Middleware.Next()
})
group.ALL("/", func(r *ghttp.Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (

```go
type User struct {
g.Meta `table:"uer" orm:"do:true"`
g.Meta `table:"user" orm:"do:true"`
Id interface{}
Passport interface{}
Password interface{}
Expand Down

0 comments on commit 5830371

Please sign in to comment.