Skip to content

Commit

Permalink
chore: update readme, update action script
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 12, 2022
1 parent 4dd95c8 commit 2dddf2b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:

- name: Revive check
uses: morphy2k/revive-action@v2.3.1
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
# Exclude patterns, separated by semicolons (optional)
exclude: "./internal/..."
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ ioutil.WriteFile("my-config.json", buf.Bytes(), 0755)

**Pretty dump JSON**

You can set the default var `JSONMarshalIndent` or custom a new JSON driver.

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

## Available options
Expand Down
6 changes: 3 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ ioutil.WriteFile("my-config.json", buf.Bytes(), 0755)

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

可以设置默认变量 `JSONMarshalIndent` 的值 或 自定义新的 JSON 驱动程序。

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

## 可用选项
Expand Down
8 changes: 4 additions & 4 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

var (
readonlyErr = errors.New("the config instance in 'readonly' mode")
keyIsEmptyErr = errors.New("the config key is cannot be empty")
errReadonly = errors.New("the config instance in 'readonly' mode")
errKeyIsEmpty = errors.New("the config key is cannot be empty")
)

// SetData for override the Config.Data
Expand All @@ -36,15 +36,15 @@ func Set(key string, val interface{}, setByPath ...bool) error {
// Set a value by key string.
func (c *Config) Set(key string, val interface{}, setByPath ...bool) (err error) {
if c.opts.Readonly {
return readonlyErr
return errReadonly
}

c.lock.Lock()
defer c.lock.Unlock()

sep := c.opts.Delimiter
if key = formatKey(key, string(sep)); key == "" {
return keyIsEmptyErr
return errKeyIsEmpty
}

defer c.fireHook(OnSetValue)
Expand Down

0 comments on commit 2dddf2b

Please sign in to comment.