代码拉取完成,页面将自动刷新
同步操作将从 tupelo-shen/mysnapd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2020 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package client
import (
"bytes"
"encoding/json"
"fmt"
"net/url"
"golang.org/x/xerrors"
)
// ValidateApplyOptions carries options for ApplyValidationSet.
type ValidateApplyOptions struct {
Mode string
Sequence int
}
// ValidationSetResult holds information about a single validation set.
type ValidationSetResult struct {
AccountID string `json:"account-id"`
Name string `json:"name"`
Sequence int `json:"sequence,omitempty"`
PinnedAt int `json:"pinned-at,omitempty"`
Mode string `json:"mode"`
Valid bool `json:"valid"`
// TODO: flags/states for notes column
}
type postValidationSetData struct {
Action string `json:"action"`
Mode string `json:"mode,omitempty"`
Sequence int `json:"sequence,omitempty"`
}
// ForgetValidationSet forgets the given validation set identified by account,
// name and optional sequence (if non-zero).
func (client *Client) ForgetValidationSet(accountID, name string, sequence int) error {
if accountID == "" || name == "" {
return xerrors.Errorf("cannot forget validation set without account ID and name")
}
data := &postValidationSetData{
Action: "forget",
Sequence: sequence,
}
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(data); err != nil {
return err
}
path := fmt.Sprintf("/v2/validation-sets/%s/%s", accountID, name)
if _, err := client.doSync("POST", path, nil, nil, &body, nil); err != nil {
fmt := "cannot forget validation set: %w"
return xerrors.Errorf(fmt, err)
}
return nil
}
// ApplyValidationSet applies the given validation set identified by account and name and returns
// the new validation set tracking info. For monitoring mode the returned res may indicate invalid
// state.
func (client *Client) ApplyValidationSet(accountID, name string, opts *ValidateApplyOptions) (res *ValidationSetResult, err error) {
if accountID == "" || name == "" {
return nil, xerrors.Errorf("cannot apply validation set without account ID and name")
}
data := &postValidationSetData{
Action: "apply",
Mode: opts.Mode,
Sequence: opts.Sequence,
}
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(data); err != nil {
return nil, err
}
path := fmt.Sprintf("/v2/validation-sets/%s/%s", accountID, name)
if _, err := client.doSync("POST", path, nil, nil, &body, &res); err != nil {
fmt := "cannot apply validation set: %w"
return nil, xerrors.Errorf(fmt, err)
}
return res, nil
}
// ListValidationsSets queries all validation sets.
func (client *Client) ListValidationsSets() ([]*ValidationSetResult, error) {
var res []*ValidationSetResult
if _, err := client.doSync("GET", "/v2/validation-sets", nil, nil, nil, &res); err != nil {
fmt := "cannot list validation sets: %w"
return nil, xerrors.Errorf(fmt, err)
}
return res, nil
}
// ValidationSet queries the given validation set identified by account/name.
func (client *Client) ValidationSet(accountID, name string, sequence int) (*ValidationSetResult, error) {
if accountID == "" || name == "" {
return nil, xerrors.Errorf("cannot query validation set without account ID and name")
}
q := url.Values{}
if sequence != 0 {
q.Set("sequence", fmt.Sprintf("%d", sequence))
}
var res *ValidationSetResult
path := fmt.Sprintf("/v2/validation-sets/%s/%s", accountID, name)
if _, err := client.doSync("GET", path, q, nil, nil, &res); err != nil {
fmt := "cannot query validation set: %w"
return nil, xerrors.Errorf(fmt, err)
}
return res, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。