2019-06-13 17:11:42 +00:00
|
|
|
package request
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2019-06-26 01:56:55 +00:00
|
|
|
"0cd.xyz-go/logger"
|
2019-06-13 17:11:42 +00:00
|
|
|
"github.com/fatih/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// File reads request json file
|
2019-06-26 01:56:55 +00:00
|
|
|
func File(path string) ([]byte, *logger.HTTPError) {
|
2019-06-13 17:11:42 +00:00
|
|
|
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}
|
2019-06-13 17:11:42 +00:00
|
|
|
}
|
|
|
|
defer jsonFile.Close()
|
|
|
|
byteValue, _ := ioutil.ReadAll(jsonFile)
|
2019-06-20 00:33:48 +00:00
|
|
|
return byteValue, nil
|
2019-06-13 17:11:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 00:41:18 +00:00
|
|
|
// Header get header data from json file
|
2019-06-26 01:56:55 +00:00
|
|
|
func Header() (headers *Headers, err *logger.HTTPError) {
|
|
|
|
resp, err := File("./assets/json/headers.json")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
json.Unmarshal(resp, &headers)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-27 00:41:18 +00:00
|
|
|
// Option get options data from json file
|
2019-06-26 01:56:55 +00:00
|
|
|
func Option() (options *Options) {
|
|
|
|
resp, err := File("./assets/json/options.json")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
json.Unmarshal(resp, &options)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-27 00:41:18 +00:00
|
|
|
// Contact get contact information from json file
|
2019-06-13 17:11:42 +00:00
|
|
|
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)
|
2019-06-13 17:11:42 +00:00
|
|
|
m := structs.Map(contact)
|
|
|
|
return m
|
|
|
|
}
|