github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/jsonhelper/jsonhelper.go (about)

     1  package jsonhelper
     2  
     3  import (
     4  	"encoding/json"
     5  	"os"
     6  )
     7  
     8  func LoadAndDecodeDisallowUnknownFields(path string, v any) error {
     9  	f, err := os.Open(path)
    10  	if err != nil {
    11  		return err
    12  	}
    13  	defer f.Close()
    14  
    15  	d := json.NewDecoder(f)
    16  	d.DisallowUnknownFields()
    17  	return d.Decode(v)
    18  }