-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangyile
committed
Dec 3, 2024
1 parent
37d58a6
commit 18a93d8
Showing
14 changed files
with
481 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: create-release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # 监听 main 分支的 push 操作(编译和测试/代码检查) | ||
tags: | ||
- 'v*' # 监听以 'v' 开头的标签的 push 操作(发布 Release) | ||
|
||
jobs: | ||
lint: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.23.x" | ||
- uses: actions/checkout@v4 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: latest | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go: [ "1.22.x", "1.23.x" ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Run test | ||
run: make test COVERAGE_DIR=/tmp/coverage | ||
|
||
- name: Send goveralls coverage | ||
uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
path-to-profile: /tmp/coverage/combined.txt | ||
flag-name: Go-${{ matrix.go }} | ||
parallel: true | ||
|
||
check-coverage: | ||
name: Check coverage | ||
needs: [ test ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
parallel-finished: true | ||
|
||
# 发布 Release | ||
release: | ||
name: Release a new version | ||
needs: [ lint, test ] | ||
runs-on: ubuntu-latest | ||
# 仅在推送标签时执行 | ||
if: ${{ success() && startsWith(github.ref, 'refs/tags/v') }} | ||
steps: | ||
# 1. 检出代码 | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
# 2. 创建 Release 和上传源码包 | ||
- name: Create Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
generate_release_notes: true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 yangyile-yyle88 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
COVERAGE_DIR ?= .coverage | ||
|
||
# cp from: https://github.com/yyle88/sure/blob/10a10cb5c07f6239fc8e310459fb6a240dd117ce/Makefile#L4 | ||
test: | ||
@-rm -r $(COVERAGE_DIR) | ||
@mkdir $(COVERAGE_DIR) | ||
make test-with-flags TEST_FLAGS='-v -race -covermode atomic -coverprofile $$(COVERAGE_DIR)/combined.txt -bench=. -benchmem -timeout 20m' | ||
|
||
test-with-flags: | ||
@go test $(TEST_FLAGS) ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,77 @@ | ||
[](https://github.com/yyle88/neatjson/actions/workflows/release.yml?query=branch%3Amain) | ||
[](https://pkg.go.dev/github.com/yyle88/neatjson) | ||
[](https://coveralls.io/github/yyle88/neatjson?branch=main) | ||
 | ||
[](https://github.com/yyle88/neatjson/releases) | ||
[](https://goreportcard.com/report/github.com/yyle88/neatjson) | ||
|
||
# neatjson | ||
neat json make it neat to use "encoding/json" in golang. | ||
|
||
其操作很简单,就是把结构体转json时,传统结果是: | ||
``` | ||
{"a": "abc","n": 123} | ||
`neatjson` make it neat to use "encoding/json" in golang. | ||
|
||
## CHINESE README | ||
|
||
[中文说明](README.zh.md) | ||
|
||
## Installation | ||
|
||
```bash | ||
go get github.com/yyle88/neatjson | ||
``` | ||
这个是转带换行和缩进格式的,便于观察,仅此而已: | ||
|
||
## Features | ||
|
||
- Convert Go structures to indented JSON strings. | ||
- Format JSON data from raw strings, byte arrays. | ||
|
||
## Usage | ||
|
||
Here's an example of how to format a Go data structure into a indented JSON string: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/yyle88/neatjson/neatjsons" | ||
) | ||
|
||
func main() { | ||
arg := map[string]any{"a": "abc", "n": 123} | ||
res := neatjsons.S(arg) | ||
|
||
fmt.Println(res) | ||
} | ||
``` | ||
|
||
Output: | ||
|
||
```json | ||
{ | ||
"a": "abc", | ||
"n": 123 | ||
"a": "abc", | ||
"n": 123 | ||
} | ||
``` | ||
具体使用方法是: | ||
``` | ||
go get github.com/yyle88/neatjson | ||
``` | ||
在代码中使用时: | ||
``` | ||
fmt.Println(neatjsons.S( a )) | ||
``` | ||
非常非常的方便。 | ||
|
||
--- | ||
|
||
## License | ||
|
||
`neatjson` is open-source and released under the MIT License. See the [LICENSE](LICENSE) file for more information. | ||
|
||
--- | ||
|
||
## Support | ||
|
||
Welcome to contribute to this project by submitting pull requests or reporting issues. | ||
|
||
If you find this package helpful, give it a star on GitHub! | ||
|
||
**Thank you for your support!** | ||
|
||
**Happy Coding with `neatjson`!** 🎉 | ||
|
||
Give me stars. Thank you!!! | ||
|
||
## See stars | ||
[](https://starchart.cc/yyle88/neatjson) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# neatjson | ||
|
||
`neatjson` 使得在 Golang 中使用 "encoding/json" 更加简洁和方便。 | ||
|
||
## 英文文档 | ||
|
||
[English README](README.md) | ||
|
||
## 安装 | ||
|
||
```bash | ||
go get github.com/yyle88/neatjson | ||
``` | ||
|
||
## 特性 | ||
|
||
- 将 Go 结构体转换为带缩进的 JSON 字符串。 | ||
- 格式化原始字符串和字节数组中的 JSON 数据。 | ||
|
||
## 用法 | ||
|
||
以下是如何将 Go 数据结构格式化为带缩进的 JSON 字符串的示例: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/yyle88/neatjson/neatjsons" | ||
) | ||
|
||
func main() { | ||
arg := map[string]any{"a": "abc", "n": 123} | ||
res := neatjsons.S(arg) | ||
|
||
fmt.Println(res) | ||
} | ||
``` | ||
|
||
输出: | ||
|
||
```json | ||
{ | ||
"a": "abc", | ||
"n": 123 | ||
} | ||
``` | ||
|
||
--- | ||
|
||
## 许可 | ||
|
||
`neatjson` 是一个开源项目,发布于 MIT 许可证下。有关更多信息,请参阅 [LICENSE](LICENSE) 文件。 | ||
|
||
## 贡献与支持 | ||
|
||
欢迎通过提交 pull request 或报告问题来贡献此项目。 | ||
|
||
如果你觉得这个包对你有帮助,请在 GitHub 上给个 ⭐,感谢支持!!! | ||
|
||
**感谢你的支持!** | ||
|
||
**祝编程愉快!** 🎉 | ||
|
||
Give me stars. Thank you!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.