package ioutil import ( "encoding/json" "io" "io/ioutil" validator "gopkg.in/go-playground/validator.v9" ) var Validate = validator.New() func ExtractJSON(reader io.Reader, vv ...interface{}) error { data, err := ioutil.ReadAll(reader) if err != nil { return err } for _, v := range vv { if err := json.Unmarshal(data, v); err != nil { return err } } return nil } func ExtractAndValidateJSON(reader io.Reader, vv ...interface{}) error { data, err := ioutil.ReadAll(reader) if err != nil { return err } for _, v := range vv { if err := json.Unmarshal(data, v); err != nil { return err } if err := Validate.Struct(v); err != nil { return err } } return nil }