moved api to options

This commit is contained in:
Michael 2019-07-05 16:47:28 +01:00
parent 762d3c875a
commit f29175fb66
3 changed files with 9 additions and 24 deletions

11
api.go
View File

@ -60,12 +60,11 @@ func Request(path string) ([]byte, *logger.HTTPError) {
return nil, logger.HTTPErr(http.StatusInternalServerError)
}
head, er := Header()
if er != nil {
return nil, er
}
for _, headers := range head.Headers {
req.Header.Set(headers.Name, headers.Value)
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
ap := Option().Options
for _, api := range ap.API {
req.Header.Set(api.Name, api.Value)
}
client := &http.Client{Timeout: time.Second * 10}

12
data.go
View File

@ -4,14 +4,6 @@ import (
"time"
)
// Headers API request headers
type Headers struct {
Headers []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"headers"`
}
// Options main program options
type Options struct {
Title string `json:"title"`
@ -24,6 +16,10 @@ type Options struct {
DynamicReload bool `json:"DynamicReload"`
BaseDir string `json:"BaseDir"`
} `json:"ace"`
API []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"api"`
} `json:"options"`
Database struct {
Server string `json:"server"`

10
file.go
View File

@ -22,16 +22,6 @@ func File(path string) ([]byte, *logger.HTTPError) {
return byteValue, nil
}
// Header get header data from json file
func Header() (headers *Headers, err *logger.HTTPError) {
resp, err := File("./assets/json/headers.json")
if err != nil {
return
}
json.Unmarshal(resp, &headers)
return
}
// Option get options data from json file
func Option() (options *Options) {
resp, err := File("./assets/json/options.json")