This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
adlin/pkg/login-app/cmd/login.go

32 lines
647 B
Go
Raw Normal View History

2018-02-10 12:54:18 +00:00
package main
import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
)
type loginForm struct {
Username string `json:"username"`
Password string `json:"password"`
Force *bool `json:"force,omitempty"`
}
func checkLogin(username, password string, force *bool) (int, error) {
j, err := json.Marshal(loginForm{Username: username, Password: password, Force: force})
2018-02-10 12:54:18 +00:00
if err != nil {
return 0, err
2018-02-10 12:54:18 +00:00
}
resp, err := http.Post(URLLogin, "application/json", bytes.NewReader(j))
if err != nil {
return 0, err
2018-02-10 12:54:18 +00:00
}
2019-02-26 22:48:01 +00:00
defer resp.Body.Close()
2018-02-10 12:54:18 +00:00
2019-02-26 22:48:01 +00:00
cnt, _ := ioutil.ReadAll(resp.Body)
return resp.StatusCode, errors.New(string(cnt))
2018-02-10 12:54:18 +00:00
}