github.com/turingchain2020/turingchain@v1.1.21/executor/authority/utils/io.go (about) 1 // Copyright Turing Corp. 2018 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 utils 6 7 import ( 8 "encoding/pem" 9 "fmt" 10 "io/ioutil" 11 ) 12 13 // ReadFile 读取文件 14 func ReadFile(file string) ([]byte, error) { 15 fileCont, err := ioutil.ReadFile(file) 16 if err != nil { 17 return nil, fmt.Errorf("Could not read file %s, err %s", file, err) 18 } 19 20 return fileCont, nil 21 } 22 23 // ReadPemFile 读取pem文件 24 func ReadPemFile(file string) ([]byte, error) { 25 bytes, err := ReadFile(file) 26 if err != nil { 27 return nil, err 28 } 29 30 b, _ := pem.Decode(bytes) 31 if b == nil { 32 return nil, fmt.Errorf("No pem content for file %s", file) 33 } 34 35 return bytes, nil 36 }