diff --git a/air.go b/air.go index a57c2da..16affc1 100644 --- a/air.go +++ b/air.go @@ -62,8 +62,8 @@ import ( "sync" "time" - "github.com/BurntSushi/toml" "github.com/mitchellh/mapstructure" + "github.com/pelletier/go-toml" "golang.org/x/crypto/acme" "golang.org/x/crypto/acme/autocert" "golang.org/x/net/http2" diff --git a/binder.go b/binder.go index cabaf86..2fe93a4 100644 --- a/binder.go +++ b/binder.go @@ -10,7 +10,7 @@ import ( "reflect" "strings" - "github.com/BurntSushi/toml" + "github.com/pelletier/go-toml" "github.com/vmihailenco/msgpack/v5" "google.golang.org/protobuf/proto" "gopkg.in/yaml.v3" @@ -59,7 +59,7 @@ func (b *binder) bind(v interface{}, r *Request) error { case "application/msgpack": err = msgpack.NewDecoder(r.Body).Decode(v) case "application/toml": - _, err = toml.DecodeReader(r.Body, v) + err = toml.NewDecoder(r.Body).Decode(v) case "application/yaml": err = yaml.NewDecoder(r.Body).Decode(v) case "application/x-www-form-urlencoded", "multipart/form-data": diff --git a/go.mod b/go.mod index e9cee61..5a19582 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/aofei/air go 1.13 require ( - github.com/BurntSushi/toml v0.3.1 github.com/VictoriaMetrics/fastcache v1.5.7 github.com/aofei/mimesniffer v1.1.5 github.com/cespare/xxhash/v2 v2.1.1 @@ -11,6 +10,7 @@ require ( github.com/golang/protobuf v1.4.2 // indirect github.com/gorilla/websocket v1.4.2 github.com/mitchellh/mapstructure v1.3.3 + github.com/pelletier/go-toml v1.8.1 github.com/stretchr/testify v1.6.1 github.com/tdewolff/minify/v2 v2.9.3 github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1 diff --git a/go.sum b/go.sum index f66f079..84284d0 100644 --- a/go.sum +++ b/go.sum @@ -54,6 +54,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs= github.com/mitchellh/mapstructure v1.3.3 h1:SzB1nHZ2Xi+17FP0zVQBHIZqvwRN9408fJO8h+eeNA8= github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= +github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= diff --git a/i18n.go b/i18n.go index c0d9cf3..7c6fea7 100644 --- a/i18n.go +++ b/i18n.go @@ -7,8 +7,8 @@ import ( "strings" "sync" - "github.com/BurntSushi/toml" "github.com/fsnotify/fsnotify" + "github.com/pelletier/go-toml" "golang.org/x/text/language" ) @@ -93,7 +93,11 @@ func (i *i18n) load() { n := filepath.Join(lr, fi.Name()) l := map[string]string{} - if _, i.loadError = toml.DecodeFile(n, &l); i.loadError != nil { + + var tt *toml.Tree + if tt, i.loadError = toml.LoadFile(n); i.loadError != nil { + return + } else if i.loadError = tt.Unmarshal(&l); i.loadError != nil { return } else if i.loadError = i.watcher.Add(n); i.loadError != nil { return diff --git a/response.go b/response.go index 8ec87ea..cda4fa9 100644 --- a/response.go +++ b/response.go @@ -26,10 +26,10 @@ import ( "sync" "time" - "github.com/BurntSushi/toml" "github.com/aofei/mimesniffer" "github.com/cespare/xxhash/v2" "github.com/gorilla/websocket" + "github.com/pelletier/go-toml" "github.com/vmihailenco/msgpack/v5" "golang.org/x/net/http/httpguts" "golang.org/x/net/http2" @@ -380,27 +380,27 @@ func (r *Response) WriteMsgpack(v interface{}) error { // WriteTOML writes an "application/toml" content encoded from the v to the // client. func (r *Response) WriteTOML(v interface{}) error { - buf := bytes.Buffer{} - if err := toml.NewEncoder(&buf).Encode(v); err != nil { + b, err := toml.Marshal(v) + if err != nil { return err } r.Header.Set("Content-Type", "application/toml; charset=utf-8") - return r.Write(bytes.NewReader(buf.Bytes())) + return r.Write(bytes.NewReader(b)) } // WriteYAML writes an "application/yaml" content encoded from the v to the // client. func (r *Response) WriteYAML(v interface{}) error { - buf := bytes.Buffer{} - if err := yaml.NewEncoder(&buf).Encode(v); err != nil { + b, err := yaml.Marshal(v) + if err != nil { return err } r.Header.Set("Content-Type", "application/yaml; charset=utf-8") - return r.Write(bytes.NewReader(buf.Bytes())) + return r.Write(bytes.NewReader(b)) } // WriteFile writes a file content targeted by the filename to the client.