summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/viper/internal/encoding
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/viper/internal/encoding')
-rw-r--r--vendor/github.com/spf13/viper/internal/encoding/dotenv/codec.go61
-rw-r--r--vendor/github.com/spf13/viper/internal/encoding/dotenv/map_utils.go41
-rw-r--r--vendor/github.com/spf13/viper/internal/encoding/json/codec.go17
-rw-r--r--vendor/github.com/spf13/viper/internal/encoding/toml/codec.go16
-rw-r--r--vendor/github.com/spf13/viper/internal/encoding/yaml/codec.go14
5 files changed, 0 insertions, 149 deletions
diff --git a/vendor/github.com/spf13/viper/internal/encoding/dotenv/codec.go b/vendor/github.com/spf13/viper/internal/encoding/dotenv/codec.go
deleted file mode 100644
index 3ebc76f02..000000000
--- a/vendor/github.com/spf13/viper/internal/encoding/dotenv/codec.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package dotenv
-
-import (
- "bytes"
- "fmt"
- "sort"
- "strings"
-
- "github.com/subosito/gotenv"
-)
-
-const keyDelimiter = "_"
-
-// Codec implements the encoding.Encoder and encoding.Decoder interfaces for encoding data containing environment variables
-// (commonly called as dotenv format).
-type Codec struct{}
-
-func (Codec) Encode(v map[string]any) ([]byte, error) {
- flattened := map[string]any{}
-
- flattened = flattenAndMergeMap(flattened, v, "", keyDelimiter)
-
- keys := make([]string, 0, len(flattened))
-
- for key := range flattened {
- keys = append(keys, key)
- }
-
- sort.Strings(keys)
-
- var buf bytes.Buffer
-
- for _, key := range keys {
- _, err := buf.WriteString(fmt.Sprintf("%v=%v\n", strings.ToUpper(key), flattened[key]))
- if err != nil {
- return nil, err
- }
- }
-
- return buf.Bytes(), nil
-}
-
-func (Codec) Decode(b []byte, v map[string]any) error {
- var buf bytes.Buffer
-
- _, err := buf.Write(b)
- if err != nil {
- return err
- }
-
- env, err := gotenv.StrictParse(&buf)
- if err != nil {
- return err
- }
-
- for key, value := range env {
- v[key] = value
- }
-
- return nil
-}
diff --git a/vendor/github.com/spf13/viper/internal/encoding/dotenv/map_utils.go b/vendor/github.com/spf13/viper/internal/encoding/dotenv/map_utils.go
deleted file mode 100644
index 8bfe0a9de..000000000
--- a/vendor/github.com/spf13/viper/internal/encoding/dotenv/map_utils.go
+++ /dev/null
@@ -1,41 +0,0 @@
-package dotenv
-
-import (
- "strings"
-
- "github.com/spf13/cast"
-)
-
-// flattenAndMergeMap recursively flattens the given map into a new map
-// Code is based on the function with the same name in the main package.
-// TODO: move it to a common place.
-func flattenAndMergeMap(shadow, m map[string]any, prefix, delimiter string) map[string]any {
- if shadow != nil && prefix != "" && shadow[prefix] != nil {
- // prefix is shadowed => nothing more to flatten
- return shadow
- }
- if shadow == nil {
- shadow = make(map[string]any)
- }
-
- var m2 map[string]any
- if prefix != "" {
- prefix += delimiter
- }
- for k, val := range m {
- fullKey := prefix + k
- switch val := val.(type) {
- case map[string]any:
- m2 = val
- case map[any]any:
- m2 = cast.ToStringMap(val)
- default:
- // immediate value
- shadow[strings.ToLower(fullKey)] = val
- continue
- }
- // recursively merge to shadow map
- shadow = flattenAndMergeMap(shadow, m2, fullKey, delimiter)
- }
- return shadow
-}
diff --git a/vendor/github.com/spf13/viper/internal/encoding/json/codec.go b/vendor/github.com/spf13/viper/internal/encoding/json/codec.go
deleted file mode 100644
index da7546b5a..000000000
--- a/vendor/github.com/spf13/viper/internal/encoding/json/codec.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package json
-
-import (
- "encoding/json"
-)
-
-// Codec implements the encoding.Encoder and encoding.Decoder interfaces for JSON encoding.
-type Codec struct{}
-
-func (Codec) Encode(v map[string]any) ([]byte, error) {
- // TODO: expose prefix and indent in the Codec as setting?
- return json.MarshalIndent(v, "", " ")
-}
-
-func (Codec) Decode(b []byte, v map[string]any) error {
- return json.Unmarshal(b, &v)
-}
diff --git a/vendor/github.com/spf13/viper/internal/encoding/toml/codec.go b/vendor/github.com/spf13/viper/internal/encoding/toml/codec.go
deleted file mode 100644
index c70aa8d28..000000000
--- a/vendor/github.com/spf13/viper/internal/encoding/toml/codec.go
+++ /dev/null
@@ -1,16 +0,0 @@
-package toml
-
-import (
- "github.com/pelletier/go-toml/v2"
-)
-
-// Codec implements the encoding.Encoder and encoding.Decoder interfaces for TOML encoding.
-type Codec struct{}
-
-func (Codec) Encode(v map[string]any) ([]byte, error) {
- return toml.Marshal(v)
-}
-
-func (Codec) Decode(b []byte, v map[string]any) error {
- return toml.Unmarshal(b, &v)
-}
diff --git a/vendor/github.com/spf13/viper/internal/encoding/yaml/codec.go b/vendor/github.com/spf13/viper/internal/encoding/yaml/codec.go
deleted file mode 100644
index a7a839fd9..000000000
--- a/vendor/github.com/spf13/viper/internal/encoding/yaml/codec.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package yaml
-
-import "go.yaml.in/yaml/v3"
-
-// Codec implements the encoding.Encoder and encoding.Decoder interfaces for YAML encoding.
-type Codec struct{}
-
-func (Codec) Encode(v map[string]any) ([]byte, error) {
- return yaml.Marshal(v)
-}
-
-func (Codec) Decode(b []byte, v map[string]any) error {
- return yaml.Unmarshal(b, &v)
-}