github.com/searKing/golang/go@v1.2.117/io/dynamic.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package io
     6  
     7  import "io"
     8  
     9  // DynamicReaderFunc returns a Reader that's from
    10  // the provided input reader getter function.
    11  type DynamicReaderFunc func() io.Reader
    12  
    13  func (f DynamicReaderFunc) Read(p []byte) (n int, err error) {
    14  	var r io.Reader
    15  	if f != nil {
    16  		r = f()
    17  	}
    18  	if r == nil {
    19  		r = EOFReader()
    20  	}
    21  	return r.Read(p)
    22  }