本文整理汇总了Golang中net/url.Values.Del方法的典型用法代码示例。如果您正苦于以下问题:Golang Values.Del方法的具体用法?Golang Values.Del怎么用?Golang Values.Del使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/url.Values
的用法示例。
在下文中一共展示了Values.Del方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestApiCreateEvent_400
func TestApiCreateEvent_400(t *testing.T) {
var genParams = func(omitName string) url.Values {
params := url.Values{
"title": []string{"test tour title"},
"link": []string{"http://www.example.com/"},
"image_link": []string{"http://www.example.com/img.png"},
}
params.Del(omitName)
return params
}
test.RunTestServer(func(ts *test.TestServer) {
assert := test.NewAssert(t)
test.DatastoreFixture(ts.Context, "./fixtures/TestApiCreateEventShow.json", nil)
p := app.TestApp().Api.Path("/events/")
var testOmitParams = []string{
"title", "link", "image_link",
}
for _, paramName := range testOmitParams {
req := ts.PostForm(p, genParams(paramName))
lib.SetApiTokenForTest(req, lib.Admin)
res := req.RouteTo(app.TestApp().Routes())
assert.HttpStatus(400, res)
}
})
}
示例2: TestV2UpdateKeySuccessWithTTL
// Ensures that a key could update TTL.
//
// $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX
// $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX -d ttl=1000 -d prevExist=true
// $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX -d ttl= -d prevExist=true
//
func TestV2UpdateKeySuccessWithTTL(t *testing.T) {
tests.RunServer(func(s *server.Server) {
v := url.Values{}
v.Set("value", "XXX")
resp, _ := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo"), v)
assert.Equal(t, resp.StatusCode, http.StatusCreated)
node := (tests.ReadBodyJSON(resp)["node"]).(map[string]interface{})
createdIndex := node["createdIndex"]
v.Set("ttl", "1000")
v.Set("prevExist", "true")
resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo"), v)
assert.Equal(t, resp.StatusCode, http.StatusOK)
node = (tests.ReadBodyJSON(resp)["node"]).(map[string]interface{})
assert.Equal(t, node["value"], "XXX", "")
assert.Equal(t, node["ttl"], 1000, "")
assert.NotEqual(t, node["expiration"], "", "")
assert.Equal(t, node["createdIndex"], createdIndex, "")
v.Del("ttl")
resp, _ = tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo"), v)
assert.Equal(t, resp.StatusCode, http.StatusOK)
node = (tests.ReadBodyJSON(resp)["node"]).(map[string]interface{})
assert.Equal(t, node["value"], "XXX", "")
assert.Equal(t, node["ttl"], nil, "")
assert.Equal(t, node["expiration"], nil, "")
assert.Equal(t, node["createdIndex"], createdIndex, "")
})
}
示例3: Path
func (ph *patHandler) Path(values ...url.Values) string {
// TODO refactor to build string in place or from preprocessed parts
// find captures
var i int
captures := make([]string, 0)
for i < len(ph.pat) {
switch {
default:
i++
case ph.pat[i] == ':':
var name string
name, _, i = match(ph.pat, isAlnum, i+1)
captures = append(captures, name)
}
}
// setup url values
v := url.Values{}
if len(values) > 0 {
v = values[0]
}
path := ph.pat
for _, capture := range captures {
first := v.Get(capture)
path = strings.Replace(path, ":"+capture, first, -1)
v.Del(capture)
}
if query := v.Encode(); len(query) > 0 {
path += strings.Join([]string{"?", query}, "")
}
return path
}
示例4: EditValues
func (c *testCustomizer) EditValues(m url.Values) {
for k := range m {
if k == "b" {
m.Del(k)
}
}
}
示例5: SetValue
// SetValue modifies the values.
func (ep EnumParam) SetValue(values url.Values, pname string, uinter enums.Uinter) (string, *bool) {
this := uinter.Touint()
_, low, err := uinter.Marshal()
if err != nil { // ignoring the error
return "", nil
}
text := ep.EnumDecodec.Text(strings.ToUpper(low))
ddef := ep.EnumDecodec.Default.Uint
dnum := ep.Number
// Default ordering is desc (values are numeric most of the time).
// Alpha values ordering: asc.
desc := !ep.IsAlpha(this)
if dnum.Negative {
desc = !desc
}
var ret *bool
if this == dnum.Uint {
ret = new(bool)
*ret = !desc
}
// for default, opposite of having a parameter is it's absence.
if this == ddef && ep.Specified {
values.Del(pname)
return text, ret
}
if this == dnum.Uint && !dnum.Negative && !ep.EnumDecodec.OnlyPositive {
low = "-" + low
}
values.Set(pname, low)
return text, ret
}
示例6: GetMessagesInRange
// GetMessagesInRange gets an Iterator containing calls in the range [start,
// end), optionally further filtered by data. GetMessagesInRange panics if
// start is not before end. Any date filters provided in data will be ignored.
// If you have an end, but don't want to specify a start, use twilio.Epoch for
// start. If you have a start, but don't want to specify an end, use
// twilio.HeatDeath for end.
//
// Assumes that Twilio returns resources in chronological order, latest
// first. If this assumption is incorrect, your results will not be correct.
//
// Returned MessagePages will have at most PageSize results, but may have
// fewer, based on filtering.
func (c *MessageService) GetMessagesInRange(start time.Time, end time.Time, data url.Values) MessagePageIterator {
if start.After(end) {
panic("start date is after end date")
}
d := url.Values{}
if data != nil {
for k, v := range data {
d[k] = v
}
}
d.Del("DateSent")
d.Del("Page") // just in case
// Omit these parameters if they are the sentinel values, since I think
// that API paging will be faster.
if start != Epoch {
startFormat := start.UTC().Format(APISearchLayout)
d.Set("DateSent>", startFormat)
}
if end != HeatDeath {
// If you specify "DateSent<=YYYY-MM-DD", the *latest* result returned
// will be midnight (the earliest possible second) on DD. We want all of
// the results for DD so we need to specify DD+1 in the API.
//
// TODO validate midnight-instant math more closely, since I don't think
// Twilio returns the correct results for that instant.
endFormat := end.UTC().Add(24 * time.Hour).Format(APISearchLayout)
d.Set("DateSent<", endFormat)
}
iter := NewPageIterator(c.client, d, messagesPathPart)
return &messageDateIterator{
start: start,
end: end,
p: iter,
}
}
示例7: Test_NutrientReport
func Test_NutrientReport(t *testing.T) {
nutrientsIDs := []string{"204", "205", "208", "269"}
v := url.Values{}
v.Set("max", "12")
//All foods
_, err := api.GetNutrientReport(nutrientsIDs, v)
if err != nil {
t.Fatal(err)
}
//For food groups Dairy and Egg Products (id = 0100) and Poultry Products (id=0500)
v.Add("fg", "0100")
v.Add("fg", "0500")
_, err = api.GetNutrientReport(nutrientsIDs, v)
if err != nil {
t.Fatal(err)
}
v.Del("fg")
//For chedder cheese (ndbno 01009) only:
v.Set("ndbno", "01009")
_, err = api.GetNutrientReport(nutrientsIDs, v)
if err != nil {
t.Fatal(err)
}
}
示例8: GetCallsInRange
// GetCallsInRange gets an Iterator containing calls in the range [start, end),
// optionally further filtered by data. GetCallsInRange panics if start is not
// before end. Any date filters provided in data will be ignored. If you have
// an end, but don't want to specify a start, use twilio.Epoch for start. If
// you have a start, but don't want to specify an end, use twilio.HeatDeath for
// end.
//
// Assumes that Twilio returns resources in chronological order, latest
// first. If this assumption is incorrect, your results will not be correct.
//
// Returned CallPages will have at most PageSize results, but may have fewer,
// based on filtering.
func (c *CallService) GetCallsInRange(start time.Time, end time.Time, data url.Values) CallPageIterator {
if start.After(end) {
panic("start date is after end date")
}
d := url.Values{}
if data != nil {
for k, v := range data {
d[k] = v
}
}
d.Del("StartTime")
d.Del("Page") // just in case
if start != Epoch {
startFormat := start.UTC().Format(APISearchLayout)
d.Set("StartTime>", startFormat)
}
if end != HeatDeath {
// If you specify "StartTime<=YYYY-MM-DD", the *latest* result returned
// will be midnight (the earliest possible second) on DD. We want all
// of the results for DD so we need to specify DD+1 in the API.
//
// TODO validate midnight-instant math more closely, since I don't think
// Twilio returns the correct results for that instant.
endFormat := end.UTC().Add(24 * time.Hour).Format(APISearchLayout)
d.Set("StartTime<", endFormat)
}
iter := NewPageIterator(c.client, d, callsPathPart)
return &callDateIterator{
start: start,
end: end,
p: iter,
}
}
示例9: TestApiCreateEventShow_400
func TestApiCreateEventShow_400(t *testing.T) {
var genParams = func(omitName string) url.Values {
params := url.Values{
"open_at": []string{"2015-01-02T06:00:00Z"},
"start_at": []string{"2015-01-02T07:00:00Z"},
"latitude": []string{"37.39"},
"longitude": []string{"140.38"},
"venue_id": []string{"153237058036933"},
"venue_name": []string{"郡山市民文化センター"},
"pia_link": []string{"http://pia.jp/link"},
"ya_keyword": []string{"郡山"},
}
params.Del(omitName)
return params
}
test.RunTestServer(func(ts *test.TestServer) {
assert := test.NewAssert(t)
test.DatastoreFixture(ts.Context, "./fixtures/TestApiCreateEventShow.json", nil)
p := app.TestApp().Api.Path("/events/event1/shows")
var testOmitParams = []string{
"open_at", "start_at", "latitude", "longitude", "venue_id", "venue_name", // "pia_link", "ya_keyword",
}
for _, paramName := range testOmitParams {
req := ts.PostForm(p, genParams(paramName))
lib.SetApiTokenForTest(req, lib.Admin)
res := req.RouteTo(app.TestApp().Routes())
assert.HttpStatus(400, res)
}
})
}
示例10: collectParameters
// collectParameters collects parameters from the request.
//
// See RFC 5849 Section 3.4.1.3.1.
func collectParameters(req *http.Request, extra url.Values) (url.Values, error) {
params, err := parseAuthorizationHeader(req)
if err != nil {
return nil, err
}
rv := url.Values{}
err = req.ParseForm()
if err == nil {
for k := range req.Form {
for _, v := range req.Form[k] {
rv.Add(k, v)
}
}
}
for k := range params {
for _, v := range params[k] {
rv.Add(k, v)
}
}
for k := range extra {
for _, v := range extra[k] {
rv.Add(k, v)
}
}
rv.Del("oauth_signature")
return rv, nil
}
示例11: changeYear
// ChangeYear changes the yeargroup filtered by the query
func changeYear(query url.Values, year string) string {
if _, exists := query["year"]; exists {
query.Del("year")
}
query.Add("year", year)
return query.Encode()
}
示例12: Changes
// Feed the changes.
//
// The handler receives the body of the stream and is expected to consume
// the contents.
func (p Database) Changes(handler ChangeHandler,
options map[string]interface{}) error {
largest := i64defopt(options, "since", 0)
heartbeatTime := i64defopt(options, "heartbeat", 5000)
timeout := time.Minute
if heartbeatTime > 0 {
timeout = time.Millisecond * time.Duration(heartbeatTime*2)
}
for largest >= 0 {
params := url.Values{}
for k, v := range options {
params.Set(k, fmt.Sprintf("%v", v))
}
if largest > 0 {
params.Set("since", fmt.Sprintf("%v", largest))
}
if heartbeatTime > 0 {
params.Set("heartbeat", fmt.Sprintf("%d", heartbeatTime))
} else {
params.Del("heartbeat")
}
full_url := fmt.Sprintf("%s/_changes?%s", p.DBURL(),
params.Encode())
var conn net.Conn
// Swapping out the transport to work around a bug.
client := &http.Client{Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: func(n, addr string) (net.Conn, error) {
var err error
conn, err = net.Dial(n, addr)
return conn, err
},
}}
resp, err := client.Get(full_url)
if err == nil {
func() {
defer resp.Body.Close()
defer conn.Close()
tc := timeoutClient{resp.Body, conn, timeout}
largest = handler(&tc)
}()
} else {
log.Printf("Error in stream: %v", err)
time.Sleep(time.Second * 1)
}
}
return nil
}
示例13: normalizeKeys
func normalizeKeys(v url.Values, normalFunc func(string) string) {
for param, values := range v {
normalizedParam := normalFunc(param)
v.Del(param)
// Mapserv doesn't take multiple values per param
// Save a little time and only set the first one
v.Set(normalizedParam, values[0])
}
}
示例14: GenerateDotString
func GenerateDotString(res []struct {
ANAME string
BNAME string
AID int
BID int
RELKIND string
RELID int
URLS []string
}, attrs url.Values) string {
attrs.Del("url")
attrs.Del("r")
// split our slice in a slice with only nodes and a slice with only rels
var splitAt int
for index, row := range res {
if row.BNAME != "" {
splitAt = index
break
}
}
graphName := "nodes"
g := gographviz.NewGraph()
g.SetName(graphName)
g.SetDir(true)
g.AddAttr(graphName, "size", "\"15,1000\"")
g.AddAttr(graphName, "ratio", "compress")
for k := range attrs {
g.AddAttr(graphName, k, attrs.Get(k))
}
// add nodes
for _, row := range res[:splitAt] {
g.AddNode(graphName, strconv.Itoa(row.AID), map[string]string{
"id": strconv.Itoa(row.AID),
"label": nodeTable(row.ANAME, row.URLS),
"shape": "box",
"fontname": "Verdana",
"fontsize": "9",
})
}
// add edges
for _, row := range res[splitAt:] {
g.AddEdge(strconv.Itoa(row.AID), strconv.Itoa(row.BID), true, map[string]string{
"id": strconv.Itoa(row.RELID),
"label": row.RELKIND,
"dir": relationshipDir(row.RELKIND),
"tooltip": row.RELKIND,
"fontname": "Verdana",
"fontsize": "9",
})
}
return g.String()
}
示例15: QuerySet
// QuerySet modifies the values.
func (bp BoolParam) QuerySet(values url.Values, value bool) {
if values == nil {
values = bp.Query.Values
}
if value == bp.BoolDecodec.Default {
values.Del(bp.BoolDecodec.Pname)
} else {
values.Set(bp.BoolDecodec.Pname, "")
}
}