github.com/lestrrat-go/jwx/v2@v2.0.21/jwt/io.go (about)

     1  // Code generated by tools/cmd/genreadfile/main.go. DO NOT EDIT.
     2  
     3  package jwt
     4  
     5  import (
     6  	"io/fs"
     7  	"os"
     8  )
     9  
    10  type sysFS struct{}
    11  
    12  func (sysFS) Open(path string) (fs.File, error) {
    13  	return os.Open(path)
    14  }
    15  
    16  func ReadFile(path string, options ...ReadFileOption) (Token, error) {
    17  	var parseOptions []ParseOption
    18  	for _, option := range options {
    19  		if po, ok := option.(ParseOption); ok {
    20  			parseOptions = append(parseOptions, po)
    21  		}
    22  	}
    23  
    24  	var srcFS fs.FS = sysFS{}
    25  	for _, option := range options {
    26  		switch option.Ident() {
    27  		case identFS{}:
    28  			srcFS = option.Value().(fs.FS)
    29  		}
    30  	}
    31  
    32  	f, err := srcFS.Open(path)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	defer f.Close()
    38  	return ParseReader(f, parseOptions...)
    39  }