[
  {
    "path": ".gitignore",
    "content": "_site\ntest_output\n"
  },
  {
    "path": ".prettierignore",
    "content": "*.md\n"
  },
  {
    "path": ".ruby-version",
    "content": "2.5.0\n"
  },
  {
    "path": "CNAME",
    "content": "golangcookbook.com\n"
  },
  {
    "path": "Dockerfile",
    "content": "FROM ruby:2.5\n\nRUN apt-get update \\\n && apt-get upgrade -y \\\n && apt-get install -y --no-install-recommends \\\n            curl\n   \nENV GOROOT /usr/local/go\nENV GOPATH /tmp/go\nENV GOCACHE /tmp\nENV GOVERSION 1.12.7\nENV PATH /site/bin:${GOROOT}/bin:${PATH}\n\nWORKDIR /usr/local\nRUN curl -sSL https://dl.google.com/go/go${GOVERSION}.linux-amd64.tar.gz | tar -zxf -\n\nRUN go version\n\nWORKDIR /site\nCOPY Gemfile .\nCOPY Gemfile.lock .\nRUN bundle install\n\nEXPOSE 8000\nEXPOSE 8001\n\nENV PORT 8000\nENV LRPORT 8001\n\nENTRYPOINT [\"/bin/bash\"]\n\n"
  },
  {
    "path": "Gemfile",
    "content": "# A sample Gemfile\nsource \"https://rubygems.org\"\n\ngem \"github-pages\"\n"
  },
  {
    "path": "LICENSE.md",
    "content": "## creative commons\n\n# Attribution-NonCommercial-NoDerivatives 4.0 International\n\nCreative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible.\n\n### Using Creative Commons Public Licenses\n\nCreative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses.\n\n* __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors).\n\n* __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees).\n\n## Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License\n\nBy exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License (\"Public License\"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.\n\n### Section 1 – Definitions.\n\na. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.\n\nb. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.\n\ne. __Effective Technological Measures__ means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.\n\nf. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.\n\nh. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License.\n\ni. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.\n\nh. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License.\n\ni. __NonCommercial__ means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange.\n\nj. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.\n\nk. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.\n\nl. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.\n\n### Section 2 – Scope.\n\na. ___License grant.___\n\n  1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:\n\n    A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and\n\n    B. produce and reproduce, but not Share, Adapted Material for NonCommercial purposes only.\n\n  2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.\n\n  3. __Term.__ The term of this Public License is specified in Section 6(a).\n\n  4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.\n\n  5. __Downstream recipients.__\n\n    A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.\n\n    B. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.\n\n  6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).\n\n ___Other rights.___\n\n  1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.\n\n  2. Patent and trademark rights are not licensed under this Public License.\n\n  3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes.\n\n### Section 3 – License Conditions.\n\nYour exercise of the Licensed Rights is expressly made subject to the following conditions.\n\na. ___Attribution.___\n\n  1. If You Share the Licensed Material, You must:\n\n    A. retain the following if it is supplied by the Licensor with the Licensed Material:\n\n      i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);\n\n      ii. a copyright notice;\n\n      iii. a notice that refers to this Public License;\n\n      iv. a notice that refers to the disclaimer of warranties;\n\n      v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable;\n\n    B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and\n\n    C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.\n\n  For the avoidance of doubt, You do not have permission under this Public License to Share Adapted Material.\n\n  2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.\n\n  3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.\n\n### Section 4 – Sui Generis Database Rights.\n\nWhere the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:\n\na. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only and provided You do not Share Adapted Material;\n\nb. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and\n\nc. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.\n\nFor the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.\n\n### Section 5 – Disclaimer of Warranties and Limitation of Liability.\n\na. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__\n\nb. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__\n\nc. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.\n\n### Section 6 – Term and Termination.\n\na. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.\n\nb. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:\n\n  1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or\n\n  2. upon express reinstatement by the Licensor.\n\n  For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.\n\nc. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.\n\n\nd. Sections 1, 5, 6, 7, and 8 survive termination of this Public License.\n\n### Section 7 – Other Terms and Conditions.\n\na. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.\n\nb. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.\n\n### Section 8 – Interpretation.\n\na. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.\n\nb. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.\n\nc. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.\n\nd. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.\n\n> Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses.\n>\n> Creative Commons may be contacted at creativecommons.org\n"
  },
  {
    "path": "README.md",
    "content": "# Go Cookbook\n\nSource for [the Go Cookbook](http://golangcookbook.com), a\ncommunity built collection of practical\nrecipes and contributions for real world Golang development, supported by\n[SuperOrbital](https://superorbit.al).\n\n### Contributing\n\nThe Go Cookbook is supported by\n[SuperOrbital](https://superorbit.al), but built by the\ncommunity, so your contributions are very welcome.  Just send\na pull request for any changes or additions.\n\n#### Adding a New Recipe\n\nRecipes are generated from the [_data/chapters.yml\nfile](https://github.com/golangcookbook/golangcookbook.github.io/blob/master/_data/chapters.yml),\nwhich is used to build [the index\npage](https://github.com/golangcookbook/golangcookbook.github.io/blob/master/index.md).\nThe `chapters.yml` file format is:\n\n```\n- title: Strings\n  recipes:\n  - title: Concatenating Strings\n    path: /chapters/strings/concatenation\n    wip: true\n  - title: Detecting a Substring\n    path: /chapters/strings/detecting\n  - title: Detecting All Substrings\n    path: false\n```\n\nSpecifying `wip: true` puts \"[Work in progress]\" in front of\nthe recipe in the index.  Setting `path: false` causes the\nrecipe to be listed without a link.\n\n#### Recipe Format\n\nRecipe files have a couple of required properties, specified\nin the preamble like such:\n\n``` yaml\n---\ntitle: Processing a String One Word or Character at a Time\nquestion: Given a string, how do I break it into words or characters and process each one in turn?\n---\n```\n\nAlso, to show example code, recipes can make use of the `{%\ninclude example.html example=\"filename\" %}` helper. This will\ninclude both `filename.go` as example source code, and\n`filename.expected.escaped` as the output of that code.  If\nyou're curious, [here's the definition for that\nhelper](https://github.com/golangcookbook/golangcookbook.github.io/blob/master/_includes/example.html).\nThe `filename.expected.escaped` files are automatically\ngenerated by the `./run_tests` script, described below.\n\n### Run locally\n\nThis project uses Docker for local development.  Once you\nhave Docker installed:\n\n``` console\n$ ./run server\n$ open http://localhost:4000\n```\n\n### Run the tests\n\n``` console\n$ ./run tests\n```\n\nThe `run_tests` script runs the tests and\nensures the `.expected`, `.go.escaped`, and\n`.expected.escaped` files are in place.  These files are\nused in the recipe templates to ensure all examples are up to\ndate and correct.\n\n### License\n\n[![Creative Commons\nLicense](https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png)](http://creativecommons.org/licenses/by-nc-sa/4.0/)\n\nThe Go Cookbook copyright\n[SuperOrbital](https://superorbit.al), and is licensed under\na [Creative Commons Attribution-NonCommercial-ShareAlike 4.0\nInternational\nLicense](http://creativecommons.org/licenses/by-nc-sa/4.0/).\n"
  },
  {
    "path": "_config.yml",
    "content": "name: The Go Cookbook\nmarkdown: kramdown\nkramdown:\n  input: GFM\nsass:\n  style: :compressed\ndefaults:\n  - scope:\n      path: \"chapters\"\n    values:\n      layout: recipe\n"
  },
  {
    "path": "_data/chapters.yml",
    "content": "- title: Running & Packaging\n  recipes:\n  - title: Running a One-Off File\n    path: /chapters/running/one-off\n  - title: Cross Compiling\n    path: /chapters/running/cross-compiling\n  - title: Building a binary\n    path: false\n  - title: Running a file via a shebang line\n    path: /chapters/running/shebang\n  - title: Exploring Go with a REPL\n    path: false\n  - title: Managing dependencies\n    path: false\n- title: Strings\n  recipes:\n  - title: Concatenating Strings\n    path: /chapters/strings/concatenation\n    wip: true\n  - title: Detecting a Substring\n    path: /chapters/strings/detecting\n    wip: true\n  - title: Detecting All Substrings\n    path: /chapters/strings/detecting-all\n    wip: true\n  - title: Accessing Substrings\n    path: /chapters/strings/accessing\n    wip: true\n  - title: Processing a String One Word or Character at a Time\n    path: /chapters/strings/processing\n  - title: Processing a String by Complex Separators and Patterns\n    path: /chapters/strings/processing-complex\n  - title: Reversing a String by Word or Character\n    path: /chapters/strings/reverse\n  - title: Replacing Parts of a String\n    path: false\n  - title: Expanding and Compressing Tabs\n    path: false\n  - title: Expanding Variables in User Input\n    path: false\n  - title: Interpolating Functions and Expressions Within Strings\n    path: false\n  - title: Indenting Here Documents\n    path: false\n  - title: Escaping Characters\n    path: false\n  - title: Trimming Blanks from the Ends of a String\n    path: false\n  - title: Controlling Case\n    path: false\n  - title: Properly Capitalizing a Title\n    path: /chapters/strings/title\n  - title: Turning an Array into a Sentence\n    path: /chapters/strings/sentence\n  - title: Parsing Comma-Separated Data\n    path: false\n- title: Numbers\n  recipes:\n  - title: Representing Enums in Go\n    path: /chapters/numbers/enums\n    wip: true\n  - title: Checking Whether a String Is a Valid Number\n    path: /chapters/numbers/string_to_num\n    wip: true\n  - title: Rounding Floating-Point Numbers\n    path: false\n  - title: Comparing Floating-Point Numbers\n    path: false\n  - title: Operating on a Series of Integers\n    path: false\n  - title: Working with Roman Numerals\n    path: false\n  - title: Generating Random Numbers\n    path: false\n  - title: Generating Repeatable Random Number Sequences\n    path: false\n  - title: Making Numbers Even More Random\n    path: false\n  - title: Generating Biased Random Numbers\n    path: false\n  - title: Doing Trigonometry in Degrees, Not Radians\n    path: false\n  - title: Calculating More Trigonometric Functions\n    path: false\n  - title: Taking Logarithms\n    path: false\n  - title: Multiplying Matrices\n    path: false\n  - title: Using Complex Numbers\n    path: false\n  - title: Converting Binary, Octal, and Hexadecimal Numbers\n    path: false\n  - title: Putting Commas in Numbers\n    path: false\n  - title: Printing Correct Plurals\n    path: false\n- title: Dates and Times\n  recipes:\n  - title: Finding Today's Date\n    path: false\n  - title: Converting DMYHMS to Epoch Seconds\n    path: false\n  - title: Converting Epoch Seconds to DMYHMS\n    path: false\n  - title: Adding to or Subtracting from a Date\n    path: false\n  - title: Difference of Two Dates\n    path: false\n  - title: Day in a Week/Month/Year or Week Number\n    path: false\n  - title: Parsing Dates and Times from Strings\n    path: false\n  - title: Printing a Date\n    path: false\n  - title: High-Resolution Timers\n    path: false\n  - title: Short Sleeps\n    path: false\n- title: Arrays\n  recipes:\n  - title: Specifying a List in Your Program\n    path: false\n  - title: Printing a List with Commas\n    path: false\n  - title: Changing Array Size\n    path: false\n  - title: Implementing a Sparse Array\n    path: false\n  - title: Iterating Over an Array\n    path: false\n  - title: Iterating Over an Array by Reference\n    path: false\n  - title: Extracting Unique Elements from a List\n    path: false\n  - title: Finding Elements in One Array but Not Another\n    path: false\n  - title: Computing Union, Intersection, or Difference of Unique Lists\n    path: false\n  - title: Appending One Array to Another\n    path: false\n  - title: Reversing an Array\n    path: /chapters/arrays/reverse\n  - title: Processing Multiple Elements of an Array\n    path: false\n  - title: Finding the First List Element That Passes a Test\n    path: false\n  - title: Finding All Elements in an Array Matching Certain Criteria\n    path: false\n  - title: Sorting an Array Numerically\n    path: false\n  - title: Sorting a List by Computable Field\n    path: false\n  - title: Implementing a Circular List\n    path: false\n  - title: Randomizing an Array\n    path: false\n- title: Maps\n  recipes:\n  - title: Adding an Element to a Map\n    path: false\n  - title: Testing for the Presence of a Key in a Map\n    path: /chapters/maps/presence\n    wip: true\n  - title: Deleting from a Map\n    path: false\n  - title: Traversing a Map\n    path: false\n  - title: Convert a Map into an Array of keys or values\n    path: false\n    source: \"http://stackoverflow.com/a/27398024\"\n  - title: Printing a Map\n    path: false\n  - title: Mapes with Multiple Values per Key\n    path: false\n  - title: Inverting a Map\n    path: false\n  - title: Sorting a Map\n    path: false\n  - title: Merging Maps\n    path: false\n  - title: Finding Common or Different Keys in Two Maps\n    path: false\n- title: Files\n  recipes:\n  - title: Checking the Existence of a File\n    source: \"http://stackoverflow.com/a/12518877/2620448\"\n  - title: Reading and Writing to Files\n    path: /chapters/files/read-write\n  - title: Expanding Tildes in Filenames\n    path: false\n  - title: Creating Temporary Files\n    path: false\n  - title: Storing a File Inside Your Program Text\n    path: false\n  - title: Storing Multiple Files in the DATA Area\n    path: false\n  - title: Writing a Unix-Style Filter Program\n    path: false\n  - title: Modifying a File in Place with a Temporary File\n    path: false\n  - title: Modifying a File in Place with the -i Switch\n    path: false\n  - title: Modifying a File in Place Without a Temporary File\n    path: false\n  - title: Locking a File\n    path: false\n  - title: Flushing Output\n    path: false\n  - title: Doing Non-Blocking I/O\n    path: false\n  - title: Determining the Number of Unread Bytes\n    path: false\n  - title: Reading from Many Filehandles Without Blocking\n    path: false\n  - title: Reading an Entire Line Without Blocking\n    path: false\n  - title: Counting Lines (or Paragraphs or Records) in a File\n    path: false\n  - title: Processing Every Word in a File\n    path: false\n  - title: Reading a File Backward by Line or Paragraph\n    path: false\n  - title: Trailing a Growing File\n    path: false\n  - title: Picking a Random Line from a File\n    path: false\n  - title: Randomizing All Lines\n    path: false\n  - title: Reading a Particular Line in a File\n    path: false\n  - title: Processing Variable-Length Text Fields\n    path: false\n  - title: Removing the Last Line of a File\n    path: false\n  - title: Processing Binary Files\n    path: false\n  - title: Using Random-Access I/O\n    path: false\n  - title: Updating a Random-Access File\n    path: false\n  - title: Reading a String from a Binary File\n    path: false\n  - title: Reading Fixed-Length Records\n    path: false\n  - title: Reading Configuration Files\n    path: false\n  - title: Testing a File for Trustworthiness\n    path: false\n  - title: Reading or Writing Unicode from a Filehandle\n    path: false\n  - title: Comparing the Contents of Two Files\n    path: false\n  - title: Reading and writing JSON files\n    path: false\n    source: \"http://golang.org/pkg/encoding/json/#example_Decoder\"\n  - title: Reading and writing YAML files\n    path: false\n- title: Directories\n  recipes:\n  - title: Getting and Setting Timestamps\n    path: false\n  - title: Deleting a File\n    path: false\n  - title: Copying or Moving a File\n    path: false\n  - title: Recognizing Two Names for the Same File\n    path: false\n  - title: Processing All Files in a Directory\n    path: false\n  - title: Globbing, or Getting a List of Filenames Matching a Pattern\n    path: false\n  - title: Processing All Files in a Directory Recursively\n    path: false\n    source: \"http://stackoverflow.com/a/6612243/2620448\"\n  - title: Removing a Directory and Its Contents\n    path: false\n  - title: Renaming Files\n    path: false\n  - title: Splitting a Filename into Its Component Parts\n    path: false\n  - title: Working with Symbolic File Permissions Instead of Octal Values\n    path: false\n- title: Goroutines\n- title: Systems Programming\n  recipes:\n  - title: Catching signals\n    source: \"http://stackoverflow.com/a/11269077/2620448\"\n  - title: Running Child Processes\n    source: \"http://stackoverflow.com/a/14885714/2620448\"\n  - title: Processing Command-line Arguments\n    source: \"https://golang.org/pkg/flag/\"\n- title: Sockets\n  recipes:\n  - title: Writing a TCP Client\n    path: false\n  - title: Writing a TCP Server\n    path: false\n  - title: Communicating over TCP\n    path: false\n  - title: Setting Up a UDP Client\n    path: false\n  - title: Setting Up a UDP Server\n    path: false\n  - title: Using Unix Domain Sockets\n    path: false\n  - title: Identifying the Other End of a Socket\n    path: false\n  - title: Finding Your Own Name and Address\n    path: false\n  - title: Closing a Socket After Forking\n    path: false\n  - title: Writing Bidirectional Clients\n    path: false\n  - title: Forking Servers\n    path: false\n  - title: Pre-Forking Servers\n    path: false\n  - title: Non-Forking Servers\n    path: false\n  - title: Multitasking Server with Threads\n    path: false\n  - title: Writing a Multitasking Server with POE\n    path: false\n  - title: Writing a Multihomed Server\n    path: false\n  - title: Making a Daemon Server\n    path: false\n  - title: Restarting a Server on Demand\n    path: false\n  - title: Managing Multiple Streams of Input\n    path: false\n- title: Internet Services\n  recipes:\n  - title: Simple DNS Lookups\n    path: false\n    source: \"http://golang.org/pkg/net/#LookupHost and http://miek.nl/posts/2014/Aug/16/go-dns-package/\"\n  - title: Sending Mail\n    path: false\n    source: \"https://code.google.com/p/go-wiki/wiki/SendingMail\"\n  - title: Reading and Posting Usenet News Messages\n    path: false\n  - title: Reading Mail with POP3\n    path: false\n  - title: Simulating Telnet from a Program\n    path: false\n  - title: Pinging a Machine\n    path: false\n  - title: Accessing an LDAP Server\n    path: false\n  - title: Sending Attachments in Mail\n    path: false\n  - title: Extracting Attachments from Mail\n    path: false\n  - title: Writing a RESTful service\n    path: false\n  - title: Connecting to MySQL\n    path: false\n    source: \"http://stackoverflow.com/questions/11353679/whats-the-recommended-way-to-connect-to-mysql-from-go\"\n  - title: Connecting to PgSQL\n    source: \"http://www.alexedwards.net/blog/practical-persistence-sql\"\n  - title: Fetching a URL\n    path: false\n  - title: Setting HTTP Headers\n    path: false\n  - title: Automating Form Submission\n    path: false\n  - title: Extracting URLs\n    path: false\n  - title: Converting ASCII to HTML\n    path: false\n  - title: Converting HTML to ASCII\n    path: false\n  - title: Extracting or Removing HTML Tags\n    path: false\n  - title: Finding Stale Links\n    path: false\n  - title: Finding Fresh Links\n    path: false\n  - title: Using Templates to Generate HTML\n    path: false\n  - title: Mirroring Web Pages\n    path: false\n  - title: Creating a Robot\n    path: false\n  - title: Parsing a Web Server Log File\n    path: false\n  - title: Processing Server Logs\n    path: false\n  - title: Using Cookies\n    path: false\n  - title: Fetching Password-Protected Pages\n    path: false\n  - title: Fetching https:// Web Pages\n    path: false\n  - title: Resuming an HTTP GET\n    path: false\n  - title: Parsing HTML\n    path: false\n  - title: Extracting Table Data\n    path: false\n  - title: Processing POST requests\n    source: \"http://stackoverflow.com/questions/15672556/handling-json-post-request-in-go\"\n"
  },
  {
    "path": "_includes/example.html",
    "content": "<div class=\"example\">\n  <div class=\"input\">\n    <tt class=\"filename\"><a href=\"./test_{{ include.example }}.go\">test_{{ include.example }}.go</a></tt>\n    <pre><code>{% include_relative test_{{ include.example }}.go.escaped %}</code></pre>\n  </div>\n\n  <div class=\"output\">\n    <pre><code><span class=\"shell\">$ go run test_{{include.example}}.go</span>\n{% include_relative test_{{ include.example }}.expected.escaped %}</code></pre>\n  </div>\n</div>\n\n"
  },
  {
    "path": "_layouts/default.html",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset='utf-8'>\n    <meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\">\n    <link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheets/stylesheet.css\" media=\"screen\" />\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheets/site.css\" media=\"screen\" />\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheets/pygment_trac.css\" media=\"screen\" />\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheets/print.css\" media=\"print\" />\n\n    <!--[if lt IE 9]>\n    <script src=\"//html5shiv.googlecode.com/svn/trunk/html5.js\"></script>\n    <![endif]-->\n\n    <title> {{ page.title }} </title>\n  </head>\n\n  <body>\n    <header>\n      <div class=\"inner\">\n        <h1><a href=\"/\">{{ site.name }}</a></h1>\n        <h2>\n          Maintained by <a href=\"https://superorbit.al\">SuperOrbital</a>.\n        </h2>\n        <h3>A community built and contributed collection of practical recipes for real world Golang development.</h3>\n        <a href=\"{{ site.github.repository_url }}\" class=\"button\"><small>View project on</small> GitHub</a>\n      </div>\n    </header>\n\n    <div id=\"content-wrapper\">\n      <div class=\"inner clearfix\">\n        <section id=\"main-content\">\n          \n          {{ content }}\n\n        </section>\n\n        <aside id=\"sidebar\">\n          <p class=\"contributions\">\n            <h3>\n              The Go Cookbook is built by the community.\n              <i>(That means you!)</i>\n            </h3>\n            <h2><a href=\"{{site.github.repository_url}}/edit/master/{{ page.path }}\">Edit this page on github</a>.</h2>\n            <h2><a href=\"{{site.github.repository_url}}/pulls\">Submit a pull request with new content</a>.</h2>\n            You can also <a href=\"{{ site.github.repository_url }}/issues/new\">submit an issue</a> \n            or \n            <a href=\"mailto:tammer@superorbit.al\">contact SuperOrbital</a>\n            if you have questions.\n          </p>\n          <hr/>\n\n          <a href=\"{{ site.github.zip_url }}\" class=\"button\">\n            <small>Download</small>\n            .zip file\n          </a>\n          <a href=\"{{ site.github.tar_url }}\" class=\"button\">\n            <small>Download</small>\n            .tar.gz file\n          </a>\n\n          <hr/>\n\n          <div class=\"repo-owner\">\n            <p>\n              <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-sa/4.0/\">\n                <img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png\" />\n              </a>\n              <br />\n              <span xmlns:dct=\"http://purl.org/dc/terms/\" property=\"dct:title\">\n                The Go Cookbook\n              </span>\n              is licensed under a \n              <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-sa/4.0/\">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.\n              <br />\n              Based on a work at <a xmlns:dct=\"http://purl.org/dc/terms/\" href=\"{{site.github.repository_url}}\" rel=\"dct:source\">{{site.github.repository_url}}</a>.\n            </p>\n          </div>\n\n        </aside>\n      </div>\n    </div>\n\n  </body>\n  <script type=\"text/javascript\">\n    !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error(\"Segment snippet included twice.\");else{analytics.invoked=!0;analytics.methods=[\"trackSubmit\",\"trackClick\",\"trackLink\",\"trackForm\",\"pageview\",\"identify\",\"group\",\"track\",\"ready\",\"alias\",\"page\",\"once\",\"off\",\"on\"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement(\"script\");e.type=\"text/javascript\";e.async=!0;e.src=(\"https:\"===document.location.protocol?\"https://\":\"http://\")+\"cdn.segment.com/analytics.js/v1/\"+t+\"/analytics.min.js\";var n=document.getElementsByTagName(\"script\")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION=\"3.0.1\";\n    analytics.load(\"Qf02gKC5AyyQkGgE7HGRXbsfe0dLaRMz\");\n    analytics.page()\n    }}();\n  </script>\n</html>\n"
  },
  {
    "path": "_layouts/recipe.html",
    "content": "---\nlayout: default\n---\n<h2 class=\"recipe\">{{ page.title }}</h2>\n\n<p class=\"question\">\n  {{ page.question }}\n</p>\n\n{{ content }}\n\n"
  },
  {
    "path": "bin/server",
    "content": "#!/usr/bin/env bash\n\nset -eou pipefail\n\nbundle exec jekyll serve -H 0.0.0.0 -wDP \"$PORT\" -l --livereload-port \"$LRPORT\" -t\n"
  },
  {
    "path": "bin/tests",
    "content": "#!/usr/bin/env bash\n\nTEST_OUTPUT=/tmp/test_output.$$\n\nprint_success() { echo -n .; }\nprint_failure() { echo -n x; }\nprint_pending() { echo -n p; }\nprint_output()  { echo; cat $TEST_OUTPUT/*; }\nrun_test() { diff <( go run \"$1\" 2>&1) \"$2\" > /dev/null; }\n\nrecord_failure() {\n  {\n    echo \"Failed: $1\"\n    echo \"  To reset, run:\"\n    echo \"  rm $2\"\n    diff -yW200 <( go run \"$1\" 2>&1) \"$2\"\n    echo \"------------------------\"\n    echo\n  } >> \"$TEST_OUTPUT/${1//\\//_}.out\"\n}\n\ngenerate_expected() {\n  echo\n  echo \"$2 not found - generating it...\"\n  go run \"$1\" > \"$2\"\n}\n\ngenerate_escaped() {\n  sed 's/&(?!amp;)/\\&amp;/g; s/</\\&lt;/g; s/>/\\&gt;/g; s/\"/\\&quot;/g; s/'\"'\"'/\\&#39;/g' < \"$1\" > \"$1.escaped\"\n}\n\nprocess_file() {\n  file=$1\n  expected=${file/.go/.expected}\n\n  if [ -s \"$file\" ]; then\n    if [ -f \"$expected\" ]; then\n      if run_test \"$file\" \"$expected\"; then\n        print_success\n      else\n        record_failure \"$file\" \"$expected\"\n        print_failure\n      fi\n    else\n      generate_expected \"$file\" \"$expected\"\n    fi\n  else\n    print_pending\n  fi\n  generate_escaped \"$expected\"\n  generate_escaped \"$file\"\n}\n\nmain() {\n  mkdir $TEST_OUTPUT\n  touch $TEST_OUTPUT/cat_on_empty_dir_hangs\n\n  if [[ \"$#\" -gt 0 ]]; then\n    shopt -s nullglob\n    files=( \"$@\" )\n  else\n    readarray -t files < <(find chapters -name \"test*.go\")\n  fi\n\n  echo \"Running tests for ${files[*]}\"\n\n  for file in \"${files[@]}\"; do\n    process_file \"$file\" &\n  done\n\n  wait\n\n  print_output\n\n  rm -rf $TEST_OUTPUT\n}\n\nmain \"$@\"\n"
  },
  {
    "path": "chapters/arrays/reverse/index.md",
    "content": "---\ntitle: Reversing an Array\nquestion: How do I reverse an array?\n---\n\nReversing an array is fairly straightforward in Go, due to multiple return\nvalues.  Simply loop through the first half of the array, swapping each element\nin turn with its mirror counterpart:\n\n{%include example.html example=\"simple\"%}\n\nThere's an even more terse implementation which makes use of the `,` operator\ninside the Go for loop:\n\n{%include example.html example=\"terse\"%}\n\nNote that both of these `reverse` functions take slices, which are passed by\nvalue.  This is good for performance, but means we're actually modifying the\npassed in array, leading to unexpected results.  In other words, the `reverse`\nmethod could be written like such:\n\n{%include example.html example=\"alternate\"%}\n\nNow `reverse` doesn't return another reference to the slice, which makes it\nmuch more clear that it's modifying the slice in-place.  If we want to return a\nmodified copy of the slice, we must do so manually:\n\n{%include example.html example=\"copy\"%}\n\nAs you can see in the output above, the original array is untouched.\n\nSince we're not modifying the array in-place, we can also simplify our\nalgorithm buy doing a more straight-forward element copy:\n\n{%include example.html example=\"copy_simple\"%}\n\n"
  },
  {
    "path": "chapters/arrays/reverse/test_alternate.expected",
    "content": "[5 4 3 2 1]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_alternate.expected.escaped",
    "content": "[5 4 3 2 1]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_alternate.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc reverse(numbers []int) {\n\tfor i, j := 0, len(numbers)-1; i < j; i, j = i+1, j-1 {\n\t\tnumbers[i], numbers[j] = numbers[j], numbers[i]\n\t}\n}\n\nfunc main() {\n\tarray := []int{1, 2, 3, 4, 5}\n\treverse(array)\n\n\tfmt.Printf(\"%v\\n\", array)\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_alternate.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc reverse(numbers []int) {\n\tfor i, j := 0, len(numbers)-1; i &lt; j; i, j = i+1, j-1 {\n\t\tnumbers[i], numbers[j] = numbers[j], numbers[i]\n\t}\n}\n\nfunc main() {\n\tarray := []int{1, 2, 3, 4, 5}\n\treverse(array)\n\n\tfmt.Printf(&quot;%v\\n&quot;, array)\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_copy.expected",
    "content": "[5 4 3 2 1]\n[1 2 3 4 5]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_copy.expected.escaped",
    "content": "[5 4 3 2 1]\n[1 2 3 4 5]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_copy.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc reverse(numbers []int) []int {\n\tnewNumbers := make([]int, len(numbers))\n\tfor i, j := 0, len(numbers)-1; i <= j; i, j = i+1, j-1 {\n\t\tnewNumbers[i], newNumbers[j] = numbers[j], numbers[i]\n\t}\n\treturn newNumbers\n}\n\nfunc main() {\n\tarray := []int{1, 2, 3, 4, 5}\n\n\tfmt.Printf(\"%v\\n\", reverse(array))\n\tfmt.Printf(\"%v\\n\", array)\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_copy.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc reverse(numbers []int) []int {\n\tnewNumbers := make([]int, len(numbers))\n\tfor i, j := 0, len(numbers)-1; i &lt;= j; i, j = i+1, j-1 {\n\t\tnewNumbers[i], newNumbers[j] = numbers[j], numbers[i]\n\t}\n\treturn newNumbers\n}\n\nfunc main() {\n\tarray := []int{1, 2, 3, 4, 5}\n\n\tfmt.Printf(&quot;%v\\n&quot;, reverse(array))\n\tfmt.Printf(&quot;%v\\n&quot;, array)\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_copy_simple.expected",
    "content": "[5 4 3 2 1]\n[1 2 3 4 5]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_copy_simple.expected.escaped",
    "content": "[5 4 3 2 1]\n[1 2 3 4 5]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_copy_simple.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc reverse(numbers []int) []int {\n\tnewNumbers := make([]int, 0, len(numbers))\n\tfor i := len(numbers)-1; i >= 0; i-- {\n\t\tnewNumbers = append(newNumbers, numbers[i])\n\t}\n\treturn newNumbers\n}\n\nfunc main() {\n\tarray := []int{1, 2, 3, 4, 5}\n\n\tfmt.Printf(\"%v\\n\", reverse(array))\n\tfmt.Printf(\"%v\\n\", array)\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_copy_simple.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc reverse(numbers []int) []int {\n\tnewNumbers := make([]int, 0, len(numbers))\n\tfor i := len(numbers)-1; i &gt;= 0; i-- {\n\t\tnewNumbers = append(newNumbers, numbers[i])\n\t}\n\treturn newNumbers\n}\n\nfunc main() {\n\tarray := []int{1, 2, 3, 4, 5}\n\n\tfmt.Printf(&quot;%v\\n&quot;, reverse(array))\n\tfmt.Printf(&quot;%v\\n&quot;, array)\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_simple.expected",
    "content": "[5 4 3 2 1]\n[4 3 2 1]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_simple.expected.escaped",
    "content": "[5 4 3 2 1]\n[4 3 2 1]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_simple.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc reverse(numbers []int) []int {\n\tfor i := 0; i < len(numbers)/2; i++ {\n\t\tj := len(numbers) - i - 1\n\t\tnumbers[i], numbers[j] = numbers[j], numbers[i]\n\t}\n\treturn numbers\n}\n\nfunc main() {\n\tfmt.Printf(\"%v\\n\", reverse([]int{1, 2, 3, 4, 5}))\n\tfmt.Printf(\"%v\\n\", reverse([]int{1, 2, 3, 4}))\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_simple.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc reverse(numbers []int) []int {\n\tfor i := 0; i &lt; len(numbers)/2; i++ {\n\t\tj := len(numbers) - i - 1\n\t\tnumbers[i], numbers[j] = numbers[j], numbers[i]\n\t}\n\treturn numbers\n}\n\nfunc main() {\n\tfmt.Printf(&quot;%v\\n&quot;, reverse([]int{1, 2, 3, 4, 5}))\n\tfmt.Printf(&quot;%v\\n&quot;, reverse([]int{1, 2, 3, 4}))\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_terse.expected",
    "content": "[5 4 3 2 1]\n[4 3 2 1]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_terse.expected.escaped",
    "content": "[5 4 3 2 1]\n[4 3 2 1]\n"
  },
  {
    "path": "chapters/arrays/reverse/test_terse.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc reverse(numbers []int) []int {\n\tfor i, j := 0, len(numbers)-1; i < j; i, j = i+1, j-1 {\n\t\tnumbers[i], numbers[j] = numbers[j], numbers[i]\n\t}\n\treturn numbers\n}\n\nfunc main() {\n\tfmt.Printf(\"%v\\n\", reverse([]int{1, 2, 3, 4, 5}))\n\tfmt.Printf(\"%v\\n\", reverse([]int{1, 2, 3, 4}))\n}\n"
  },
  {
    "path": "chapters/arrays/reverse/test_terse.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc reverse(numbers []int) []int {\n\tfor i, j := 0, len(numbers)-1; i &lt; j; i, j = i+1, j-1 {\n\t\tnumbers[i], numbers[j] = numbers[j], numbers[i]\n\t}\n\treturn numbers\n}\n\nfunc main() {\n\tfmt.Printf(&quot;%v\\n&quot;, reverse([]int{1, 2, 3, 4, 5}))\n\tfmt.Printf(&quot;%v\\n&quot;, reverse([]int{1, 2, 3, 4}))\n}\n"
  },
  {
    "path": "chapters/files/read-write/index.md",
    "content": "---\ntitle: Reading and Writing to Files \nquestion: How do I read from and write to a file?\n---\n\nhttp://stackoverflow.com/questions/1821811/how-to-read-write-from-to-file\n\nhttp://stackoverflow.com/a/16615559/2620448\n"
  },
  {
    "path": "chapters/maps/presence/index.md",
    "content": "---\ntitle: Testing for the Presence of a Key in a Map\nquestion: How do I determine if a map contains a given key?\n---\n\nhttp://stackoverflow.com/questions/2050391/how-to-check-if-a-map-contains-a-key-in-go\n"
  },
  {
    "path": "chapters/numbers/enums/index.md",
    "content": "---\ntitle: Representing Enums\nquestion: How do I represent enumerated constants in Go?\n---\n\nhttp://stackoverflow.com/questions/14426366/what-is-an-idiomatic-way-of-representing-enums-in-golang\n\nhttp://stackoverflow.com/a/1721367\n"
  },
  {
    "path": "chapters/numbers/string_to_num/index.md",
    "content": "---\ntitle: Converting a string to number\nquestion: How do I convert a string to number if possible in Go?\n---\n\nGo comes with a core package called `strconv` which makes this task very\neasy. You can convert a string to an integer and specify a base as well. You\nalso have the flexibility to define the size of bits into which the number\nshould fit into.\n\n{% include example.html example=\"string_to_int\" %}\n\nThe `strconv` package also contains functions such as `ParseUint` and\n`ParseFloat` which convert a string to unsigned integer and floating point\nnumbers respectively.\n\n{% include example.html example=\"string_to_float\" %}\n"
  },
  {
    "path": "chapters/numbers/string_to_num/test_string_to_float.expected",
    "content": "float64 123.123000\n"
  },
  {
    "path": "chapters/numbers/string_to_num/test_string_to_float.expected.escaped",
    "content": "float64 123.123000\n"
  },
  {
    "path": "chapters/numbers/string_to_num/test_string_to_float.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tstr := \"123.123\"\n\t/*\n\t\tThe first argument to ParseInt is the string to be converted.\n\t\tThe second argument is the number of bits to which the number should fit.\n\t*/\n\ti, err := strconv.ParseFloat(str, 64)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(\"%T %f\\n\", i, i)\n}\n"
  },
  {
    "path": "chapters/numbers/string_to_num/test_string_to_float.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;os&quot;\n\t&quot;strconv&quot;\n)\n\nfunc main() {\n\tstr := &quot;123.123&quot;\n\t/*\n\t\tThe first argument to ParseInt is the string to be converted.\n\t\tThe second argument is the number of bits to which the number should fit.\n\t*/\n\ti, err := strconv.ParseFloat(str, 64)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Printf(&quot;%T %f\\n&quot;, i, i)\n}\n"
  },
  {
    "path": "chapters/numbers/string_to_num/test_string_to_int.expected",
    "content": "int64 123\nstrconv.ParseInt: parsing \"invalidString123\": invalid syntax\n"
  },
  {
    "path": "chapters/numbers/string_to_num/test_string_to_int.expected.escaped",
    "content": "int64 123\nstrconv.ParseInt: parsing &quot;invalidString123&quot;: invalid syntax\n"
  },
  {
    "path": "chapters/numbers/string_to_num/test_string_to_int.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n)\n\nfunc handleError(err error) {\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n}\n\nfunc main() {\n\tstr := \"123\"\n\t/*\n\t\tThe first argument to ParseInt is the string to be converted.\n\t\tThe second argument is the base to which the number is to be converted.\n\t\tThe third argument is the number of bits to which the number should fit.\n\t*/\n\ti, err := strconv.ParseInt(str, 10, 64)\n\thandleError(err)\n\tfmt.Printf(\"%T %d\\n\", i, i)\n\tstr = \"invalidString123\"\n\t_, err = strconv.ParseInt(str, 10, 64)\n\thandleError(err)\n}\n"
  },
  {
    "path": "chapters/numbers/string_to_num/test_string_to_int.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strconv&quot;\n)\n\nfunc handleError(err error) {\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n}\n\nfunc main() {\n\tstr := &quot;123&quot;\n\t/*\n\t\tThe first argument to ParseInt is the string to be converted.\n\t\tThe second argument is the base to which the number is to be converted.\n\t\tThe third argument is the number of bits to which the number should fit.\n\t*/\n\ti, err := strconv.ParseInt(str, 10, 64)\n\thandleError(err)\n\tfmt.Printf(&quot;%T %d\\n&quot;, i, i)\n\tstr = &quot;invalidString123&quot;\n\t_, err = strconv.ParseInt(str, 10, 64)\n\thandleError(err)\n}\n"
  },
  {
    "path": "chapters/running/cross-compiling/index.md",
    "content": "---\ntitle: Cross Compiling\nquestion: How do I compile a binary designed to run on a different platform than my local host?\n---\n\nSince Go is a statically compiled language, it's well designed for producing tiny, pre-compiled tools.  This is great for Unix administrators or DevOps engineers, as they can send their tools with them when they work on remote systems.  However, many developers use OS X or Windows on their local machine, and another OS like Linux on others.  How do you use one system to compile binaries that will work on the other?  This is called cross-compiling, and it's pretty simple with Go.\n\n### Pre 1.5\n\nBefore 1.5, cross compilation was an arduous process, requiring [massive scripts](http://dave.cheney.net/2013/07/09/an-introduction-to-cross-compilation-with-go-1-1) to build separate go compilers for each supported platform.\n\n### Post 1.5\n\nThings have been much better since v1.5 of Go was released.  Go now [comes with support for all architectures built in](http://dave.cheney.net/2015/03/03/cross-compilation-just-got-a-whole-lot-better-in-go-1-5).  That means cross compiling is as simple as setting the right `$GOOS` and `$GOARCH` environment variables before building.\n\nConsider the below example program, which simply prints the OS and Architecture it's compiled for.  While the output will always be the same as the platform it's being executed on, it's really a compile-time value - not something determined at runtime.\n\n```\npackage main\n\nimport \"fmt\"\nimport \"runtime\"\n\nfunc main() {\n    fmt.Printf(\"OS: %s\\nArchitecture: %s\\n\", runtime.GOOS, runtime.GOARCH)\n}\n```\n\nNow, let's compile this program for an Apple MacBook.  To do so, we simply set two environment variables: `$GOOS`, which is the target operating system, and `$GOARCH`, which is the target processor.  Then we run `go build` as normal:\n\n```\n$ GOOS=darwin GOARCH=386 go build test.go\n```\n\nNote that the `test` executable that comes out the other end only runs on OS X, and cannot be run on Linux or Windows.  On the other hand, if we wanted to compile for Microsoft Windows, we'd simply set `GOOS=windows` and `GOARCH=386`.\n\nWhen we run the resulting binary on the right platform, we see:\n\n```\n$ ./test\nOS: windows\nArchitecture: 386\n```\n\nThis is another example of Go's strengths as a language for building easily distributed tools.  It's almost trivial to modify your build process to produce binaries for every major platform your users may run.  This is used, for example, to enable the Cloud Foundry team to distribute [Linux, Windows, and OS X CLI tools](https://github.com/cloudfoundry/cli).\n"
  },
  {
    "path": "chapters/running/one-off/index.md",
    "content": "---\ntitle: Running a one-off File\nquestion: What's the easiest way to run a single Go file?\n---\n\nFirst steps are often both fundamental and overlooked.\n\nGo's unusual packaging and compilation process can be daunting and confusing to a new developer.  Unlike most compiled languages, Go actually comes with a very easy way of running a single file.  Simply execute the program with `go run filename.go`:\n\n{% include example.html example=\"hello_world\" %}\n\nThis allows Go to act as though it were a more dynamic language, and is useful for development and exploration.  However, Go's compiler is so incredibly fast, that it's possible to use this technique in a production setting:\n\n```\n$ time go run empty.go\n\nreal\t0m0.103s\nuser\t0m0.058s\nsys\t0m0.033s\n```\n\nThroughout this book, you'll see many Go programs.  Each one is available as a separate file in this book, and each example includes the `go run` command required to run the file along side the full output.\n"
  },
  {
    "path": "chapters/running/one-off/test_empty.expected",
    "content": ""
  },
  {
    "path": "chapters/running/one-off/test_empty.expected.escaped",
    "content": ""
  },
  {
    "path": "chapters/running/one-off/test_empty.go",
    "content": "package main\n\nfunc main() {\n\n}\n"
  },
  {
    "path": "chapters/running/one-off/test_empty.go.escaped",
    "content": "package main\n\nfunc main() {\n\n}\n"
  },
  {
    "path": "chapters/running/one-off/test_hello_world.expected",
    "content": "Hello World!\n"
  },
  {
    "path": "chapters/running/one-off/test_hello_world.expected.escaped",
    "content": "Hello World!\n"
  },
  {
    "path": "chapters/running/one-off/test_hello_world.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello World!\")\n}\n"
  },
  {
    "path": "chapters/running/one-off/test_hello_world.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n\tfmt.Println(&quot;Hello World!&quot;)\n}\n"
  },
  {
    "path": "chapters/running/shebang/bash.go",
    "content": "//usr/bin/env go run $0 $@; exit\n\npackage main\n\nfunc main() {\n\tprintln(\"hello\")\n}\n"
  },
  {
    "path": "chapters/running/shebang/fail.go",
    "content": "#!/usr/bin/env go run\n\npackage main\n\nfunc main() {\n\tprintln(\"hello\")\n}\n"
  },
  {
    "path": "chapters/running/shebang/gorun.go",
    "content": "#!/usr/bin/env gorun\n\npackage main\n\nfunc main() {\n\tprintln(\"hello\")\n}\n"
  },
  {
    "path": "chapters/running/shebang/index.md",
    "content": "---\ntitle: Running a file via a shebang line\nquestion: How can I add a shebang line to the top of my Go file in order to run it directly, as though it were an interpreted script?\n---\n\n### \"Shebang??\"\n\nIn order to make it possible to execute scripts as though they were first class executables, UNIX systems will looks for what we refer to as a shebang line at the top of the file.  The origin of the name is murky.  Some think it came from sharp-bang or hash-bang -- contractions of `#` (\"sharp\") and `!` (\"bang\").  Others think the \"SH\" is in reference to the first UNIX shell, named \"sh\".\n\nIn any case, if a UNIX system sees that the first line of an executable begins with `#!`, then it will execute the file using whatever command is specified in the rest of the line.  For example, if there's a file named `/path/to/bar` that looks like:\n\n```\n#!/bin/foo\n...\n```\n\nThen, when run, the kernel will execute `/bin/foo /path/to/bar`.  \n\nThis is great for interpreted languages like Ruby and Python which allow `#` as an innocuous comment.  A clever gopher might attempt to create a file named `/path/to/example` that looks like such:\n\n``` golang\n#!/usr/local/bin/go run\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hello!\")\n}\n```\n\nAnd expect to run it and see \"hello\" in their terminal.  However, Go does not allow `#` as a comment, which causes this to fail with a syntax error:\n\n```\n$ ./fail.go\nfail.go:1:1: illegal character U+0023 '#'\n```\n\nIn order for this to work, the Go spec would have to be modified to accept `#` as a comment on the first line of the file.  However, the Go authors are highly opinionated.  When (repeatedly) asked for this feature, [Rob Pike has said](https://groups.google.com/d/msg/golang-nuts/iGHWoUQFHjg/_dbLKomrPmUJ):\n\n> I have never said it cannot be done. I have always said it should not be done, and I have explained why.\n> \n> \"Useful\" is not an argument for a feature. All features are useful; otherwise they would not be features. The issue is whether the feature justifies its cost. That is a judgement call, and my judgement is, no. Running compilers and linkers, doing megabytes of I/O, and creating temporary binary files is not a justifiable expense for running a small program. For large programs, the amortization is even more in favor of not doing this.\n> \n> I am firmly against adding a feature to Go that encourages abuse of resources.\n> \n> If you want the feature, use gorun or an equivalent wrapper program. That's what it's for.  I think believe [sic] gorun is a mistake, but I'm not stopping you from installing it and using it as you see fit.\n\n### gorun\n\nWhat's this gorun that has Rob up in arms?  The Ubuntu Linux distribution produced the [gorun utility](https://wiki.ubuntu.com/gorun) to solve the shebang issue.  As listed in the homepage, gorun will:\n\n* write files under a safe directory in `$TMPDIR` (or `/tmp`), so that the actual script location isn't touched (may be read-only)\n* avoid races between parallel executions of the same file\n* automatically clean up old compiled files that remain unused for some time (without races)\n* replace the process rather than using a child\n* pass arguments to the compiled application properly\n* handle well `GOROOT`, `GOROOT_FINAL` and the location of the toolchain\n\nImportantly, gorun will also strip the shebang line from the executed file before running it via `go run`.\n\nBecause gorun is a separate tool, and not included in the Go distribution, it must first be installed via `go get launchpad.net/gorun`.  Once it's installed, you can make use of it quite simply:\n\n```\n#!/usr/bin/gorun\n\npackage main\n\nfunc main() {\n    println(\"Hello world!\")\n}\n```\n\nThis file is now executable on the command line (after setting the execution bit via `chmod +x`, of course).  However, it's also technically invalid Go. This means you can't compile the same code via `go build` that you would run with gorun.\n\nAs we said earlier, this solution also requires that your users install gorun, making it less portable than ideal.\n\nAs of March 1st, 2015, [gorun does not compile on OS X](https://bugs.launchpad.net/gorun/+bug/1176275), but it looks like this will be resolved, soon.\n{:.warning}\n\n### Mimic the shebang via Bash\n\nIn UNIX systems, the shebang line is handled by the family of `exec` functions inside the fundamental libc.  The `exec` functions use what's referred to as magic numbers in the first bits of a file to determine what kind of executable it is.  The characters `#!` are simply hard coded as a magic number that corresponds to being run as a script.\n\nBut we can make clever use of the fact that `//` is both a comment in Go, *and* interpreted as a valid part of a file path in Bash, in order to trick Bash into running the file for us instead of `exec`.  This isn't technically a shebang line, but serves the same purpose quite nicely.  The resulting file looks like such:\n\n```\n//usr/bin/go run $0 $@; exit $?\npackage main\n\nfunc main() {\n    println(\"Hello world!\")\n}\n```\n\nThis file is *both* a valid Bash script and valid Go source code.  When Bash runs this file, it executes `/usr/bin/go run $0 $@`, and then immediately exits.  If the file were named \"/path/to/foo.go\", and we ran it like `./foo.go bar baz`, then Bash would execute `/usr/bin/go run ./foo.go \"bar\" \"baz\"`.\n\nAt this point, the file is parsed by `go run`, which ignores the first line as a comment, and dutifully compiles and executes the rest of the file.\n\nThis trick doesn't require a separately installed command, and is relatively portable.  However, all is not roses:  \n\n* The file must end in `.go`, since `go run` will happily ignore it otherwise.\n* This only works when executed via a shell.  It won't work if executed directly by other programs.\n\n### Trade-offs\n\nSadly, unless Rob changes his mind and modifies the Go spec, there is no one-size-fits-all solution in sight.  Both of the recipes above have their drawbacks, and choosing which one to use is entirely about your specific needs and tastes.\n\n"
  },
  {
    "path": "chapters/strings/accessing/index.md",
    "content": "---\ntitle: Accessing Substrings\nquestion: How do I access parts of a given string?\n---\n\nGo allows you to access parts of a string via the normal indexing primitives you're accustomed to using with arrays and slices.  In particular, it allows you to access `mystring[n:m]`.  Either `n` or `m` can be omitted, which implies from the beginning or to the end, respectively.  There's also the primitive `len(s)`, which gives you the number of characters in the string.\n\nHere are some examples:\n\n{% include example.html example=\"index\" %}\n\nAccessing strings by character, word or token are covered in the [Processing a String One Word or Character at a Time](/chapters/strings/processing) recipe.\n\n"
  },
  {
    "path": "chapters/strings/accessing/test_index.expected",
    "content": "Hello\nHello\nello World\nWorld\nello Worl\n"
  },
  {
    "path": "chapters/strings/accessing/test_index.expected.escaped",
    "content": "Hello\nHello\nello World\nWorld\nello Worl\n"
  },
  {
    "path": "chapters/strings/accessing/test_index.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ts := \"Hello World\"\n\tfmt.Println(s[:5])           // the first 5 characters\n\tfmt.Println(s[:len(s)-6])    // the same, but counting back from the end\n\tfmt.Println(s[1:])           // all except the first character\n\tfmt.Println(s[len(s)-5:])    // the last 5 characters\n\tfmt.Println(s[1 : len(s)-1]) // all except the first and last\n}\n"
  },
  {
    "path": "chapters/strings/accessing/test_index.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n\ts := &quot;Hello World&quot;\n\tfmt.Println(s[:5])           // the first 5 characters\n\tfmt.Println(s[:len(s)-6])    // the same, but counting back from the end\n\tfmt.Println(s[1:])           // all except the first character\n\tfmt.Println(s[len(s)-5:])    // the last 5 characters\n\tfmt.Println(s[1 : len(s)-1]) // all except the first and last\n}\n"
  },
  {
    "path": "chapters/strings/concatenation/index.md",
    "content": "---\ntitle: Concatenating Strings\nquestion: How do I combine strings?\n---\n\nhttp://stackoverflow.com/questions/1760757/how-to-efficiently-concatenate-strings-in-go\n\nhttp://srcode.org/2014/08/23/string-concatenation-in-golang/\n"
  },
  {
    "path": "chapters/strings/detecting/index.md",
    "content": "---\ntitle: Detecting a Substring\nquestion: How do I determine if a string contains another string or pattern?\n---\n\nGo prides itself on being a low level language with a rich set of functionality included by default via the standard packages.  The `strings` package is a great example of this.\n\n### Detecting Substrings\n\n* `strings.Contains`\n* `strings.ContainsAny`\n* `strings.HasPrefix`\n* `strings.HasSuffix`\n\n{% include example.html example=\"substrings\" %}\n\n### Detecting Patterns\n\n{% include example.html example=\"regexp\" %}\n\n### Finding Matched Strings\n\n{% include example.html example=\"returned_regexp\" %}\n\n### Detecting Patterns that Include Special Characters\n\n{% include example.html example=\"safe_regexp\" %}\n\n### Precompiling Regular Expressions\n\n* `regexp.Compile`\n* `regexp.MustCompile`\n\n{% include example.html example=\"precompiled_regexp\" %}\n\n"
  },
  {
    "path": "chapters/strings/detecting/test_precompiled_regexp.expected",
    "content": ""
  },
  {
    "path": "chapters/strings/detecting/test_precompiled_regexp.expected.escaped",
    "content": ""
  },
  {
    "path": "chapters/strings/detecting/test_precompiled_regexp.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"unimplemented\")\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_precompiled_regexp.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n\tfmt.Println(&quot;unimplemented&quot;)\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_regexp.expected",
    "content": "Matched: true Error: <nil>\nMatched: false Error: <nil>\nMatched: false Error: error parsing regexp: missing closing ): `(bad regexp`\n"
  },
  {
    "path": "chapters/strings/detecting/test_regexp.expected.escaped",
    "content": "Matched: true Error: &lt;nil&gt;\nMatched: false Error: &lt;nil&gt;\nMatched: false Error: error parsing regexp: missing closing ): `(bad regexp`\n"
  },
  {
    "path": "chapters/strings/detecting/test_regexp.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n)\n\nfunc main() {\n\tmatched, err := regexp.MatchString(\"Wor.*\", \"Hello World\")\n\tfmt.Println(\"Matched:\", matched, \"Error:\", err)\n\tmatched, err = regexp.MatchString(\"Good.*\", \"Hello World\")\n\tfmt.Println(\"Matched:\", matched, \"Error:\", err)\n\tmatched, err = regexp.MatchString(\"(bad regexp\", \"Hello World\")\n\tfmt.Println(\"Matched:\", matched, \"Error:\", err)\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_regexp.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;regexp&quot;\n)\n\nfunc main() {\n\tmatched, err := regexp.MatchString(&quot;Wor.*&quot;, &quot;Hello World&quot;)\n\tfmt.Println(&quot;Matched:&quot;, matched, &quot;Error:&quot;, err)\n\tmatched, err = regexp.MatchString(&quot;Good.*&quot;, &quot;Hello World&quot;)\n\tfmt.Println(&quot;Matched:&quot;, matched, &quot;Error:&quot;, err)\n\tmatched, err = regexp.MatchString(&quot;(bad regexp&quot;, &quot;Hello World&quot;)\n\tfmt.Println(&quot;Matched:&quot;, matched, &quot;Error:&quot;, err)\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_returned_regexp.expected",
    "content": ""
  },
  {
    "path": "chapters/strings/detecting/test_returned_regexp.expected.escaped",
    "content": ""
  },
  {
    "path": "chapters/strings/detecting/test_returned_regexp.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"unimplemented\")\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_returned_regexp.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n\tfmt.Println(&quot;unimplemented&quot;)\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_safe_regexp.expected",
    "content": ""
  },
  {
    "path": "chapters/strings/detecting/test_safe_regexp.expected.escaped",
    "content": ""
  },
  {
    "path": "chapters/strings/detecting/test_safe_regexp.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"unimplemented\")\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_safe_regexp.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n\tfmt.Println(&quot;unimplemented&quot;)\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_substrings.expected",
    "content": "true\nfalse\ntrue\ntrue\ntrue\n"
  },
  {
    "path": "chapters/strings/detecting/test_substrings.expected.escaped",
    "content": "true\nfalse\ntrue\ntrue\ntrue\n"
  },
  {
    "path": "chapters/strings/detecting/test_substrings.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Println(strings.Contains(\"Assume\", \"Ass\"))\n\n\tfmt.Println(strings.ContainsAny(\"team\", \"i\"))\n\tfmt.Println(strings.ContainsAny(\"Hello\", \"aeiou&y\"))\n\n\tfmt.Println(strings.HasPrefix(\"Hello World\", \"Hello\"))\n\tfmt.Println(strings.HasSuffix(\"Hello World\", \"World\"))\n}\n"
  },
  {
    "path": "chapters/strings/detecting/test_substrings.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc main() {\n\tfmt.Println(strings.Contains(&quot;Assume&quot;, &quot;Ass&quot;))\n\n\tfmt.Println(strings.ContainsAny(&quot;team&quot;, &quot;i&quot;))\n\tfmt.Println(strings.ContainsAny(&quot;Hello&quot;, &quot;aeiou&y&quot;))\n\n\tfmt.Println(strings.HasPrefix(&quot;Hello World&quot;, &quot;Hello&quot;))\n\tfmt.Println(strings.HasSuffix(&quot;Hello World&quot;, &quot;World&quot;))\n}\n"
  },
  {
    "path": "chapters/strings/detecting-all/index.md",
    "content": "---\ntitle: Detecting All Substrings\nquestion: How do I gather a list of all substrings matching a pattern?\n---\n\n### Finding All Matches\n\n* `regexp.FindAllString`\n* `regexp.FindAllStringIndex`\n\n\n"
  },
  {
    "path": "chapters/strings/processing/index.md",
    "content": "---\ntitle: Processing a String One Word or Character at a Time\nquestion: Given a string, how do I break it into words or characters and process each one in turn?\n---\n\n### Each Character\n\nBecause of Go's built in support for Unicode \"runes\", processing a string one character at a time is quite straightforward.  Simply iterate over the `range` of that string:\n\n{% include example.html example=\"each_char\" %}\n\n### Each Word\n\nProcessing a string one word at a time is a bit more involved, and depends on your specific needs.  If you're fine with the unsophisticated approach of cutting the string into words based on whitespace, then you're in luck - `strings.Fields` was built just for you:\n\n{% include example.html example=\"words\" %}\n\n### Without Punctuation\n\nHowever, most applications will need a more grammatically tolerant approach, where punctuation is taken into account.  Here we have two options.  We can either make use of a `strings.Replacer`, which we generate via the `strings.NewReplacer` function:\n\n{% include example.html example=\"without_punctuation\" %}\n\nOr we can achieve a bit more clarity by making use of `strings.Map`:\n\n{% include example.html example=\"without_punctuation_using_map\" %}\n\n### Special Separators\n\nThere are other situations where you'd want to split a string based on a separator other than whitespace.  The UNIX `/etc/passwd` file, for example, contains lines of tokens separated by colons.  Splitting each line into the relevant pieces is easy in Go, with the `strings.Split` function, which is a more generic form of `strings.Fields`:\n\n{% include example.html example=\"separator\" %}\n\n"
  },
  {
    "path": "chapters/strings/processing/test_each_char.expected",
    "content": "0  =>  a\n1  =>  b\n2  =>  c\n"
  },
  {
    "path": "chapters/strings/processing/test_each_char.expected.escaped",
    "content": "0  =&gt;  a\n1  =&gt;  b\n2  =&gt;  c\n"
  },
  {
    "path": "chapters/strings/processing/test_each_char.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfor i, c := range \"abc\" {\n\t\tfmt.Println(i, \" => \", string(c))\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_each_char.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n\tfor i, c := range &quot;abc&quot; {\n\t\tfmt.Println(i, &quot; =&gt; &quot;, string(c))\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_separator.expected",
    "content": "0  =>  root\n1  =>  *\n2  =>  0\n3  =>  0\n4  =>  System Administrator\n5  =>  /root\n6  =>  /bin/sh\n"
  },
  {
    "path": "chapters/strings/processing/test_separator.expected.escaped",
    "content": "0  =&gt;  root\n1  =&gt;  *\n2  =&gt;  0\n3  =&gt;  0\n4  =&gt;  System Administrator\n5  =&gt;  /root\n6  =&gt;  /bin/sh\n"
  },
  {
    "path": "chapters/strings/processing/test_separator.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\ts := \"root:*:0:0:System Administrator:/root:/bin/sh\"\n\twords := strings.Split(s, \":\")\n\tfor i, word := range words {\n\t\tfmt.Println(i, \" => \", word)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_separator.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc main() {\n\ts := &quot;root:*:0:0:System Administrator:/root:/bin/sh&quot;\n\twords := strings.Split(s, &quot;:&quot;)\n\tfor i, word := range words {\n\t\tfmt.Println(i, &quot; =&gt; &quot;, word)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_without_punctuation.expected",
    "content": "0  =>  This\n1  =>  that\n2  =>  and\n3  =>  the\n4  =>  other\n"
  },
  {
    "path": "chapters/strings/processing/test_without_punctuation.expected.escaped",
    "content": "0  =&gt;  This\n1  =&gt;  that\n2  =&gt;  and\n3  =&gt;  the\n4  =&gt;  other\n"
  },
  {
    "path": "chapters/strings/processing/test_without_punctuation.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\ts := \"This, that, and the other.\"\n\treplacer := strings.NewReplacer(\",\", \"\", \".\", \"\", \";\", \"\")\n\ts = replacer.Replace(s)\n\twords := strings.Fields(s)\n\tfor i, word := range words {\n\t\tfmt.Println(i, \" => \", word)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_without_punctuation.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc main() {\n\ts := &quot;This, that, and the other.&quot;\n\treplacer := strings.NewReplacer(&quot;,&quot;, &quot;&quot;, &quot;.&quot;, &quot;&quot;, &quot;;&quot;, &quot;&quot;)\n\ts = replacer.Replace(s)\n\twords := strings.Fields(s)\n\tfor i, word := range words {\n\t\tfmt.Println(i, &quot; =&gt; &quot;, word)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_without_punctuation_using_map.expected",
    "content": "0  =>  This\n1  =>  that\n2  =>  and\n3  =>  the\n4  =>  other\n"
  },
  {
    "path": "chapters/strings/processing/test_without_punctuation_using_map.expected.escaped",
    "content": "0  =&gt;  This\n1  =&gt;  that\n2  =&gt;  and\n3  =&gt;  the\n4  =&gt;  other\n"
  },
  {
    "path": "chapters/strings/processing/test_without_punctuation_using_map.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tremovePunctuation := func(r rune) rune {\n\t\tif strings.ContainsRune(\".,:;\", r) {\n\t\t\treturn -1\n\t\t} else {\n\t\t\treturn r\n\t\t}\n\t}\n\n\ts := \"This, that, and the other.\"\n\ts = strings.Map(removePunctuation, s)\n\twords := strings.Fields(s)\n\tfor i, word := range words {\n\t\tfmt.Println(i, \" => \", word)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_without_punctuation_using_map.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc main() {\n\tremovePunctuation := func(r rune) rune {\n\t\tif strings.ContainsRune(&quot;.,:;&quot;, r) {\n\t\t\treturn -1\n\t\t} else {\n\t\t\treturn r\n\t\t}\n\t}\n\n\ts := &quot;This, that, and the other.&quot;\n\ts = strings.Map(removePunctuation, s)\n\twords := strings.Fields(s)\n\tfor i, word := range words {\n\t\tfmt.Println(i, &quot; =&gt; &quot;, word)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_words.expected",
    "content": "0  =>  This,\n1  =>  that,\n2  =>  and\n3  =>  the\n4  =>  other.\n"
  },
  {
    "path": "chapters/strings/processing/test_words.expected.escaped",
    "content": "0  =&gt;  This,\n1  =&gt;  that,\n2  =&gt;  and\n3  =&gt;  the\n4  =&gt;  other.\n"
  },
  {
    "path": "chapters/strings/processing/test_words.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\twords := strings.Fields(\"This, that, and the other.\")\n\tfor i, word := range words {\n\t\tfmt.Println(i, \" => \", word)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing/test_words.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc main() {\n\twords := strings.Fields(&quot;This, that, and the other.&quot;)\n\tfor i, word := range words {\n\t\tfmt.Println(i, &quot; =&gt; &quot;, word)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing-complex/index.md",
    "content": "---\ntitle: Processing a String by Complex Separators and Patterns\nquestion: Given a string with complex and variable separators, how do I break it into words?\n---\n\nSplitting strings based on a single separator character is fairly simple in Go, but what about more tenacious strings?  If a string uses multiple separators that should be treated equally, then `regexp.Split` is the tool for you:\n\n{% include example.html example=\"regexp_separator\" %}\n\nHowever, some strings are more complex, still -- involving tokens wrapped in complex patterns.  For these situations, `regexp.FindAllStringSubmatch` combined with regexp capture groups will do what you need.\n\n`regexp.FindAllStringSubmatch` will search a string for the regexp, and will return tuples of the matched string and any submatches found via capture groups.\n\n{% include example.html example=\"regexp_match\" %}\n"
  },
  {
    "path": "chapters/strings/processing-complex/test_regexp_match.expected",
    "content": "0 => \"one\" from \"[one]\"\n1 => \"two\" from \"[two]\"\n2 => \"three\" from \"[three]\"\n"
  },
  {
    "path": "chapters/strings/processing-complex/test_regexp_match.expected.escaped",
    "content": "0 =&gt; &quot;one&quot; from &quot;[one]&quot;\n1 =&gt; &quot;two&quot; from &quot;[two]&quot;\n2 =&gt; &quot;three&quot; from &quot;[three]&quot;\n"
  },
  {
    "path": "chapters/strings/processing-complex/test_regexp_match.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n)\n\nfunc main() {\n\ts := \"[one][two][three]\"\n\tmatches := regexp.MustCompile(`\\[(.*?)\\]`).FindAllStringSubmatch(s, -1)\n\tif matches == nil {\n\t\tfmt.Println(\"No matches found.\")\n\t\treturn\n\t}\n\n\tfor i, match := range matches {\n\t\tfull := match[0]\n\t\tsubmatches := match[1:len(match)]\n\t\tfmt.Printf(\"%v => \\\"%v\\\" from \\\"%v\\\"\\n\", i, submatches[0], full)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing-complex/test_regexp_match.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;regexp&quot;\n)\n\nfunc main() {\n\ts := &quot;[one][two][three]&quot;\n\tmatches := regexp.MustCompile(`\\[(.*?)\\]`).FindAllStringSubmatch(s, -1)\n\tif matches == nil {\n\t\tfmt.Println(&quot;No matches found.&quot;)\n\t\treturn\n\t}\n\n\tfor i, match := range matches {\n\t\tfull := match[0]\n\t\tsubmatches := match[1:len(match)]\n\t\tfmt.Printf(&quot;%v =&gt; \\&quot;%v\\&quot; from \\&quot;%v\\&quot;\\n&quot;, i, submatches[0], full)\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing-complex/test_regexp_separator.expected",
    "content": "0  =>  one\n1  =>  two\n2  =>  three\n"
  },
  {
    "path": "chapters/strings/processing-complex/test_regexp_separator.expected.escaped",
    "content": "0  =&gt;  one\n1  =&gt;  two\n2  =&gt;  three\n"
  },
  {
    "path": "chapters/strings/processing-complex/test_regexp_separator.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n)\n\nfunc main() {\n\ts := \"one#two;three\"\n\twords := regexp.MustCompile(\"[#;]\").Split(s, -1)\n\tif words != nil {\n\t\tfor i, word := range words {\n\t\t\tfmt.Println(i, \" => \", word)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/processing-complex/test_regexp_separator.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;regexp&quot;\n)\n\nfunc main() {\n\ts := &quot;one#two;three&quot;\n\twords := regexp.MustCompile(&quot;[#;]&quot;).Split(s, -1)\n\tif words != nil {\n\t\tfor i, word := range words {\n\t\t\tfmt.Println(i, &quot; =&gt; &quot;, word)\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "chapters/strings/reverse/index.md",
    "content": "---\ntitle: Reversing a String by Word or Character\nquestion: How do I reverse a string by word or character?\n---\n\nReversing a string by character is very similar to the process to reverse an\narray.  The difference is that strings are immutable in Go.  Therefore, we must\nfirst convert the string to a mutable array of runes (`[]rune`), perform the\nreverse operation on that, and then re-cast to a string.\n\n{% include example.html example=\"reverse_by_character\" %}\n\nReversing a string by word is a similar process.  First, we convert the string\ninto an array of strings where each entry is a word.  Next we apply the normal\nreverse loop to that array. Finally, we smush the results back together into a\nstring that we can return to the caller.\n\n{% include example.html example=\"reverse_by_word\" %}\n\n"
  },
  {
    "path": "chapters/strings/reverse/test_reverse_by_character.expected",
    "content": "gfedcba\n"
  },
  {
    "path": "chapters/strings/reverse/test_reverse_by_character.expected.escaped",
    "content": "gfedcba\n"
  },
  {
    "path": "chapters/strings/reverse/test_reverse_by_character.go",
    "content": "package main\n\nimport \"fmt\"\n\nfunc reverse(s string) string {\n\tchars := []rune(s)\n\tfor i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {\n\t\tchars[i], chars[j] = chars[j], chars[i]\n\t}\n\treturn string(chars)\n}\n\nfunc main() {\n\tfmt.Printf(\"%v\\n\", reverse(\"abcdefg\"))\n}\n"
  },
  {
    "path": "chapters/strings/reverse/test_reverse_by_character.go.escaped",
    "content": "package main\n\nimport &quot;fmt&quot;\n\nfunc reverse(s string) string {\n\tchars := []rune(s)\n\tfor i, j := 0, len(chars)-1; i &lt; j; i, j = i+1, j-1 {\n\t\tchars[i], chars[j] = chars[j], chars[i]\n\t}\n\treturn string(chars)\n}\n\nfunc main() {\n\tfmt.Printf(&quot;%v\\n&quot;, reverse(&quot;abcdefg&quot;))\n}\n"
  },
  {
    "path": "chapters/strings/reverse/test_reverse_by_word.expected",
    "content": "three two one\n"
  },
  {
    "path": "chapters/strings/reverse/test_reverse_by_word.expected.escaped",
    "content": "three two one\n"
  },
  {
    "path": "chapters/strings/reverse/test_reverse_by_word.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc reverse_words(s string) string {\n\twords := strings.Fields(s)\n\tfor i, j := 0, len(words)-1; i < j; i, j = i+1, j-1 {\n\t\twords[i], words[j] = words[j], words[i]\n\t}\n\treturn strings.Join(words, \" \")\n}\n\nfunc main() {\n\tfmt.Println(reverse_words(\"one two three\"))\n}\n"
  },
  {
    "path": "chapters/strings/reverse/test_reverse_by_word.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc reverse_words(s string) string {\n\twords := strings.Fields(s)\n\tfor i, j := 0, len(words)-1; i &lt; j; i, j = i+1, j-1 {\n\t\twords[i], words[j] = words[j], words[i]\n\t}\n\treturn strings.Join(words, &quot; &quot;)\n}\n\nfunc main() {\n\tfmt.Println(reverse_words(&quot;one two three&quot;))\n}\n"
  },
  {
    "path": "chapters/strings/sentence/index.md",
    "content": "---\ntitle: Turning an Array into a Sentence\nquestion: How can I convert an array of words into a readable sentence of options?\n---\n\nIf you're content with joining each of the strings in a given array using a consistent separator, then `strings.Join()` is the tool for you.  `Join()` takes an array of strings, and a final string that acts as the separator.  If we pass in `\", \"` as our separator, then we come pretty close to producing a sentence:\n\n{% include example.html example=\"join\" %}\n\nSometimes this is good enough, but we often want the resulting string to read more like and English sentence, offering all or some of the options.  To produce this, we can create a `ToSentence` method like such:\n\n{% include example.html example=\"sentence\" %}\n\n...which is much more friendly when presented to our users.\n"
  },
  {
    "path": "chapters/strings/sentence/test_join.expected",
    "content": "this, that, the other\n"
  },
  {
    "path": "chapters/strings/sentence/test_join.expected.escaped",
    "content": "this, that, the other\n"
  },
  {
    "path": "chapters/strings/sentence/test_join.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\ta := []string{\"this\", \"that\", \"the other\"}\n\tfmt.Println(strings.Join(a, \", \"))\n}\n"
  },
  {
    "path": "chapters/strings/sentence/test_join.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc main() {\n\ta := []string{&quot;this&quot;, &quot;that&quot;, &quot;the other&quot;}\n\tfmt.Println(strings.Join(a, &quot;, &quot;))\n}\n"
  },
  {
    "path": "chapters/strings/sentence/test_sentence.expected",
    "content": "this, that, or the other\nthis, that, and the other\n"
  },
  {
    "path": "chapters/strings/sentence/test_sentence.expected.escaped",
    "content": "this, that, or the other\nthis, that, and the other\n"
  },
  {
    "path": "chapters/strings/sentence/test_sentence.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc ToSentence(words []string, andOrOr string) string {\n\tl := len(words)\n\twordsForSentence := make([]string, l)\n\tcopy(wordsForSentence, words)\n\twordsForSentence[l-1] = andOrOr + \" \" + wordsForSentence[l-1]\n\treturn strings.Join(wordsForSentence, \", \")\n}\n\nfunc main() {\n\ta := []string{\"this\", \"that\", \"the other\"}\n\tfmt.Println(ToSentence(a, \"or\"))\n\tfmt.Println(ToSentence(a, \"and\"))\n}\n"
  },
  {
    "path": "chapters/strings/sentence/test_sentence.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc ToSentence(words []string, andOrOr string) string {\n\tl := len(words)\n\twordsForSentence := make([]string, l)\n\tcopy(wordsForSentence, words)\n\twordsForSentence[l-1] = andOrOr + &quot; &quot; + wordsForSentence[l-1]\n\treturn strings.Join(wordsForSentence, &quot;, &quot;)\n}\n\nfunc main() {\n\ta := []string{&quot;this&quot;, &quot;that&quot;, &quot;the other&quot;}\n\tfmt.Println(ToSentence(a, &quot;or&quot;))\n\tfmt.Println(ToSentence(a, &quot;and&quot;))\n}\n"
  },
  {
    "path": "chapters/strings/strings_suit_test.go",
    "content": "package strings_test\n\nimport (\n\t. \"github.com/onsi/ginkgo\"\n\t. \"github.com/onsi/gomega\"\n\n\t\"testing\"\n)\n\nfunc TestStrings(t *testing.T) {\n\tRegisterFailHandler(Fail)\n\tRunSpecs(t, \"Strings Suite\")\n}\n"
  },
  {
    "path": "chapters/strings/strings_test.go",
    "content": "package strings_test\n\nimport (\n\t\"strings\"\n\n\t. \"github.com/onsi/ginkgo\"\n\t. \"github.com/onsi/gomega\"\n)\n\nvar _ = Describe(\"Strings\", func() {\n\tContext(\"Substrings\", func() {\n\t\tIt(\"can detect substrings\", func() {\n\t\t\tExpect(strings.Contains(\"Assume\", \"Ass\")).To(Equal(true))\n\n\t\t\tExpect(strings.ContainsAny(\"team\", \"i\")).To(Equal(false))\n\t\t\tExpect(strings.ContainsAny(\"Hello\", \"aeiou&y\")).To(Equal(true))\n\n\t\t\tExpect(strings.HasPrefix(\"Hello World\", \"Hello\")).To(Equal(true))\n\t\t\tExpect(strings.HasSuffix(\"Hello World\", \"World\")).To(Equal(true))\n\t\t})\n\n\t\tIt(\"can access by index\", func() {\n\t\t\ts := \"Hello World\"\n\t\t\tExpect(s[:5]).To(Equal(\"Hello\"))\n\t\t\tExpect(s[:len(s)-6]).To(Equal(\"Hello\"))\n\t\t\tExpect(s[len(s)-5 : len(s)]).To(Equal(\"World\"))\n\t\t\tExpect(s[1 : len(s)-1]).To(Equal(\"ello Worl\"))\n\t\t})\n\n\t\tIt(\"can split a string into words\", func() {\n\t\t\ts := \"Hello World\"\n\t\t\tExpect(strings.Fields(s)).To(Equal([]string{\"Hello\", \"World\"}))\n\t\t\tExpect(strings.Split(s, \"o\")).To(Equal([]string{\"Hell\", \" W\", \"rld\"}))\n\t\t})\n\n\t\tIt(\"can replace substrings\", func() {\n\t\t\tExpect(strings.Replace(\"Hello World\", \"l\", \"L\", 2)).To(Equal(\"HeLLo World\"))\n\t\t\tExpect(strings.Replace(\"Hello World\", \"l\", \"L\", -1)).To(Equal(\"HeLLo WorLd\"))\n\n\t\t\tr := strings.NewReplacer(\"<\", \"&lt;\", \">\", \"&gt;\")\n\t\t\tExpect(r.Replace(\"<Hello> <World>\")).To(Equal(\"&lt;Hello&gt; &lt;World&gt;\"))\n\t\t})\n\t})\n\n})\n"
  },
  {
    "path": "chapters/strings/title/index.md",
    "content": "---\ntitle: Properly Capitalizing a Title\nquestion: How do I convert a string into a properly capitalized title?\n---\n\n### Welcome To The Dollhouse?\n\nGolang comes packaged with a good number of very useful string manipulation helpers in the `strings` package.  Unfortunately, the `strings.Title()` method is clever but naive in implementation.   Let's look at the source for `strings.Title()` (this is from the 1.4.1 version of Go):\n\n``` go\n// Title returns a copy of the string s with all Unicode letters that \n// begin words mapped to their title case.\n//\n// BUG: The rule Title uses for word boundaries does not handle Unicode\n// punctuation properly.\nfunc Title(s string) string {\n\t// Use a closure here to remember state.\n\t// Hackish but effective. Depends on Map scanning in order and calling\n\t// the closure once per rune.\n\tprev := ' '\n\treturn Map(\n\t\tfunc(r rune) rune {\n\t\t\tif isSeparator(prev) {\n\t\t\t\tprev = r\n\t\t\t\treturn unicode.ToTitle(r)\n\t\t\t}\n\t\t\tprev = r\n\t\t\treturn r\n\t\t},\n\t\ts)\n}\n```\n\n`strings.Map()` iterates over each character of a string, replacing it with whatever character is returned from the `func(r rune) rune` method supplied by the caller.  `strings.Title()` makes use of this in a clever way, by recording the current character as `prev`, so that the next run can tell whether it's at a word boundary.\n\nThe flaw in this implementation is that it doesn't account for small words. For example:  \n\n{% include example.html example=\"simple\" %}\n\n### Welcome _to the_ Dollhouse!\n\nOur English professors wouldn't be happy with the results.  Small words, such as \"a\" and \"the\" shouldn't be capitalized in a title.  In order to _properly_ capitalize a string, we have to do a bit more work.  \n\n{% include example.html example=\"proper\" %}\n\nIn the implementation above, we first split the string into an array of words, loop through them, and only capitalize those who don't match our hard-coded list of small words.  Finally, we join the words up into a single string, and return the result.  \n\nGo doesn't have anything like an `array.Includes(element)` predicate, so we get a bit clever when determining if the word is a small word by making use of spaces as word boundaries.\n\nAs you can see in the output above, the printed title is grammatically correct.\n"
  },
  {
    "path": "chapters/strings/title/test_proper.expected",
    "content": "Welcome to the Dollhouse!\n"
  },
  {
    "path": "chapters/strings/title/test_proper.expected.escaped",
    "content": "Welcome to the Dollhouse!\n"
  },
  {
    "path": "chapters/strings/title/test_proper.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc properTitle(input string) string {\n\twords := strings.Fields(input)\n\tsmallwords := \" a an on the to \"\n\n\tfor index, word := range words {\n\t\tif strings.Contains(smallwords, \" \"+word+\" \") {\n\t\t\twords[index] = word\n\t\t} else {\n\t\t\twords[index] = strings.Title(word)\n\t\t}\n\t}\n\treturn strings.Join(words, \" \")\n}\n\nfunc main() {\n\tfmt.Println(properTitle(\"welcome to the dollhouse!\"))\n}\n"
  },
  {
    "path": "chapters/strings/title/test_proper.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc properTitle(input string) string {\n\twords := strings.Fields(input)\n\tsmallwords := &quot; a an on the to &quot;\n\n\tfor index, word := range words {\n\t\tif strings.Contains(smallwords, &quot; &quot;+word+&quot; &quot;) {\n\t\t\twords[index] = word\n\t\t} else {\n\t\t\twords[index] = strings.Title(word)\n\t\t}\n\t}\n\treturn strings.Join(words, &quot; &quot;)\n}\n\nfunc main() {\n\tfmt.Println(properTitle(&quot;welcome to the dollhouse!&quot;))\n}\n"
  },
  {
    "path": "chapters/strings/title/test_simple.expected",
    "content": "Welcome To The Dollhouse!\n"
  },
  {
    "path": "chapters/strings/title/test_simple.expected.escaped",
    "content": "Welcome To The Dollhouse!\n"
  },
  {
    "path": "chapters/strings/title/test_simple.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Println(strings.Title(\"welcome to the dollhouse!\"))\n}\n"
  },
  {
    "path": "chapters/strings/title/test_simple.go.escaped",
    "content": "package main\n\nimport (\n\t&quot;fmt&quot;\n\t&quot;strings&quot;\n)\n\nfunc main() {\n\tfmt.Println(strings.Title(&quot;welcome to the dollhouse!&quot;))\n}\n"
  },
  {
    "path": "index.md",
    "content": "---\nlayout: default\ntitle: Go Cookbook\n---\n\nThe Go Cookbook is built with the help of people like yourself.  Please support this site and help others by [contributing a recipe of your own](https://github.com/golangcookbook/golangcookbook.github.io#readme).\n\n---\n\n{% for chapter in site.data.chapters %}\n### {{ chapter.title }}\n\n  <ul>\n  {% for recipe in chapter.recipes %}\n    <li>\n    {% if recipe.wip %}\n      <strong>[work in progress]</strong>\n    {% endif %}\n    {% if recipe.path %}\n      <a href=\"{{recipe.path}}\">{{ recipe.title }}</a>\n    {% else %}\n      {{ recipe.title }}\n    {% endif %}\n    </li>\n  {% endfor %}\n  </ul>\n{% endfor %}\n\n"
  },
  {
    "path": "params.json",
    "content": "{\"name\":\"Go Cookbook\",\"tagline\":\"Go Cookbook\",\"body\":\"### Welcome to GitHub Pages.\\r\\nThis automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:\\r\\n\\r\\n```\\r\\n$ cd your_repo_root/repo_name\\r\\n$ git fetch origin\\r\\n$ git checkout gh-pages\\r\\n```\\r\\n\\r\\nIf you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.\\r\\n\\r\\n### Designer Templates\\r\\nWe've crafted some handsome templates for you to use. Go ahead and continue to layouts to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved if it remained markdown format.\\r\\n\\r\\n### Rather Drive Stick?\\r\\nIf you prefer to not use the automatic generator, push a branch named `gh-pages` to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator written by our own Tom Preston-Werner. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.\\r\\n\\r\\n### Authors and Contributors\\r\\nYou can @mention a GitHub username to generate a link to their profile. The resulting `<a>` element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.\\r\\n\\r\\n### Support or Contact\\r\\nHaving trouble with Pages? Check out the documentation at https://help.github.com/pages or contact support@github.com and we’ll help you sort it out.\\r\\n\",\"google\":\"\",\"note\":\"Don't delete this file! It's used internally to help with page regeneration.\"}"
  },
  {
    "path": "run",
    "content": "#!/usr/bin/env bash\n\nset -eou pipefail\n\ndocker build . -t golangcookbook.com\ndocker run --rm -it -p 8000:8000 -p 8001:8001 -u \"$(id -u):$(id -g)\" -v \"$PWD:/site\" golangcookbook.com \"$@\"\n"
  },
  {
    "path": "stylesheets/print.css",
    "content": "html, body, div, span, applet, object, iframe,\nh1, h2, h3, h4, h5, h6, p, blockquote, pre,\na, abbr, acronym, address, big, cite, code,\ndel, dfn, em, img, ins, kbd, q, s, samp,\nsmall, strike, strong, sub, sup, tt, var,\nb, u, i, center,\ndl, dt, dd, ol, ul, li,\nfieldset, form, label, legend,\ntable, caption, tbody, tfoot, thead, tr, th, td,\narticle, aside, canvas, details, embed,\nfigure, figcaption, footer, header, hgroup,\nmenu, nav, output, ruby, section, summary,\ntime, mark, audio, video {\n  padding: 0;\n  margin: 0;\n  font: inherit;\n  font-size: 100%;\n  vertical-align: baseline;\n  border: 0;\n}\n/* HTML5 display-role reset for older browsers */\narticle, aside, details, figcaption, figure,\nfooter, header, hgroup, menu, nav, section {\n  display: block;\n}\nbody {\n  line-height: 1;\n}\nol, ul {\n  list-style: none;\n}\nblockquote, q {\n  quotes: none;\n}\nblockquote:before, blockquote:after,\nq:before, q:after {\n  content: '';\n  content: none;\n}\ntable {\n  border-spacing: 0;\n  border-collapse: collapse;\n}\nbody {\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: 13px;\n  line-height: 1.5;\n  color: #000;\n}\n\na {\n  font-weight: bold;\n  color: #d5000d;\n}\n\nheader {\n  padding-top: 35px;\n  padding-bottom: 10px;\n}\n\nheader h1 {\n  font-size: 48px;\n  font-weight: bold;\n  line-height: 1.2;\n  color: #303030;\n  letter-spacing: -1px;\n}\n\nheader h2 {\n  font-size: 24px;\n  font-weight: normal;\n  line-height: 1.3;\n  color: #aaa;\n  letter-spacing: -1px;\n}\n#downloads {\n  display: none;\n}\n#main_content {\n  padding-top: 20px;\n}\n\ncode, pre {\n  margin-bottom: 30px;\n  font-family: Monaco, \"Bitstream Vera Sans Mono\", \"Lucida Console\", Terminal;\n  font-size: 12px;\n  color: #222;\n}\n\ncode {\n  padding: 0 3px;\n}\n\npre {\n  padding: 20px;\n  overflow: auto;\n  border: solid 1px #ddd;\n}\npre code {\n  padding: 0;\n}\n\nul, ol, dl {\n  margin-bottom: 20px;\n}\n\n\n/* COMMON STYLES */\n\ntable {\n  width: 100%;\n  border: 1px solid #ebebeb;\n}\n\nth {\n  font-weight: 500;\n}\n\ntd {\n  font-weight: 300;\n  text-align: center;\n  border: 1px solid #ebebeb;\n}\n\nform {\n  padding: 20px;\n  background: #f2f2f2;\n\n}\n\n\n/* GENERAL ELEMENT TYPE STYLES */\n\nh1 {\n  font-size: 2.8em;\n}\n\nh2 {\n  margin-bottom: 8px;\n  font-size: 22px;\n  font-weight: bold;\n  color: #303030;\n}\n\nh3 {\n  margin-bottom: 8px;\n  font-size: 18px;\n  font-weight: bold;\n  color: #d5000d;\n}\n\nh4 {\n  font-size: 16px;\n  font-weight: bold;\n  color: #303030;\n}\n\nh5 {\n  font-size: 1em;\n  color: #303030;\n}\n\nh6 {\n  font-size: .8em;\n  color: #303030;\n}\n\np {\n  margin-bottom: 20px;\n  font-weight: 300;\n}\n\na {\n  text-decoration: none;\n}\n\np a {\n  font-weight: 400;\n}\n\nblockquote {\n  padding: 0 0 0 30px;\n  margin-bottom: 20px;\n  font-size: 1.6em;\n  border-left: 10px solid #e9e9e9;\n}\n\nul li {\n  padding-left: 20px;\n  list-style-position: inside;\n  list-style: disc;\n}\n\nol li {\n  padding-left: 3px;\n  list-style-position: inside;\n  list-style: decimal;\n}\n\ndl dd {\n  font-style: italic;\n  font-weight: 100;\n}\n\nfooter {\n  padding-top: 20px;\n  padding-bottom: 30px;\n  margin-top: 40px;\n  font-size: 13px;\n  color: #aaa;\n}\n\nfooter a {\n  color: #666;\n}\n\n/* MISC */\n.clearfix:after {\n  display: block;\n  height: 0;\n  clear: both;\n  visibility: hidden;\n  content: '.';\n}\n\n.clearfix {display: inline-block;}\n* html .clearfix {height: 1%;}\n.clearfix {display: block;}"
  },
  {
    "path": "stylesheets/pygment_trac.css",
    "content": ".highlight  { background: #ffffff; }\n.highlight .c { color: #999988; font-style: italic } /* Comment */\n.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */\n.highlight .k { font-weight: bold } /* Keyword */\n.highlight .o { font-weight: bold } /* Operator */\n.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */\n.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */\n.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */\n.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */\n.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */\n.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */\n.highlight .ge { font-style: italic } /* Generic.Emph */\n.highlight .gr { color: #aa0000 } /* Generic.Error */\n.highlight .gh { color: #999999 } /* Generic.Heading */\n.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */\n.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */\n.highlight .go { color: #888888 } /* Generic.Output */\n.highlight .gp { color: #555555 } /* Generic.Prompt */\n.highlight .gs { font-weight: bold } /* Generic.Strong */\n.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */\n.highlight .gt { color: #aa0000 } /* Generic.Traceback */\n.highlight .kc { font-weight: bold } /* Keyword.Constant */\n.highlight .kd { font-weight: bold } /* Keyword.Declaration */\n.highlight .kn { font-weight: bold } /* Keyword.Namespace */\n.highlight .kp { font-weight: bold } /* Keyword.Pseudo */\n.highlight .kr { font-weight: bold } /* Keyword.Reserved */\n.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */\n.highlight .m { color: #009999 } /* Literal.Number */\n.highlight .s { color: #d14 } /* Literal.String */\n.highlight .na { color: #008080 } /* Name.Attribute */\n.highlight .nb { color: #0086B3 } /* Name.Builtin */\n.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */\n.highlight .no { color: #008080 } /* Name.Constant */\n.highlight .ni { color: #800080 } /* Name.Entity */\n.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */\n.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */\n.highlight .nn { color: #555555 } /* Name.Namespace */\n.highlight .nt { color: #000080 } /* Name.Tag */\n.highlight .nv { color: #008080 } /* Name.Variable */\n.highlight .ow { font-weight: bold } /* Operator.Word */\n.highlight .w { color: #bbbbbb } /* Text.Whitespace */\n.highlight .mf { color: #009999 } /* Literal.Number.Float */\n.highlight .mh { color: #009999 } /* Literal.Number.Hex */\n.highlight .mi { color: #009999 } /* Literal.Number.Integer */\n.highlight .mo { color: #009999 } /* Literal.Number.Oct */\n.highlight .sb { color: #d14 } /* Literal.String.Backtick */\n.highlight .sc { color: #d14 } /* Literal.String.Char */\n.highlight .sd { color: #d14 } /* Literal.String.Doc */\n.highlight .s2 { color: #d14 } /* Literal.String.Double */\n.highlight .se { color: #d14 } /* Literal.String.Escape */\n.highlight .sh { color: #d14 } /* Literal.String.Heredoc */\n.highlight .si { color: #d14 } /* Literal.String.Interpol */\n.highlight .sx { color: #d14 } /* Literal.String.Other */\n.highlight .sr { color: #009926 } /* Literal.String.Regex */\n.highlight .s1 { color: #d14 } /* Literal.String.Single */\n.highlight .ss { color: #990073 } /* Literal.String.Symbol */\n.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */\n.highlight .vc { color: #008080 } /* Name.Variable.Class */\n.highlight .vg { color: #008080 } /* Name.Variable.Global */\n.highlight .vi { color: #008080 } /* Name.Variable.Instance */\n.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */\n\n.type-csharp .highlight .k { color: #0000FF }\n.type-csharp .highlight .kt { color: #0000FF }\n.type-csharp .highlight .nf { color: #000000; font-weight: normal }\n.type-csharp .highlight .nc { color: #2B91AF }\n.type-csharp .highlight .nn { color: #000000 }\n.type-csharp .highlight .s { color: #A31515 }\n.type-csharp .highlight .sc { color: #A31515 }\n"
  },
  {
    "path": "stylesheets/site.scss",
    "content": "---\n---\n\nh2.recipe {\n  &:before { \n    content: \"Recipe: \";\n    font-weight: bold;\n  }\n}\n\np.question {\n  padding: 1em;\n  padding-left: 75px;\n  background: #FFF5B0 url(../images/question.png) 10px 10px no-repeat;\n  background-size: 50px 50px;\n  border: 1px dashed #2360C2;\n  min-height: 50px;\n}\n\np.warning {\n  &:before { \n    content: \"Warning: \";\n    font-weight: bold;\n  }\n  padding: 1em;\n  padding-left: 75px;\n  background: #FFF5B0 url(../images/warning.png) 10px 10px no-repeat;\n  background-size: 50px 50px;\n  border: 1px solid #FF8000;\n  min-height: 50px;\n}\n\n\n.example {\n  padding: 0px;\n  margin-bottom: 20px;\n\t.filename {\n\t\tdisplay: block;\n\t\tfont-size: 75%;\n\t\ttext-align: right;\n\t\tcolor: #ccc;\n\t}\n  pre { \n    margin: 0; \n    padding: 10px 10px;\n  }\n  .output pre, .output code {\n    .shell { color: #aaaaaa; }\n    background: #333333;\n    color: white;\n  }\n}\n"
  },
  {
    "path": "stylesheets/stylesheet.css",
    "content": "/*! normalize.css v3.0.2 | MIT License | git.io/normalize */\n\n/**\n * 1. Set default font family to sans-serif.\n * 2. Prevent iOS text size adjust after orientation change, without disabling\n *    user zoom.\n */\n\nhtml {\n  font-family: sans-serif; /* 1 */\n  -webkit-text-size-adjust: 100%; /* 2 */\n  -ms-text-size-adjust: 100%; /* 2 */\n}\n\n/**\n * Remove default margin.\n */\n\nbody {\n  margin: 0;\n}\n\n/* HTML5 display definitions\n   ========================================================================== */\n\n/**\n * Correct `block` display not defined for any HTML5 element in IE 8/9.\n * Correct `block` display not defined for `details` or `summary` in IE 10/11\n * and Firefox.\n * Correct `block` display not defined for `main` in IE 11.\n */\n\narticle,\naside,\ndetails,\nfigcaption,\nfigure,\nfooter,\nheader,\nhgroup,\nmain,\nmenu,\nnav,\nsection,\nsummary {\n  display: block;\n}\n\n/**\n * 1. Correct `inline-block` display not defined in IE 8/9.\n * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.\n */\n\naudio,\ncanvas,\nprogress,\nvideo {\n  display: inline-block; /* 1 */\n  vertical-align: baseline; /* 2 */\n}\n\n/**\n * Prevent modern browsers from displaying `audio` without controls.\n * Remove excess height in iOS 5 devices.\n */\n\naudio:not([controls]) {\n  display: none;\n  height: 0;\n}\n\n/**\n * Address `[hidden]` styling not present in IE 8/9/10.\n * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22.\n */\n\n[hidden],\ntemplate {\n  display: none;\n}\n\n/* Links\n   ========================================================================== */\n\n/**\n * Remove the gray background color from active links in IE 10.\n */\n\na {\n  background-color: transparent;\n}\n\n/**\n * Improve readability when focused and also mouse hovered in all browsers.\n */\n\na:active,\na:hover {\n  outline: 0;\n}\n\n/* Text-level semantics\n   ========================================================================== */\n\n/**\n * Address styling not present in IE 8/9/10/11, Safari, and Chrome.\n */\n\nabbr[title] {\n  border-bottom: 1px dotted;\n}\n\n/**\n * Address style set to `bolder` in Firefox 4+, Safari, and Chrome.\n */\n\nb,\nstrong {\n  font-weight: bold;\n}\n\n/**\n * Address styling not present in Safari and Chrome.\n */\n\ndfn {\n  font-style: italic;\n}\n\n/**\n * Address variable `h1` font-size and margin within `section` and `article`\n * contexts in Firefox 4+, Safari, and Chrome.\n */\n\nh1 {\n  margin: 0.67em 0;\n  font-size: 2em;\n}\n\n/**\n * Address styling not present in IE 8/9.\n */\n\nmark {\n  color: #000;\n  background: #ff0;\n}\n\n/**\n * Address inconsistent and variable font size in all browsers.\n */\n\nsmall {\n  font-size: 80%;\n}\n\n/**\n * Prevent `sub` and `sup` affecting `line-height` in all browsers.\n */\n\nsub,\nsup {\n  position: relative;\n  font-size: 75%;\n  line-height: 0;\n  vertical-align: baseline;\n}\n\nsup {\n  top: -0.5em;\n}\n\nsub {\n  bottom: -0.25em;\n}\n\n/* Embedded content\n   ========================================================================== */\n\n/**\n * Remove border when inside `a` element in IE 8/9/10.\n */\n\nimg {\n  border: 0;\n}\n\n/**\n * Correct overflow not hidden in IE 9/10/11.\n */\n\nsvg:not(:root) {\n  overflow: hidden;\n}\n\n/* Grouping content\n   ========================================================================== */\n\n/**\n * Address margin not present in IE 8/9 and Safari.\n */\n\nfigure {\n  margin: 1em 40px;\n}\n\n/**\n * Address differences between Firefox and other browsers.\n */\n\nhr {\n  height: 0;\n  -moz-box-sizing: content-box;\n  box-sizing: content-box;\n}\n\n/**\n * Contain overflow in all browsers.\n */\n\npre {\n  overflow: auto;\n}\n\n/**\n * Address odd `em`-unit font size rendering in all browsers.\n */\n\ncode,\nkbd,\npre,\nsamp {\n  font-family: monospace, monospace;\n  font-size: 1em;\n}\n\n/* Forms\n   ========================================================================== */\n\n/**\n * Known limitation: by default, Chrome and Safari on OS X allow very limited\n * styling of `select`, unless a `border` property is set.\n */\n\n/**\n * 1. Correct color not being inherited.\n *    Known issue: affects color of disabled elements.\n * 2. Correct font properties not being inherited.\n * 3. Address margins set differently in Firefox 4+, Safari, and Chrome.\n */\n\nbutton,\ninput,\noptgroup,\nselect,\ntextarea {\n  margin: 0; /* 3 */\n  font: inherit; /* 2 */\n  color: inherit; /* 1 */\n}\n\n/**\n * Address `overflow` set to `hidden` in IE 8/9/10/11.\n */\n\nbutton {\n  overflow: visible;\n}\n\n/**\n * Address inconsistent `text-transform` inheritance for `button` and `select`.\n * All other form control elements do not inherit `text-transform` values.\n * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.\n * Correct `select` style inheritance in Firefox.\n */\n\nbutton,\nselect {\n  text-transform: none;\n}\n\n/**\n * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`\n *    and `video` controls.\n * 2. Correct inability to style clickable `input` types in iOS.\n * 3. Improve usability and consistency of cursor style between image-type\n *    `input` and others.\n */\n\nbutton,\nhtml input[type=\"button\"], /* 1 */\ninput[type=\"reset\"],\ninput[type=\"submit\"] {\n  -webkit-appearance: button; /* 2 */\n  cursor: pointer; /* 3 */\n}\n\n/**\n * Re-set default cursor for disabled elements.\n */\n\nbutton[disabled],\nhtml input[disabled] {\n  cursor: default;\n}\n\n/**\n * Remove inner padding and border in Firefox 4+.\n */\n\nbutton::-moz-focus-inner,\ninput::-moz-focus-inner {\n  padding: 0;\n  border: 0;\n}\n\n/**\n * Address Firefox 4+ setting `line-height` on `input` using `!important` in\n * the UA stylesheet.\n */\n\ninput {\n  line-height: normal;\n}\n\n/**\n * It's recommended that you don't attempt to style these elements.\n * Firefox's implementation doesn't respect box-sizing, padding, or width.\n *\n * 1. Address box sizing set to `content-box` in IE 8/9/10.\n * 2. Remove excess padding in IE 8/9/10.\n */\n\ninput[type=\"checkbox\"],\ninput[type=\"radio\"] {\n  box-sizing: border-box; /* 1 */\n  padding: 0; /* 2 */\n}\n\n/**\n * Fix the cursor style for Chrome's increment/decrement buttons. For certain\n * `font-size` values of the `input`, it causes the cursor style of the\n * decrement button to change from `default` to `text`.\n */\n\ninput[type=\"number\"]::-webkit-inner-spin-button,\ninput[type=\"number\"]::-webkit-outer-spin-button {\n  height: auto;\n}\n\n/**\n * 1. Address `appearance` set to `searchfield` in Safari and Chrome.\n * 2. Address `box-sizing` set to `border-box` in Safari and Chrome\n *    (include `-moz` to future-proof).\n */\n\ninput[type=\"search\"] {\n  -webkit-box-sizing: content-box; /* 2 */\n  -moz-box-sizing: content-box;\n  box-sizing: content-box;\n  -webkit-appearance: textfield; /* 1 */\n}\n\n/**\n * Remove inner padding and search cancel button in Safari and Chrome on OS X.\n * Safari (but not Chrome) clips the cancel button when the search input has\n * padding (and `textfield` appearance).\n */\n\ninput[type=\"search\"]::-webkit-search-cancel-button,\ninput[type=\"search\"]::-webkit-search-decoration {\n  -webkit-appearance: none;\n}\n\n/**\n * Define consistent border, margin, and padding.\n */\n\nfieldset {\n  padding: 0.35em 0.625em 0.75em;\n  margin: 0 2px;\n  border: 1px solid #c0c0c0;\n}\n\n/**\n * 1. Correct `color` not being inherited in IE 8/9/10/11.\n * 2. Remove padding so people aren't caught out if they zero out fieldsets.\n */\n\nlegend {\n  padding: 0; /* 2 */\n  border: 0; /* 1 */\n}\n\n/**\n * Remove default vertical scrollbar in IE 8/9/10/11.\n */\n\ntextarea {\n  overflow: auto;\n}\n\n/**\n * Don't inherit the `font-weight` (applied by a rule above).\n * NOTE: the default cannot safely be changed in Chrome and Safari on OS X.\n */\n\noptgroup {\n  font-weight: bold;\n}\n\n/* Tables\n   ========================================================================== */\n\n/**\n * Remove most spacing between table cells.\n */\n\ntable {\n  border-spacing: 0;\n  border-collapse: collapse;\n}\n\ntd,\nth {\n  padding: 0;\n}\n\n/* LAYOUT STYLES */\nbody {\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: 15px;\n  font-weight: 400;\n  line-height: 1.5;\n  color: #666;\n  background: #fafafa url(../images/body-bg.jpg) 0 0 repeat;\n}\n\np {\n  margin-top: 0;\n}\n\na {\n  color: #2879d0;\n}\na:hover {\n  color: #2268b2;\n}\n\nheader {\n  padding-top: 40px;\n  padding-bottom: 40px;\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  background: #2e7bcf url(../images/header-bg.jpg) 0 0 repeat-x;\n  border-bottom: solid 1px #275da1;\n}\n\nheader h1 a {\n  width: 540px;\n  margin-top: 0;\n  margin-bottom: 0.2em;\n  font-size: 72px;\n  font-weight: normal;\n  line-height: 1;\n  color: #fff;\n  letter-spacing: -1px;\n}\n\nheader h2 {\n  width: 540px;\n  margin-top: 0;\n  margin-bottom: 0;\n  font-size: 26px;\n  font-weight: normal;\n  line-height: 1.3;\n  color: #9ddcff;\n  letter-spacing: 0;\n}\n\nheader h2 a { color: #fff; }\nheader h2 a:hover { color: #9ddcff; text-decoration: underline; }\n\nheader h3 {\n  width: 540px;\n  /* margin-top: 0; */\n  margin-bottom: 0;\n  font-size: 20px;\n  font-weight: normal;\n  line-height: 1.3;\n  color: #9ddcff;\n  letter-spacing: 0;\n}\n\n.inner {\n  position: relative;\n  width: 940px;\n  margin: 0 auto;\n}\n\n#content-wrapper {\n  padding-top: 30px;\n  border-top: solid 1px #fff;\n}\n\n#main-content {\n  float: left;\n  width: 690px;\n}\n\n#main-content img {\n  max-width: 100%;\n}\n\naside#sidebar {\n  float: right;\n  width: 200px;\n  min-height: 504px;\n  padding-left: 20px;\n  font-size: 12px;\n  line-height: 1.3;\n  background: transparent url(../images/sidebar-bg.jpg) 0 0 no-repeat;\n}\n\naside#sidebar p.repo-owner,\naside#sidebar p.repo-owner a {\n  font-weight: bold;\n}\n\n#downloads {\n  margin-bottom: 40px;\n}\n\na.button {\n  width: 134px;\n  height: 58px;\n  padding-top: 22px;\n  padding-left: 68px;\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: 23px;\n  line-height: 1.2;\n  color: #fff;\n}\na.button small {\n  display: block;\n  font-size: 11px;\n}\nheader a.button {\n  position: absolute;\n  top: 0;\n  right: 0;\n  background: transparent url(../images/github-button.png) 0 0 no-repeat;\n}\naside a.button {\n  display: block;\n  width: 138px;\n  padding-left: 64px;\n  margin-bottom: 20px;\n  font-size: 21px;\n  background: transparent url(../images/download-button.png) 0 0 no-repeat;\n}\n\ncode, pre {\n  margin-bottom: 30px;\n  font-family: Monaco, \"Bitstream Vera Sans Mono\", \"Lucida Console\", Terminal, monospace;\n  font-size: 13px;\n  color: #222;\n}\n\ncode {\n  padding: 0 3px;\n  background-color: #f2f8fc;\n  border: solid 1px #dbe7f3;\n}\n\npre {\n  padding: 20px;\n  overflow: auto;\n  text-shadow: none;\n  background: #fff;\n  border: solid 1px #f2f2f2;\n}\npre code {\n  padding: 0;\n  color: #2879d0;\n  background-color: #fff;\n  border: none;\n}\n\nul, ol, dl {\n  margin-bottom: 20px;\n}\n\n\n/* COMMON STYLES */\n\nhr {\n  height: 0;\n  margin-top: 1em;\n  margin-bottom: 1em;\n  border: 0;\n  border-top: solid 1px #ddd;\n}\n\ntable {\n  width: 100%;\n  border: 1px solid #ebebeb;\n}\n\nth {\n  font-weight: 500;\n}\n\ntd {\n  font-weight: 300;\n  text-align: center;\n  border: 1px solid #ebebeb;\n}\n\nform {\n  padding: 20px;\n  background: #f2f2f2;\n\n}\n\n\n/* GENERAL ELEMENT TYPE STYLES */\n\n#main-content h1 {\n  margin-top: 0;\n  margin-bottom: 0;\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: 2.8em;\n  font-weight: normal;\n  color: #474747;\n  text-indent: 6px;\n  letter-spacing: -1px;\n}\n\n/* #main-content h1:before { */\n/*   padding-right: 0.3em; */\n/*   margin-left: -0.9em; */\n/*   color: #9ddcff; */\n/*   content: \"/\"; */\n/* } */\n\n#main-content h2 {\n  margin-bottom: 8px;\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: 22px;\n  font-weight: bold;\n  color: #474747;\n  text-indent: 4px;\n}\n/* #main-content h2:before { */\n/*   padding-right: 0.3em; */\n/*   margin-left: -1.5em; */\n/*   content: \"//\"; */\n/*   color: #9ddcff; */\n/* } */\n\n#main-content h3 {\n  margin-top: 24px;\n  margin-bottom: 8px;\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: 18px;\n  font-weight: bold;\n  color: #474747;\n  text-indent: 3px;\n}\n\n/* #main-content h3:before { */\n/*   padding-right: 0.3em; */\n/*   margin-left: -2em; */\n/*   content: \"///\"; */\n/*   color: #9ddcff; */\n/* } */\n\n#main-content h4 {\n  margin-bottom: 8px;\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: 15px;\n  font-weight: bold;\n  color: #474747;\n  text-indent: 3px;\n}\n\n/* h4:before { */\n/*   padding-right: 0.3em; */\n/*   margin-left: -2.8em; */\n/*   content: \"////\"; */\n/*   color: #9ddcff; */\n/* } */\n\n#main-content h5 {\n  margin-bottom: 8px;\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: 14px;\n  color: #474747;\n  text-indent: 3px;\n}\n/* h5:before { */\n/*   padding-right: 0.3em; */\n/*   margin-left: -3.2em; */\n/*   content: \"/////\"; */\n/*   color: #9ddcff; */\n/* } */\n\n#main-content h6 {\n  margin-bottom: 8px;\n  font-family: 'Helvetica Neue', Helvetica, Arial, serif;\n  font-size: .8em;\n  color: #474747;\n  text-indent: 3px;\n}\n/* h6:before { */\n/*   padding-right: 0.3em; */\n/*   margin-left: -3.7em; */\n/*   content: \"//////\"; */\n/*   color: #9ddcff; */\n/* } */\n\np {\n  margin-bottom: 20px;\n}\n\na {\n  text-decoration: none;\n}\n\np a {\n  font-weight: 400;\n}\n\nblockquote {\n  padding: 0 0 0 30px;\n  margin-bottom: 20px;\n  border-left: 10px solid #e9e9e9;\n}\n\nul {\n  list-style-position: inside;\n  list-style: disc;\n  padding-left: 20px;\n}\n\nol {\n  list-style-position: inside;\n  list-style: decimal;\n  padding-left: 3px;\n}\n\ndl dd {\n  font-style: italic;\n  font-weight: 100;\n}\n\n/* MISC */\n.clearfix:after {\n  display: block;\n  height: 0;\n  clear: both;\n  visibility: hidden;\n  content: '.';\n}\n\n.clearfix {display: inline-block;}\n* html .clearfix {height: 1%;}\n.clearfix {display: block;}\n\n/* #Media Queries\n================================================== */\n\n/* Smaller than standard 960 (devices and browsers) */\n@media only screen and (max-width: 959px) { }\n\n/* Tablet Portrait size to standard 960 (devices and browsers) */\n@media only screen and (min-width: 768px) and (max-width: 959px) {\n  .inner {\n    width: 740px;\n  }\n  header h1, header h2 {\n    width: 340px;\n  }\n  header h1 {\n    font-size: 60px;\n  }\n  header h2 {\n    font-size: 30px;\n  }\n  #main-content {\n    width: 490px;\n  }\n  /* #main-content h1:before, */\n  /* #main-content h2:before, */\n  /* #main-content h3:before, */\n  /* #main-content h4:before, */\n  /* #main-content h5:before, */\n  /* #main-content h6:before { */\n  /*   padding-right: 0; */\n  /*   margin-left: 0; */\n  /*   content: none; */\n  /* } */\n}\n\n/* All Mobile Sizes (devices and browser) */\n@media only screen and (max-width: 767px) {\n  .inner {\n    width: 93%;\n  }\n  header {\n    padding: 20px 0;\n  }\n  header .inner {\n    position: relative;\n  }\n  header h1, header h2 {\n    width: 100%;\n  }\n  header h1 {\n    font-size: 48px;\n  }\n  header h2 {\n    font-size: 24px;\n  }\n  header a.button {\n    position: relative;\n    display: inline-block;\n    width: auto;\n    height: auto;\n    padding: 5px 10px;\n    margin-top: 15px;\n    font-size: 13px;\n    line-height: 1;\n    color: #2879d0;\n    text-align: center;\n    background-color: #9ddcff;\n    background-image: none;\n    border-radius: 5px;\n    -moz-border-radius: 5px;\n    -webkit-border-radius: 5px;\n  }\n  header a.button small {\n    display: inline;\n    font-size: 13px;\n  }\n  #main-content,\n  aside#sidebar {\n    float: none;\n    width: 100% ! important;\n  }\n  aside#sidebar {\n    min-height: 0;\n    padding: 20px 0;\n    margin-top: 20px;\n    background-image: none;\n    border-top: solid 1px #ddd;\n  }\n  aside#sidebar a.button {\n    display: none;\n  }\n  /* #main-content h1:before, */\n  /* #main-content h2:before, */\n  /* #main-content h3:before, */\n  /* #main-content h4:before, */\n  /* #main-content h5:before, */\n  /* #main-content h6:before { */\n  /*   padding-right: 0; */\n  /*   margin-left: 0; */\n  /*   content: none; */\n  /* } */\n}\n\n/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */\n@media only screen and (min-width: 480px) and (max-width: 767px) { }\n\n/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */\n@media only screen and (max-width: 479px) { }\n"
  }
]