From 29ee65f4bdb1300f0a4e0060b3c69e2dd4174861 Mon Sep 17 00:00:00 2001 From: dengsgo Date: Sun, 20 Aug 2023 17:02:19 +0800 Subject: [PATCH] update doc --- GUIDE.md | 8 ++++++++ GUIDE.zh_cn.md | 8 ++++++++ README.md | 14 ++------------ README.zh_cn.md | 13 ++----------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/GUIDE.md b/GUIDE.md index beb9f62..efdcf07 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -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. @@ -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: diff --git a/GUIDE.zh_cn.md b/GUIDE.zh_cn.md index 00f943d..2780bb4 100644 --- a/GUIDE.zh_cn.md +++ b/GUIDE.zh_cn.md @@ -48,6 +48,12 @@ $ go install github.com/dengsgo/go-decorator/cmd/decorator@latest 它适用于大多数 `go` 的子命令。 +### 添加依赖 + +```shell +$ go get -u github.com/dengsgo/go-decorator +``` + ### 目标函数和装饰器 > 目标函数:即使用了装饰器的函数,也称为被装饰的函数。 @@ -189,6 +195,8 @@ func datetime(timestamp int64) string { 上面的 `datetime` [example/datetime](example/datetime) 例子中,我们的装饰器和目标函数都是在一个包中的,我们无需考虑包的问题。 +当我们有很多包时,需要考虑包引用。 + go 规范中,没有被当前文件里的代码使用到的包无法导入,这就导致了 `//go:decor` 这样的注释无法真正的导入包,因此需要我们使用匿名导入包的方式来导入对应的包。像这样 `import _ "path/to/your/package"`. 有下面两种情况需要使用匿名导入包: diff --git a/README.md b/README.md index df8d6be..b639cdd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/README.zh_cn.md b/README.zh_cn.md index baf744d..2e80bb3 100644 --- a/README.zh_cn.md +++ b/README.zh_cn.md @@ -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` 版本信息即为安装成功。 注意:请经常更新以安装最新版本。获得最佳体验。