readerfactory.go (403B)
1 package utilities 2 3 import ( 4 "bytes" 5 "io" 6 "io/ioutil" 7 ) 8 9 // IOReaderFactory takes in an io.Reader and returns a function that will allow you to create a new reader that begins 10 // at the start of the stream 11 func IOReaderFactory(r io.Reader) (func() io.Reader, error) { 12 b, err := ioutil.ReadAll(r) 13 if err != nil { 14 return nil, err 15 } 16 17 return func() io.Reader { 18 return bytes.NewReader(b) 19 }, nil 20 }