Masterminds/goutils
GitHub: Masterminds/goutils
Go 语言的字符串处理工具库,将 Java Apache Commons 的部分字符串操作功能移植到 Go 生态中。
Stars: 99 | Forks: 28
# GoUtils
[](https://masterminds.github.io/stability/maintenance.html)
[](https://godoc.org/github.com/Masterminds/goutils) [](https://travis-ci.org/Masterminds/goutils) [](https://ci.appveyor.com/project/mattfarina/goutils)
GoUtils 为用户提供了以各种方式处理字符串的实用工具函数。它是 Java Apache Commons 的部分字符串处理库的 Go 语言实现。GoUtils 包含以下 Java Apache Commons 类:
* WordUtils
* RandomStringUtils
* StringUtils(部分实现)
## 安装说明
如果您的系统已经配置好 Go 环境,请在命令行/终端中切换到 GOPATH 目录,并输入以下命令:
```
go get github.com/Masterminds/goutils
```
## 文档
GoUtils 文档可在此处获取:[](https://godoc.org/github.com/Masterminds/goutils)
## 用法
下面的代码片段展示了如何使用 GoUtils 的示例。有些函数会返回错误,而有些则不会。下面的第一个示例是不返回错误的 `Initials` 函数(位于 `wordutils.go` 文件中)。
```
package main
import (
"fmt"
"github.com/Masterminds/goutils"
)
func main() {
// EXAMPLE 1: A goutils function which returns no errors
fmt.Println (goutils.Initials("John Doe Foo")) // Prints out "JDF"
}
```
有些函数返回错误,主要是由于用作参数的非法参数。下面的代码示例演示了如何处理返回错误的函数。在这个示例中,该函数是 `Random` 函数(位于 `randomstringutils.go` 文件中)。
```
package main
import (
"fmt"
"github.com/Masterminds/goutils"
)
func main() {
// EXAMPLE 2: A goutils function which returns an error
rand1, err1 := goutils.Random (-1, 0, 0, true, true)
if err1 != nil {
fmt.Println(err1) // Prints out error message because -1 was entered as the first parameter in goutils.Random(...)
} else {
fmt.Println(rand1)
}
}
```
## 许可证
GoUtils 采用 Apache License, Version 2.0 授权。请查看 LICENSE.txt 文件或访问 http://www.apache.org/licenses/LICENSE-2.0 获取许可证副本。
## 问题报告
请使用 Git issue 追踪器提出建议或报告问题:https://github.com/Masterminds/goutils/issues
## 网站
* [GoUtils 网页](http://Masterminds.github.io/goutils/)
标签:EVTX分析, 日志审计