11package apirequest
22
3- import (
4- "net/http"
5- "net/url"
3+ import (
4+ "bytes"
65 "github.com/Didjacome/hmac-veracode/hmac"
76 "io"
7+ "net/http"
8+ "net/url"
89 "os"
9- "bytes "
10+ "log "
1011)
1112
12- func ApiRequest (apiKeyID , apiKeySecret , apiUrl , httpMethod string ) string {
13+ func ApiRequest (apiKeyID , apiKeySecret , apiUrl , httpMethod string ) ( string ) {
1314 parsedUrl , err := url .Parse (apiUrl )
1415 if err != nil {
15- panic ( err )
16+ log . Fatalf ( "Error for Url Parse: %v" , err )
1617 }
1718
1819 client := & http.Client {}
1920
2021 req , err := http .NewRequest (httpMethod , parsedUrl .String (), nil )
2122 if err != nil {
22- panic ( err )
23+ log . Fatalf ( "Error creating Request: %v" , err )
2324 }
2425
2526 authorizationHeader , err := hmac .CalculateAuthorizationHeader (parsedUrl , httpMethod , apiKeyID , apiKeySecret )
2627 if err != nil {
27- panic ( err )
28+ log . Fatalf ( "Error for calculating hmac: %v" , err )
2829 }
2930
3031 req .Header .Add ("Authorization" , authorizationHeader )
3132
3233 resp , err := client .Do (req )
3334 if err != nil {
34- panic ( err )
35+ log . Fatalf ( "api response error validate your credentials or uri: %v" , err )
3536 }
3637 if resp .StatusCode != http .StatusOK {
3738 panic ("Expected status 200. Status was: " + resp .Status )
@@ -42,7 +43,6 @@ func ApiRequest(apiKeyID, apiKeySecret, apiUrl, httpMethod string) string {
4243 panic (err )
4344 }
4445
45-
4646 file , err := os .Create ("response.json" )
4747 if err != nil {
4848 panic (err )
0 commit comments