You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

348 lines
10 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>query - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package query</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "github.com/google/go-querystring/query"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package query implements encoding of structs into URL query parameters.
  68. </p>
  69. <p>
  70. As a simple example:
  71. </p>
  72. <pre>type Options struct {
  73. Query string `url:&#34;q&#34;`
  74. ShowAll bool `url:&#34;all&#34;`
  75. Page int `url:&#34;page&#34;`
  76. }
  77. opt := Options{ &#34;foo&#34;, true, 2 }
  78. v, _ := query.Values(opt)
  79. fmt.Print(v.Encode()) // will output: &#34;q=foo&amp;all=true&amp;page=2&#34;
  80. </pre>
  81. <p>
  82. The exact mapping between Go values and url.Values is described in the
  83. documentation for the Values() function.
  84. </p>
  85. </div>
  86. </div>
  87. <div id="pkg-index" class="toggleVisible">
  88. <div class="collapsed">
  89. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  90. </div>
  91. <div class="expanded">
  92. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  93. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  94. <div id="manual-nav">
  95. <dl>
  96. <dd><a href="index.html#Values">func Values(v interface{}) (url.Values, error)</a></dd>
  97. <dd><a href="index.html#Encoder">type Encoder</a></dd>
  98. </dl>
  99. </div><!-- #manual-nav -->
  100. <h4>Package files</h4>
  101. <p>
  102. <span style="font-size:90%">
  103. <a href="http://localhost:6060/src/github.com/google/go-querystring/query/encode.go">encode.go</a>
  104. </span>
  105. </p>
  106. </div><!-- .expanded -->
  107. </div><!-- #pkg-index -->
  108. <div id="pkg-callgraph" class="toggle" style="display: none">
  109. <div class="collapsed">
  110. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  111. </div> <!-- .expanded -->
  112. <div class="expanded">
  113. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  114. <p>
  115. In the call graph viewer below, each node
  116. is a function belonging to this package
  117. and its children are the functions it
  118. calls&mdash;perhaps dynamically.
  119. </p>
  120. <p>
  121. The root nodes are the entry points of the
  122. package: functions that may be called from
  123. outside the package.
  124. There may be non-exported or anonymous
  125. functions among them if they are called
  126. dynamically from another package.
  127. </p>
  128. <p>
  129. Click a node to visit that function's source code.
  130. From there you can visit its callers by
  131. clicking its declaring <code>func</code>
  132. token.
  133. </p>
  134. <p>
  135. Functions may be omitted if they were
  136. determined to be unreachable in the
  137. particular programs or tests that were
  138. analyzed.
  139. </p>
  140. <!-- Zero means show all package entry points. -->
  141. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  142. </div>
  143. </div> <!-- #pkg-callgraph -->
  144. <h2 id="Values">func <a href="http://localhost:6060/src/github.com/google/go-querystring/query/encode.go?s=4057:4103#L103">Values</a></h2>
  145. <pre>func Values(v interface{}) (<a href="../../../../net/url/index.html">url</a>.<a href="../../../../net/url/index.html#Values">Values</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
  146. <p>
  147. Values returns the url.Values encoding of v.
  148. </p>
  149. <p>
  150. Values expects to be passed a struct, and traverses it recursively using the
  151. following encoding rules.
  152. </p>
  153. <p>
  154. Each exported struct field is encoded as a URL parameter unless
  155. </p>
  156. <pre>- the field&#39;s tag is &#34;-&#34;, or
  157. - the field is empty and its tag specifies the &#34;omitempty&#34; option
  158. </pre>
  159. <p>
  160. The empty values are false, 0, any nil pointer or interface value, any array
  161. slice, map, or string of length zero, and any time.Time that returns true
  162. for IsZero().
  163. </p>
  164. <p>
  165. The URL parameter name defaults to the struct field name but can be
  166. specified in the struct field&#39;s tag value. The &#34;url&#34; key in the struct
  167. field&#39;s tag value is the key name, followed by an optional comma and
  168. options. For example:
  169. </p>
  170. <pre>// Field is ignored by this package.
  171. Field int `url:&#34;-&#34;`
  172. // Field appears as URL parameter &#34;myName&#34;.
  173. Field int `url:&#34;myName&#34;`
  174. // Field appears as URL parameter &#34;myName&#34; and the field is omitted if
  175. // its value is empty
  176. Field int `url:&#34;myName,omitempty&#34;`
  177. // Field appears as URL parameter &#34;Field&#34; (the default), but the field
  178. // is skipped if empty. Note the leading comma.
  179. Field int `url:&#34;,omitempty&#34;`
  180. </pre>
  181. <p>
  182. For encoding individual field values, the following type-dependent rules
  183. apply:
  184. </p>
  185. <p>
  186. Boolean values default to encoding as the strings &#34;true&#34; or &#34;false&#34;.
  187. Including the &#34;int&#34; option signals that the field should be encoded as the
  188. strings &#34;1&#34; or &#34;0&#34;.
  189. </p>
  190. <p>
  191. time.Time values default to encoding as RFC3339 timestamps. Including the
  192. &#34;unix&#34; option signals that the field should be encoded as a Unix time (see
  193. time.Unix())
  194. </p>
  195. <p>
  196. Slice and Array values default to encoding as multiple URL values of the
  197. same name. Including the &#34;comma&#34; option signals that the field should be
  198. encoded as a single comma-delimited value. Including the &#34;space&#34; option
  199. similarly encodes the value as a single space-delimited string. Including
  200. the &#34;semicolon&#34; option will encode the value as a semicolon-delimited string.
  201. Including the &#34;brackets&#34; option signals that the multiple URL values should
  202. have &#34;[]&#34; appended to the value name. &#34;numbered&#34; will append a number to
  203. the end of each incidence of the value name, example:
  204. name0=value0&amp;name1=value1, etc.
  205. </p>
  206. <p>
  207. Anonymous struct fields are usually encoded as if their inner exported
  208. fields were fields in the outer struct, subject to the standard Go
  209. visibility rules. An anonymous struct field with a name given in its URL
  210. tag is treated as having that name, rather than being anonymous.
  211. </p>
  212. <p>
  213. Non-nil pointer values are encoded as the value pointed to.
  214. </p>
  215. <p>
  216. Nested structs are encoded including parent fields in value names for
  217. scoping. e.g:
  218. </p>
  219. <pre>&#34;user[name]=acme&amp;user[addr][postcode]=1234&amp;user[addr][city]=SFO&#34;
  220. </pre>
  221. <p>
  222. All other values are encoded using their default string representation.
  223. </p>
  224. <p>
  225. Multiple fields that encode to the same URL parameter name will be included
  226. as multiple URL values of the same name.
  227. </p>
  228. <h2 id="Encoder">type <a href="http://localhost:6060/src/github.com/google/go-querystring/query/encode.go?s=965:1038#L29">Encoder</a></h2>
  229. <pre>type Encoder interface {
  230. EncodeValues(key <a href="../../../../builtin/index.html#string">string</a>, v *<a href="../../../../net/url/index.html">url</a>.<a href="../../../../net/url/index.html#Values">Values</a>) <a href="../../../../builtin/index.html#error">error</a>
  231. }</pre>
  232. <p>
  233. Encoder is an interface implemented by any type that wishes to encode
  234. itself into URL values in a non-standard way.
  235. </p>
  236. <div id="footer">
  237. Build version go1.6.<br>
  238. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  239. the content of this page is licensed under the
  240. Creative Commons Attribution 3.0 License,
  241. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  242. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  243. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  244. </div>
  245. </div><!-- .container -->
  246. </div><!-- #page -->
  247. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  248. <script type="text/javascript" src="../../../../../lib/godoc/jquery.js"></script>
  249. <script type="text/javascript" src="../../../../../lib/godoc/jquery.treeview.js"></script>
  250. <script type="text/javascript" src="../../../../../lib/godoc/jquery.treeview.edit.js"></script>
  251. <script type="text/javascript" src="../../../../../lib/godoc/godocs.js"></script>
  252. </body>
  253. </html>