Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dengsgo committed Aug 20, 2023
1 parent a3e0624 commit 29ee65f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
8 changes: 8 additions & 0 deletions GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ For example: 'go build **-toolexec decorator**', 'go run **-toolexec decorator**

This applies to most `go` subcommands.

### Add a dependency

```shell
$ go get -u github.com/dengsgo/go-decorator
```

### Destination functions and decorators

> Target functions: functions that use a decorator, also known as decorated functions.
Expand Down Expand Up @@ -191,6 +197,8 @@ If `ctx.TargetDo()` is not executed in the decorator, it means that the real log

In the `datetime` [example/datetime](example/datetime) example above, our decorator and target function are in a package and we don't need to think about packages.

Package references need to be considered when we have many packages.

The go specification prevents importing packages that aren't used by the code in the current file, which means that comments like `//go:decor` don't really import packages, so we need to use an anonymous package import to import the corresponding package. Like this `import _"path/to/your/package"`.

There are two cases where you need to import a package anonymously:
Expand Down
8 changes: 8 additions & 0 deletions GUIDE.zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ $ go install github.com/dengsgo/go-decorator/cmd/decorator@latest

它适用于大多数 `go` 的子命令。

### 添加依赖

```shell
$ go get -u github.com/dengsgo/go-decorator
```

### 目标函数和装饰器

> 目标函数:即使用了装饰器的函数,也称为被装饰的函数。
Expand Down Expand Up @@ -189,6 +195,8 @@ func datetime(timestamp int64) string {

上面的 `datetime` [example/datetime](example/datetime) 例子中,我们的装饰器和目标函数都是在一个包中的,我们无需考虑包的问题。

当我们有很多包时,需要考虑包引用。

go 规范中,没有被当前文件里的代码使用到的包无法导入,这就导致了 `//go:decor` 这样的注释无法真正的导入包,因此需要我们使用匿名导入包的方式来导入对应的包。像这样 `import _ "path/to/your/package"`.

有下面两种情况需要使用匿名导入包:
Expand Down
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,12 @@ The usage scenarios of decorators can be compared to other languages, such as Py

## Install

The project is still actively developing, and the best installation method currently is source code compilation (binary distribution will be provided after stabilization).

```shell
$ git clone https://github.com/dengsgo/go-decorator.git
$ cd go-decorator/cmd/decorator
$ go build
```

Successfully compiled will result in the `decorator` binary file. Add this file path to your environment variable `Path` for future calls.

You can also directly `go install`:
Install via `go install`.
```shell
$ go install github.com/dengsgo/go-decorator/cmd/decorator@latest
```

Run `decorator --help` and the help message `decorator` appears to indicate successful installation.
Run `decorator` and it will show you the `decorator` version.

Note: Please update frequently to install the latest version. Get the best experience.

Expand Down
13 changes: 2 additions & 11 deletions README.zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@

## Install

项目仍在积极开发,当前最好的安装方式是源码编译(后续稳定后会提供二进制分发)。

```shell
$ git clone https://github.com/dengsgo/go-decorator.git
$ cd go-decorator/cmd/decorator
$ go build
```
编译成功会得到 `decorator` 二进制文件。将此文件路径加入你的环境变量 `Path` 中以便后续调用。

也可以直接 `go install`:
通过 `go install` 安装:
```shell
$ go install github.com/dengsgo/go-decorator/cmd/decorator@latest
```

运行 `decorator --help`,出现`decorator`的帮助信息即为安装成功
运行 `decorator`,显示 `decorator` 版本信息即为安装成功

注意:请经常更新以安装最新版本。获得最佳体验。

Expand Down

0 comments on commit 29ee65f

Please sign in to comment.