mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-06 18:50:09 +01:00
29 lines
629 B
Plaintext
29 lines
629 B
Plaintext
// HarborLogon.go
|
|
package HarborAPI
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
func (a HarborAPI) HarborLogin(user UsrInfo) (int, error) {
|
|
|
|
v := url.Values{}
|
|
v.Set("principal", user.Name)
|
|
v.Set("password", user.Passwd)
|
|
|
|
body := ioutil.NopCloser(strings.NewReader(v.Encode())) //endode v:[body struce]
|
|
|
|
client := &http.Client{}
|
|
reqest, err := http.NewRequest("POST", a.basePath+"/login", body)
|
|
|
|
reqest.Header.Set("Content-Type", "application/x-www-form-urlencoded;param=value") //setting post head
|
|
|
|
resp, err := client.Do(reqest)
|
|
defer resp.Body.Close() //close resp.Body
|
|
|
|
return resp.StatusCode, err
|
|
}
|