"Fossies" - the Fresh Open Source Software Archive

Member "gdrive-2.1.1/vendor/google.golang.org/api/gensupport/params.go" (28 May 2021, 1255 Bytes) of package /linux/misc/old/gdrive-2.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2015 The Go Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style
    3 // license that can be found in the LICENSE file.
    4 
    5 package gensupport
    6 
    7 import (
    8     "net/url"
    9 
   10     "google.golang.org/api/googleapi"
   11 )
   12 
   13 // URLParams is a simplified replacement for url.Values
   14 // that safely builds up URL parameters for encoding.
   15 type URLParams map[string][]string
   16 
   17 // Get returns the first value for the given key, or "".
   18 func (u URLParams) Get(key string) string {
   19     vs := u[key]
   20     if len(vs) == 0 {
   21         return ""
   22     }
   23     return vs[0]
   24 }
   25 
   26 // Set sets the key to value.
   27 // It replaces any existing values.
   28 func (u URLParams) Set(key, value string) {
   29     u[key] = []string{value}
   30 }
   31 
   32 // SetMulti sets the key to an array of values.
   33 // It replaces any existing values.
   34 // Note that values must not be modified after calling SetMulti
   35 // so the caller is responsible for making a copy if necessary.
   36 func (u URLParams) SetMulti(key string, values []string) {
   37     u[key] = values
   38 }
   39 
   40 // Encode encodes the values into ``URL encoded'' form
   41 // ("bar=baz&foo=quux") sorted by key.
   42 func (u URLParams) Encode() string {
   43     return url.Values(u).Encode()
   44 }
   45 
   46 func SetOptions(u URLParams, opts ...googleapi.CallOption) {
   47     for _, o := range opts {
   48         u.Set(o.Get())
   49     }
   50 }