Last active
March 26, 2019 18:32
-
-
Save MuthukumarHelios/79ef131001a9f8fb5b2b4232c63c6b50 to your computer and use it in GitHub Desktop.
heimdall failing for ngnix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "github.com/gorilla/mux"" | |
func GetRequestWithRawHttp(w http.ResponseWriter, r *http.Request) { | |
api := "http://13.126.204.154/api/excel-report/v1/smart/live?reportName=agencyPerformanceReport&itemsperpage=10&pageNo=1&from=2018-02-22T12:10:19.441Z&to=2019-04-22T12:10:19.441Z" | |
httpC := &http.Client{} | |
req, err := http.NewRequest("GET", api, nil) | |
tokenValue := r.Header["Authorization"] | |
fmt.Println(tokenValue) | |
req.Header.Add("Authorization", tokenValue[0]) | |
resp, err := httpC.Do(req) | |
data, err := ioutil.ReadAll(resp.Body) | |
var errorResponse *interface{} | |
if resp.StatusCode != 200 { | |
json.Unmarshal(data, &errorResponse) | |
utils.ResponseWith(w, resp.StatusCode, errorResponse) | |
return | |
} | |
fmt.Println("--err", err, resp.StatusCode) | |
fmt.Println("--data", data) | |
w.Write(data) | |
return | |
} | |
//Heimdall Code | |
func GetRequestWithHeimdall(w http.ResponseWriter, r *http.Request) { | |
timeout := 1000 * time.Second | |
client := httpclient.NewClient(httpclient.WithHTTPTimeout(timeout)) | |
api := "http://13.126.204.154/api/excel-report/v1/smart/live?reportName=agencyPerformanceReport&itemsperpage=10&pageNo=1&from=2018-02-22T12:10:19.441Z&to=2019-04-22T12:10:19.441Z" | |
// api := constants.BaseUrl + constants.ApiVersion + "/manifests/4ffba45f-a10d-4b63-8b19-cb1e4104f1e5" | |
req, err := client.Get(api, r.Header) | |
if err != nil { | |
utils.ResponseWith(w, req.StatusCode, err.Error()) | |
return | |
} | |
fmt.Println("--after") | |
data, err := ioutil.ReadAll(req.Body) | |
fmt.Println("--err", err, req.StatusCode) | |
// fmt.Fprintf(w, string(data)) | |
w.Write(data) | |
// utils.ResponseWith(w, req.St | |
return | |
} | |
func main(){ | |
r := mux.NewRouter() | |
r.HandleFunc("/api/rawhttp", GetRequestWithRawHttp).Methods("GET") | |
r.HandleFunc("/api/heimdall", GetRequestWithHeimdall).Methods("GET") | |
port :=":3016" | |
fmt.Println("your app running on " + port) | |
http.ListenAndServe(port,r) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
edit made for response with different behavior