Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. func GetToken (shoperAccount *ShoperAccount) {
  2. logPass := b64.StdEncoding.EncodeToString([]byte((*shoperAccount).ShoperLogin + ":" + (*shoperAccount).ShoperPassword))
  3. req, errorRequest := http.NewRequest("POST", (*shoperAccount).ApiUrl + "/auth", nil)
  4. req.Header.Set("Authorization", "Basic " + logPass)
  5. req.Header.Set("Accept", "application/json")
  6. req.Header.Set("Content-Type", "application/json")
  7. req.Header.Set("User-Agent", "python-requests/2.11.1")
  8. client := &http.Client{}
  9. resp, errorRequest := client.Do(req)
  10.  
  11. if errorRequest != nil {
  12. panic(errorRequest)
  13. }
  14. if resp.StatusCode != 200 {
  15. panic("Wrong login or password - error in get token")
  16. }
  17. defer resp.Body.Close()
  18. var v interface{}
  19. json.NewDecoder(resp.Body).Decode(&v)
  20.  
  21. for key, value := range v.(map[string]interface{}) {
  22. switch key {
  23. case "access_token":
  24. (*shoperAccount).Token = value.(string)
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement