request/file.go

22 lines
437 B
Go
Raw Normal View History

package request
import (
"io/ioutil"
"log"
"os"
2019-06-26 01:56:55 +00:00
"0cd.xyz-go/logger"
)
// File reads request json file
2019-06-26 01:56:55 +00:00
func File(path string) ([]byte, *logger.HTTPError) {
jsonFile, err := os.Open(path)
if err != nil {
2019-06-20 00:33:48 +00:00
log.Println("Error reading request. ", err)
2019-06-26 01:56:55 +00:00
return nil, &logger.HTTPError{Status: "500 Internal Server Error", StatusCode: 500}
}
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
2019-06-20 00:33:48 +00:00
return byteValue, nil
}