From 0bc1c9a8bb9180ce3f98f7149828ebcd868308ce Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Sat, 17 Jul 2021 11:32:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=86=85=E5=AE=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- .../Language/Go/Basic/Golang_安装_Packages.md | 18 +++++--- .../Language/Go/Basic/Golang_文件操作.md | 43 ++++++++++++++++++- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/Software/Development/Language/Go/Basic/Golang_安装_Packages.md b/Software/Development/Language/Go/Basic/Golang_安装_Packages.md index 7b7bc53..fecebfe 100644 --- a/Software/Development/Language/Go/Basic/Golang_安装_Packages.md +++ b/Software/Development/Language/Go/Basic/Golang_安装_Packages.md @@ -11,12 +11,20 @@ go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn ``` -## 2.安装 Packages +## 2.下载和安装 Packages -以安装 guru 为例: +通常,开发过程中所需要的 Package 只需要通过 go get 命令下载就可以使用,以 uuid 包为例,下载指定版本的 uuid 包命令如下: ```bash -go get golang.org/x/tools/cmd/guru -go build golang.org/x/tools/cmd/guru -mv guru $(go env GOROOT)/bin +# 下载 Go Package +go get github.com/satori/go.uuid@v1.2.0 +``` + +有些 go 工具除了下载外还需要编译安装,以 gopls 工具为例,下载、编译和安装命令如下: + +```bash +# 下载 gopls +go get -v golang.org/x/tools/gopls +# 编译并安装 +go install golang.org/x/tools/gopls ``` diff --git a/Software/Development/Language/Go/Basic/Golang_文件操作.md b/Software/Development/Language/Go/Basic/Golang_文件操作.md index 5879d87..fbc4bad 100644 --- a/Software/Development/Language/Go/Basic/Golang_文件操作.md +++ b/Software/Development/Language/Go/Basic/Golang_文件操作.md @@ -31,7 +31,7 @@ func Open(name string) (*File, error) func OpenFile(name string, flag int, perm FileMode) (*File, error) ``` -perm 模式如下: +flag 如下: ```go //打开方式 @@ -55,6 +55,47 @@ O_TRUNC int = syscall.O_TRUNC // if possible, truncate file when opened. ) ``` +perm 模式如下: + +```go +const ( + // The single letters are the abbreviations + // used by the String method's formatting. + // 文件夹模式 + ModeDir FileMode = 1 << (32 - 1 - iota) // d: is a directory + // 追加模式 + ModeAppend // a: append-only + // 单独使用 + ModeExclusive // l: exclusive use + // 临时文件 + ModeTemporary // T: temporary file; Plan 9 only + // 象征性的关联 + ModeSymlink // L: symbolic link + // 设备文件 + ModeDevice // D: device file + // 命名管道 + ModeNamedPipe // p: named pipe (FIFO) + // Unix 主机 socket + ModeSocket // S: Unix domain socket + // 设置uid + ModeSetuid // u: setuid + // 设置gid + ModeSetgid // g: setgid + // UNIX 字符串设备,当设备模式是设置unix + ModeCharDevice // c: Unix character device, when ModeDevice is set + // 粘性的 + ModeSticky // t: sticky + // 非常规文件;对该文件一无所知 + ModeIrregular // ?: non-regular file; nothing else is known about this file + + // bit位遮盖,不变的文件设置为none + // Mask for the type bits. For regular files, none will be set. + ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice | ModeCharDevice | ModeIrregular + // 权限位 + ModePerm FileMode = 0777 // Unix permission bits +) +``` + ### 1.3.获取文件状态 ```go