示例#1
0
// Logout -
func (s *harborAuthClient) Logout(username string, token string) (bool, error) {
	if !govalidator.IsAlpha(username) {
		return false, errors.New("Usernames must be alphabetical")
	}

	if len(token) == 0 {
		return false, errors.New("Empty token")
	}

	in := logoutIn{}
	in.Username = username
	in.Token = token
	inBuf, err := json.Marshal(in)

	fullURL := s.url + "/v1/auth/destroytoken"
	req, err := http.NewRequest("POST", fullURL, bytes.NewBuffer(inBuf))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println(err.Error())
		return false, err
	}

	defer resp.Body.Close()

	status := resp.StatusCode
	if status != 200 {
		return false, errors.New("Invalid Status Code: " + resp.Status)
	}

	responseBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return false, errors.New("Error in ReadAll")
	}

	var out logoutOut
	json.Unmarshal(responseBody, &out)

	// Need to verify output before returning

	return out.Success, nil
}
示例#2
0
func (i IsAlphaChecker) IsFormat(data string) bool {
	return govalidator.IsAlpha(data)
}
示例#3
0
func (s *service) IsAlpha(str string) bool                   { return gov.IsAlpha(str) }
示例#4
0
文件: checkers.go 项目: jwulf/zedlist
func isName(name string) bool {
	if name != "" {
		return validate.IsAlpha(name)
	}
	return true
}