Skip to content

Commit

Permalink
Fix typos and cosmetic refactor of code (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyXor committed Jul 21, 2023
1 parent 5dceb97 commit 860346f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
12 changes: 6 additions & 6 deletions getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (ko *Koanf) Int64Map(path string) map[string]int64 {
}

// MustInt64Map returns the map[string]int64 value of a given key path
// or panics if its not set or set to default value.
// or panics if it isn't set or set to default value.
func (ko *Koanf) MustInt64Map(path string) map[string]int64 {
val := ko.Int64Map(path)
if len(val) == 0 {
Expand All @@ -130,7 +130,7 @@ func (ko *Koanf) Int(path string) int {
}

// MustInt returns the int value of a given key path or panics
// or panics if its not set or set to default value of 0.
// if it isn't set or set to default value of 0.
func (ko *Koanf) MustInt(path string) int {
val := ko.Int(path)
if val == 0 {
Expand Down Expand Up @@ -221,7 +221,7 @@ func (ko *Koanf) Float64(path string) float64 {
}

// MustFloat64 returns the float64 value of a given key path or panics
// or panics if its not set or set to default value 0.
// if it isn't set or set to default value 0.
func (ko *Koanf) MustFloat64(path string) float64 {
val := ko.Float64(path)
if val == 0 {
Expand Down Expand Up @@ -328,7 +328,7 @@ func (ko *Koanf) Duration(path string) time.Duration {
}

// MustDuration returns the time.Duration value of a given key path or panics
// if its not set or set to default value 0.
// if it isn't set or set to default value 0.
func (ko *Koanf) MustDuration(path string) time.Duration {
val := ko.Duration(path)
if val == 0 {
Expand Down Expand Up @@ -382,7 +382,7 @@ func (ko *Koanf) String(path string) string {
}

// MustString returns the string value of a given key path
// or panics if its not set or set to default value "".
// or panics if it isn't set or set to default value "".
func (ko *Koanf) MustString(path string) string {
val := ko.String(path)
if val == "" {
Expand Down Expand Up @@ -414,7 +414,7 @@ func (ko *Koanf) Strings(path string) []string {
return out
case []string:
out := make([]string, len(v))
copy(out[:], v[:])
copy(out, v)
return out
}

Expand Down
2 changes: 1 addition & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package koanf
// Provider represents a configuration provider. Providers can
// read configuration from a source (file, HTTP etc.)
type Provider interface {
// Read returns the entire configuration as raw []bytes to be parsed.
// ReadBytes returns the entire configuration as raw []bytes to be parsed.
// with a Parser.
ReadBytes() ([]byte, error)

Expand Down
23 changes: 12 additions & 11 deletions koanf.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ func (ko *Koanf) Keys() []string {
}

// KeyMap returns a map of flattened keys and the individual parts of the
// key as slices. eg: "parent.child.key" => ["parent", "child", "key"]
// key as slices. eg: "parent.child.key" => ["parent", "child", "key"].
func (ko *Koanf) KeyMap() KeyMap {
out := make(KeyMap, len(ko.keyMap))
for key, parts := range ko.keyMap {
out[key] = make([]string, len(parts))
copy(out[key][:], parts[:])
copy(out[key], parts)
}
return out
}
Expand All @@ -161,7 +161,7 @@ func (ko *Koanf) Raw() map[string]interface{} {
func (ko *Koanf) Sprint() string {
b := bytes.Buffer{}
for _, k := range ko.Keys() {
b.Write([]byte(fmt.Sprintf("%s -> %v\n", k, ko.confMapFlat[k])))
b.WriteString(fmt.Sprintf("%s -> %v\n", k, ko.confMapFlat[k]))
}
return b.String()
}
Expand Down Expand Up @@ -425,7 +425,7 @@ func (ko *Koanf) merge(c map[string]interface{}, opts *options) error {

// toInt64 takes an interface value and if it is an integer type,
// converts and returns int64. If it's any other type,
// forces it to a string and attempts to an strconv.Atoi
// forces it to a string and attempts to do a strconv.Atoi
// to get an integer out.
func toInt64(v interface{}) (int64, error) {
switch i := v.(type) {
Expand Down Expand Up @@ -507,19 +507,20 @@ func populateKeyParts(m KeyMap, delim string) KeyMap {
continue
}
out[nk] = make([]string, i+1)
copy(out[nk][:], parts[0:i+1])
copy(out[nk], parts[0:i+1])
}
}
return out
}

// textUnmarshalerHookFunc is a fixed version of mapstructure.TextUnmarshallerHookFunc.
// This hook allows to additionally unmarshal text into custom string types that implement the encoding.(Un)TextMarshaler interface(s)
// This hook allows to additionally unmarshal text into custom string types that implement the encoding.Text(Un)Marshaler interface(s).
func textUnmarshalerHookFunc() mapstructure.DecodeHookFuncType {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
data interface{},
) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
Expand All @@ -529,7 +530,7 @@ func textUnmarshalerHookFunc() mapstructure.DecodeHookFuncType {
return data, nil
}

// default text representaion is the actual value of the `from` string
// default text representation is the actual value of the `from` string
var (
dataVal = reflect.ValueOf(data)
text = []byte(dataVal.String())
Expand All @@ -550,8 +551,8 @@ func textUnmarshalerHookFunc() mapstructure.DecodeHookFuncType {
ptrVal.Elem().Set(dataVal)

// We need to assert that both, the value type and the pointer type
// do (not) implement the TextMarshaler interface before proceeding and simmply
// using the the string value of the string type.
// do (not) implement the TextMarshaller interface before proceeding and simply
// using the string value of the string type.
// it might be the case that the internal string representation differs from
// the (un)marshalled string.

Expand All @@ -567,7 +568,7 @@ func textUnmarshalerHookFunc() mapstructure.DecodeHookFuncType {
}

// text is either the source string's value or the source string type's marshaled value
// which may differ fromit internal string value.
// which may differ from its internal string value.
if err := unmarshaller.UnmarshalText(text); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions providers/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package file
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"

Expand All @@ -25,7 +25,7 @@ func Provider(path string) *File {

// ReadBytes reads the contents of a file on disk and returns the bytes.
func (f *File) ReadBytes() ([]byte, error) {
return ioutil.ReadFile(f.path)
return os.ReadFile(f.path)
}

// Read is not supported by the file provider.
Expand Down

0 comments on commit 860346f

Please sign in to comment.