Switch to DecodeFile because it's cleaner

This commit is contained in:
comp500 2019-04-27 14:22:59 +01:00
parent 2e4ddb667f
commit db7c837bfa
No known key found for this signature in database
GPG Key ID: 214C822FFEC586B5
2 changed files with 2 additions and 12 deletions

View File

@ -4,7 +4,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -33,12 +32,8 @@ type IndexFile struct {
// LoadIndex attempts to load the index file from a path // LoadIndex attempts to load the index file from a path
func LoadIndex(indexFile string, flags Flags) (Index, error) { func LoadIndex(indexFile string, flags Flags) (Index, error) {
data, err := ioutil.ReadFile(indexFile)
if err != nil {
return Index{}, err
}
var index Index var index Index
if _, err := toml.Decode(string(data), &index); err != nil { if _, err := toml.DecodeFile(indexFile, &index); err != nil {
return Index{}, err return Index{}, err
} }
index.flags = flags index.flags = flags

View File

@ -3,7 +3,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -27,12 +26,8 @@ type Pack struct {
// LoadPack loads the modpack metadata to a Pack struct // LoadPack loads the modpack metadata to a Pack struct
func LoadPack(flags Flags) (Pack, error) { func LoadPack(flags Flags) (Pack, error) {
data, err := ioutil.ReadFile(flags.PackFile)
if err != nil {
return Pack{}, err
}
var modpack Pack var modpack Pack
if _, err := toml.Decode(string(data), &modpack); err != nil { if _, err := toml.DecodeFile(flags.PackFile, &modpack); err != nil {
return Pack{}, err return Pack{}, err
} }