32 lines
538 B
Go
32 lines
538 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
"io/ioutil"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func checkLogin(username, password string) (bool, error) {
|
||
|
j, err := json.Marshal(map[string]string{
|
||
|
"username": username,
|
||
|
"password": password,
|
||
|
})
|
||
|
if err != nil {
|
||
|
return false, err
|
||
|
}
|
||
|
|
||
|
resp, err := http.Post(URLLogin, "application/json", bytes.NewReader(j))
|
||
|
if err != nil {
|
||
|
return false, err
|
||
|
}
|
||
|
|
||
|
if resp.StatusCode != http.StatusOK {
|
||
|
cnt, _ := ioutil.ReadAll(resp.Body)
|
||
|
return false, errors.New(string(cnt))
|
||
|
}
|
||
|
|
||
|
return true, nil
|
||
|
}
|