request/file.go

44 lines
858 B
Go
Raw Normal View History

package request
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"github.com/fatih/structs"
)
// File reads request json file
2019-06-20 00:33:48 +00:00
func File(path string) ([]byte, *HTTPError) {
jsonFile, err := os.Open(path)
if err != nil {
2019-06-20 00:33:48 +00:00
log.Println("Error reading request. ", err)
return nil, &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
}
func Contact() map[string]interface{} {
var contact Contacts
2019-06-20 00:39:24 +00:00
resp, err := File("./assets/json/contacts.json")
2019-06-20 00:33:48 +00:00
if err != nil {
m := structs.Map(err)
return m
}
json.Unmarshal(resp, &contact)
m := structs.Map(contact)
return m
}
2019-06-20 00:33:48 +00:00
func Header() (headers *Headers, err *HTTPError) {
2019-06-20 00:39:24 +00:00
resp, err := File("./assets/json/headers.json")
2019-06-20 00:33:48 +00:00
if err != nil {
return
}
json.Unmarshal(resp, &headers)
return
}