-
Notifications
You must be signed in to change notification settings - Fork 47
/
read_files.go
46 lines (37 loc) · 952 Bytes
/
read_files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Copyright (c) 2021 - Present. Blend Labs, Inc. All rights reserved
Use of this source code is governed by a MIT license that can be found in the LICENSE file.
*/
package certutil
import (
"io/ioutil"
"github.com/blend/go-sdk/ex"
)
// Errors
const (
ErrInvalidCertPEM ex.Class = "failed to add cert to pool as pem"
)
// MustBytes panics on an error or returns the contents.
func MustBytes(contents []byte, err error) []byte {
if err != nil {
panic(err)
}
return contents
}
// BytesWithError returns a bytes error response with the error
// as an ex.
func BytesWithError(bytes []byte, err error) ([]byte, error) {
return bytes, ex.New(err)
}
// ReadFiles reads a list of files as bytes.
func ReadFiles(files ...string) (data [][]byte, err error) {
var contents []byte
for _, path := range files {
contents, err = ioutil.ReadFile(path)
if err != nil {
return nil, ex.New(err)
}
data = append(data, contents)
}
return
}