Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func GetToken (shoperAccount *ShoperAccount) {
- logPass := b64.StdEncoding.EncodeToString([]byte((*shoperAccount).ShoperLogin + ":" + (*shoperAccount).ShoperPassword))
- req, errorRequest := http.NewRequest("POST", (*shoperAccount).ApiUrl + "/auth", nil)
- req.Header.Set("Authorization", "Basic " + logPass)
- req.Header.Set("Accept", "application/json")
- req.Header.Set("Content-Type", "application/json")
- req.Header.Set("User-Agent", "python-requests/2.11.1")
- client := &http.Client{}
- resp, errorRequest := client.Do(req)
- if errorRequest != nil {
- panic(errorRequest)
- }
- if resp.StatusCode != 200 {
- panic("Wrong login or password - error in get token")
- }
- defer resp.Body.Close()
- var v interface{}
- json.NewDecoder(resp.Body).Decode(&v)
- for key, value := range v.(map[string]interface{}) {
- switch key {
- case "access_token":
- (*shoperAccount).Token = value.(string)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement