api now has to be set in ENV for production
This commit is contained in:
parent
1a2d9265e0
commit
82c31cb3cc
15
api.go
15
api.go
@ -2,10 +2,10 @@ package request
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -28,22 +28,25 @@ func Request(path string) ([]byte, *logger.HTTPError) {
|
||||
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
ap := Option()
|
||||
for _, api := range ap.API {
|
||||
req.Header.Set(api.Name, api.Value)
|
||||
if os.Getenv("GOENV") != "production" {
|
||||
resp := API()
|
||||
for _, api := range resp.API {
|
||||
req.Header.Set(api.Name, api.Value)
|
||||
}
|
||||
} else {
|
||||
req.Header.Set("Api-Key", os.Getenv("GOAPIKEY"))
|
||||
req.Header.Set("Api-Username", os.Getenv("APIUSERNAME"))
|
||||
}
|
||||
|
||||
client := &http.Client{Timeout: time.Second * 10}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.ErrorLog("Error reading request. ", err)
|
||||
fmt.Println(err)
|
||||
return nil, logger.HTTPErr(http.StatusInternalServerError)
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
logger.ErrorLog("Error reading request. ", err)
|
||||
fmt.Println(err)
|
||||
return nil, logger.HTTPErr(http.StatusInternalServerError)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
12
data.go
12
data.go
@ -4,6 +4,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// APIOpt API options
|
||||
type APIOpt struct {
|
||||
API []struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
} `json:"api"`
|
||||
}
|
||||
|
||||
// Options struct for application options
|
||||
type Options struct {
|
||||
Title string `json:"title"`
|
||||
@ -18,10 +26,6 @@ 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"`
|
||||
Database struct {
|
||||
Server string `json:"server"`
|
||||
Db string `json:"db"`
|
||||
|
10
file.go
10
file.go
@ -32,6 +32,16 @@ func Option() (options *Options) {
|
||||
return
|
||||
}
|
||||
|
||||
// API gets api options data from json file
|
||||
func API() (api *APIOpt) {
|
||||
resp, err := File("./assets/json/api.json")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
json.Unmarshal(resp, &api)
|
||||
return
|
||||
}
|
||||
|
||||
// Contact get contact information from json file
|
||||
func Contact() map[string]interface{} {
|
||||
var contact Contacts
|
||||
|
Loading…
Reference in New Issue
Block a user