Skip to content

Commit

Permalink
update: update gh action script and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 12, 2022
1 parent fe69183 commit a4ca4c0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
27 changes: 23 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,32 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v3
# https://github.com/actions/setup-go
- name: Use Go ${{ matrix.go_version }}
timeout-minutes: 5
uses: actions/setup-go@v3

- name: Setup Go Faster
uses: WillAbides/setup-go-faster@v1.7.0
timeout-minutes: 3
with:
go-version: ${{ matrix.go_version }}

- name: Revive check
uses: morphy2k/revive-action@v2.3.1
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
# Exclude patterns, separated by semicolons (optional)
exclude: "./internal/..."

- name: Run static check
uses: reviewdog/action-staticcheck@v1
if: ${{ github.event_name == 'pull_request'}}
with:
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
reporter: github-pr-check
# Report all results. [added,diff_context,file,nofilter].
filter_mode: added
# Exit with 1 when it find at least one finding.
fail_on_error: true

- name: Run unit tests
# run: go test -v -cover ./...
# must add " for profile.cov on windows OS
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@ fire the: set.data
fire the: clean.data
```

## Dump config data

```go
buf := new(bytes.Buffer)

_, err := config.DumpTo(buf, config.JSON)

ioutil.WriteFile("my-config.json", buf.Bytes(), 0755)
```

**Pretty dump JSON**

```go
config.SetEncoder(config.JSON, func(v interface{}) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
})
```

## Available options

```go
Expand Down
18 changes: 18 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ fire the: set.data
fire the: clean.data
```

## 导出配置到文件

```go
buf := new(bytes.Buffer)

_, err := config.DumpTo(buf, config.JSON)

ioutil.WriteFile("my-config.json", buf.Bytes(), 0755)
```

**示例:美化导出的JSON**

```go
config.SetEncoder(config.JSON, func(v interface{}) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
})
```

## 可用选项

```go
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func formatKey(key, sep string) string {
return strings.Trim(strings.TrimSpace(key), sep)
}

// fix inc/conf/yaml format
// resolve fix inc/conf/yaml format
func fixFormat(f string) string {
if f == Yml {
f = Yaml
Expand Down
2 changes: 1 addition & 1 deletion write.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *Config) Set(key string, val interface{}, setByPath ...bool) (err error)
return err
}
default:
// as an top key
// as a top key
c.data[key] = val
// err = errors.New("not supported value type, cannot setting value for the key: " + key)
}
Expand Down

0 comments on commit a4ca4c0

Please sign in to comment.