github.com/daixiang0/gci@v0.13.0/pkg/io/stdin.go (about)

     1  package io
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  )
     7  
     8  type stdInFile struct{}
     9  
    10  func (s stdInFile) Load() ([]byte, error) {
    11  	return ioutil.ReadAll(os.Stdin)
    12  }
    13  
    14  func (s stdInFile) Path() string {
    15  	return "StdIn"
    16  }
    17  
    18  var StdInGenerator FileGeneratorFunc = func() ([]FileObj, error) {
    19  	stat, err := os.Stdin.Stat()
    20  	if err != nil {
    21  		return nil, err
    22  	}
    23  	if (stat.Mode() & os.ModeCharDevice) == 0 {
    24  		return []FileObj{stdInFile{}}, nil
    25  	}
    26  	return []FileObj{}, nil
    27  }