Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

  <input type="checkbox" name="checkbox" checked="checked" id="toggle">
  <label for="toggle" class="icon"></label>
<nav id="navbar">
    <header id="Go_Documentation">Go Documentation</header>
    <ul>
        <li><a class="nav-link" href="#Introduction">Introduction</a></li>
        <li><a class="nav-link" href="#Code_Organization">Code Organization</a></li>
        <li><a class="nav-link" href="#First_Program">First Program</a></li>
        <li><a class="nav-link" href="#Importing_packages_from_your_module">Importing packages from your module</a></li>
        <li><a class="nav-link" href="#Importing_packages_from_remote_modules">Importing packages from remote modules</a></li>
        <li><a class="nav-link" href="#Testing">Testing</a></li>
        <li><a class="nav-link" href="#Editor_plugins_and_IDEs">Editor plugins and IDEs</a></li>
        <li><a class="nav-link" href="#Reference">Reference</a></li>
    </ul>
</nav>
<main id="main-doc">
        <section class="main-section" id="Introduction">
            <header>Introduction</header>
            <p>Go is an open source programming language that makes it easy to build simple, reliable, and efficient software and make programmers more productive.</p>
            <p>Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction.</p>
            <p>Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.</p>
            <p>This document demonstrates the development of a simple Go package inside a module and introduces the go tool, the standard way to fetch, build, and install Go modules, packages, and commands.</p>
            <p>Note: This document assumes that you are using Go 1.13 or later and the <code>GO111MODULE</code> environment variable is not set. If you are looking for the older, pre-modules version of this document.</p>
        </section>
        <section class="main-section" id="Code_Organization">
            <header>Code Organization</header>
            <p>Go programs are organized into packages. A package is a collection of source files in the same directory that are compiled together. Functions, types, variables, and constants defined in one source file are visible to all other source files within the same package.</p>
            <p>    
                A repository contains one or more modules. A module is a collection of related Go packages that are released together.
                A Go repository typically contains only one module, located at the root of the repository.
                <br> 
                A file named <code>go.mod</code> there declares the module path: the import path prefix for all packages within the module.
                <br> 
                The module contains the packages in the directory containing its <code>go.mod</code> file as well as subdirectories of that directory, up to the next subdirectory containing another <code>go.mod</code> file (if any). 
            </p>
            <p>Note that you don't need to publish your code to a remote repository before you can build it. A module can be defined locally without belonging to a repository. However, it's a good habit to organize your code as if you will publish it someday.</p>
            <p>
                Each module's path not only serves as an import path prefix for its packages, but also indicates where the <code>go</code> command should look to download it. For example, in order to download the module <code>golang.org/x/tools</code>, the <code>go</code> command would consult the repository indicated by <code>https://golang.org/x/tools</code>. 
            </p>
            <p>
                An import path is a string used to import a package. A package's import path is its module path joined with its subdirectory within the module. For example, the module <code>github.com/google/go-cmp</code> contains a package in the directory <code>cmp/</code>. That package's import path is <code>github.com/google/go-cmp/cmp</code>. Packages in the standard library do not have a module path prefix.
            </p>
        </section>
        <section class="main-section" id="First_Program">
            <header>First Program</header>
            <p>To compile and run a simple program, first choose a module path (we'll use <code>example.com/user/hello</code>) and create a <code>go.mod</code> file that declares it: </p>
            <div class="box"><code>$ mkdir hello # Alternatively, clone it if it already exists in version control.
                    $ cd hello
                    $ go mod init example.com/user/hello
                    go: creating new go.mod: module example.com/user/hello
                    $ cat go.mod
                    module example.com/user/hello
                    go 1.14
                    $</code></div>
            <p>The first statement in a Go source file must be <code>package name</code>. Executable commands must always use <code>package main</code>.</p>
            <p>Next, create a file named <code>hello.go</code> inside that directory containing the following Go code: </p>
            <div class="box"><code>package main
                    import "fmt"
                    func main() {
                    fmt.Println("Hello, world.")
                    }</code></div>
            <p>Now you can build and install that program with the <code>go</code> tool:</p>
            <div class="box"><code>$ go install example.com/user/hello
                    $</code></div>
            <p>
                This command builds the <code>hello</code> command, producing an executable binary. It then installs that binary as <code>$HOME/go/bin/hello</code> (or, under Windows, <code>%USERPROFILE%\go\bin\hello.exe</code>).
            </p>
            <p>
                The install directory is controlled by the <code>GOPATH</code> and <code>GOBIN</code> environment variables. If <code>GOBIN</code> is set, binaries are installed to that directory. If <code>GOPATH</code> is set, binaries are installed to the <code>bin</code> subdirectory of the first directory in the <code>GOPATH</code> list. Otherwise, binaries are installed to the bin subdirectory of the default <code>GOPATH</code> (<code>$HOME/go</code> or <code>%USERPROFILE%\go</code>). 
            </p>
            <p>You can use the <code>go env</code> command to portably set the default value for an environment variable for future <code>go</code> commands: </p>
            <div class="box"><code>$ go env -w GOBIN=/somewhere/else/bin
                    $</code></div>
            <p>To unset a variable previously set by <code>go env -w</code>, use <code>go env -u</code>:</p>
            <div class="box"><code>$ go env -u GOBIN
                    $</code></div>
            <p>Commands like <code>go install</code> apply within the context of the module containing the current working directory. If the working directory is not within the <code>example.com/user/hello</code> module, <code>go install</code> may fail.</p>
            <div class="box"><code>$ go install example.com/user/hello</code></div>
            <div class="box"><code>$ go install .</code></div>
            <div class="box"><code>$ go install</code></div>
            <p>Next, let's run the program to ensure it works. For added convenience, we'll add the install directory to our <code>PATH</code> to make running binaries easy: </p>
            <div class="box"><code># Windows users should consult https://github.com/golang/go/wiki/SettingGOPATH
                    # for setting %PATH%.
                    $ export PATH=$PATH:$(dirname $(go list -f '{{.Target}}' .))
                    $ hello
                    Hello, world.
                    $</code></div>
            <p>If you're using a source control system, now would be a good time to initialize a repository, add the files, and commit your first change. Again, this step is optional: you do not need to use source control to write Go code. </p>
            <div class="box"><code>$ git init
                    Initialized empty Git repository in /home/user/hello/.git/
                    $ git add go.mod hello.go
                    $ git commit -m "initial commit"
                    [master (root-commit) 0b4507d] initial commit
                    1 file changed, 7 insertion(+)
                    create mode 100644 go.mod hello.go
                    $</code></div>
            <p>
                The <code>go</code> command locates the repository containing a given module path by requesting a corresponding HTTPS URL and reading metadata embedded in the HTML response. Many hosting services already provide that metadata for repositories containing Go code, so the easiest way to make your module available for others to use is usually to make its module path match the URL for the repository. 
            </p>
        </section>
        <section class="main-section" id="Importing_packages_from_your_module">
            <header>Importing packages from your module</header>
            <p>
                Let's write a <code>morestrings</code> package and use it from the <code>hello</code> program. First, create a directory for the package named <code>$HOME/hello/morestrings</code>, and then a file named <code>reverse.go</code> in that directory with the following contents: 
            </p>
            <div class="box"><code>// Package morestrings implements additional functions to manipulate UTF-8
                    // encoded strings, beyond what is provided in the standard "strings" package.
                    package morestrings

                    // ReverseRunes returns its argument string reversed rune-wise left to right.
                    func ReverseRunes(s string) string {
                        r := []rune(s)
                        for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
                            r[i], r[j] = r[j], r[i]
                        }
                        return string(r)
                    }</code></div>
            <p>
                Because our <code>ReverseRunes</code> function begins with an upper-case letter, it is exported, and can be used in other packages that import our <code>morestrings</code> package.</p>
            <p> Let's test that the package compiles with <code>go build</code>:
            </p>
            <div class="box"><code>$ cd $HOME/hello/morestrings
                    $ go build
                    $</code></div>
            <p>This won't produce an output file. Instead it saves the compiled package in the local build cache.</p>
            <p> 
                After confirming that the <code>morestrings</code> package builds, let's use it from the <code>hello</code> program. To do so, modify your original <code>$HOME/hello/hello.go</code> to use the <code>morestrings</code> package:
            </p>
            <div class="box"><code>package main

                    import (
                        "fmt"

                        "example.com/user/hello/morestrings"
                    )

                    func main() {
                        fmt.Println(morestrings.ReverseRunes("!oG ,olleH"))
                    }</code></div>
            <p> Install the <code>hello</code> program:</p>
            <div class="box"><code>$ go install example.com/user/hello</code></div>
            <p> Running the new version of the program, you should see a new, reversed message:</p>
            <div class="box"><code>$ hello
                    Hello, Go!</code></div>
        </section>
        <section class="main-section" id="Importing_packages_from_remote_modules">
            <header>Importing packages from remote modules</header>
            <p>
                An import path can describe how to obtain the package source code using a revision control system such as Git or Mercurial. The <code>go</code> tool uses this property to automatically fetch packages from remote repositories. For instance, to use <code>github.com/google/go-cmp/cmp</code> in your program:
            </p>
            <div class="box"><code>package main

                    import (
                        "fmt"

                        "example.com/user/hello/morestrings"
                        "github.com/google/go-cmp/cmp"
                    )

                    func main() {
                        fmt.Println(morestrings.ReverseRunes("!oG ,olleH"))
                        fmt.Println(cmp.Diff("Hello World", "Hello Go"))
                    }</code></div>
            <p>When you run commands like <code>go install</code>, <code>go build</code>, or <code>go run</code>, the <code>go</code> command will automatically download the remote module and record its version in your <code>go.mod</code> file: </p>
            <div class="box"><code>$ go install example.com/user/hello
                    go: finding module for package github.com/google/go-cmp/cmp
                    go: downloading github.com/google/go-cmp v0.4.0
                    go: found github.com/google/go-cmp/cmp in github.com/google/go-cmp v0.4.0
                    $ hello
                    Hello, Go!
                    string(
                    - 	"Hello World",
                    + 	"Hello Go",
                    )
                    $ cat go.mod
                    module example.com/user/hello

                    go 1.14

                    require github.com/google/go-cmp v0.4.0
                    $</code></div>
            <p>Module dependencies are automatically downloaded to the <code>pkg/mod</code> subdirectory of the directory indicated by the <code>GOPATH</code> environment variable. The downloaded contents for a given version of a module are shared among all other modules that <code>require</code> that version, so the <code>go</code> command marks those files and directories as read-only. To remove all downloaded modules, you can pass the <code>-modcache</code> flag to <code>go clean</code>:</p>
            <div class="box"><code>$ go clean -modcache
                    $</code></div>
        </section>
        <section class="main-section" id="Testing">
            <header>Testing</header>
            <p>Go has a lightweight test framework composed of the go test command and the testing package.</p>
            <p>
                You write a test by creating a file with a name ending in <code>_test.go</code> that contains functions named <code>TestXXX</code> with signature <code>func (t *testing.T)</code>. The test framework runs each such function; if the function calls a failure function such as <code>t.Error</code> or <code>t.Fail</code>, the test is considered to have failed.
            </p>
            <p>
                Add a test to the <code>morestrings</code> package by creating the file <code>$HOME/hello/morestrings/reverse_test.go</code> containing the following Go code.
            </p>
            <div class="box"><code> package morestrings

                    import "testing"

                    func TestReverseRunes(t *testing.T) {
                        cases := []struct {
                            in, want string
                        }{
                            {"Hello, world", "dlrow ,olleH"},
                            {"Hello, 世界", "界世 ,olleH"},
                            {"", ""},
                        }
                        for _, c := range cases {
                            got := ReverseRunes(c.in)
                            if got != c.want {
                                t.Errorf("ReverseRunes(%q) == %q, want %q", c.in, got, c.want)
                            }
                        }
                    }</code></div>
            <p>Then run the test with <code>go</code> test: </p>
            <div class="box"><code>$ go test
                    PASS
                    ok  	example.com/user/morestrings 0.165s
                    $</code></div>
            <p>Run <code>go help test</code> and see the testing package documentation for more detail.</p>
        </section>
        <section class="main-section" id="Editor_plugins_and_IDEs">
            <header>Editor plugins and IDEs</header>
            <p>This document lists commonly used editor plugins and IDEs from the Go ecosystem that make Go development more productive and seamless. A comprehensive list of editor support and IDEs for Go development is available at the wiki.</p>
            <p>The Go ecosystem provides a variety of editor plugins and IDEs to enhance your day-to-day editing, navigation, testing, and debugging experience.</p>
            <ul>
                <li>vim: vim-go plugin provides Go programming language support</li>
                <li>Visual Studio Code: Go extension provides support for the Go programming language</li>
                <li>GoLand: GoLand is distributed either as a standalone IDE or as a plugin for IntelliJ IDEA Ultimate</li>
                <li>Atom: Go-Plus is an Atom package that provides enhanced Go support</li>
            </ul>
            <p>Note that these are only a few top solutions; a more comprehensive community-maintained list of IDEs and text editor plugins is available at the Wiki.</p>
        </section>
        <section class="main-section" id="Reference">
            <header>Reference</header>
            <ul>
                <li>All the documentation in this page is taken from
                    <a
                    href="https://golang.org/doc/"
                    target="_blank"
                    >GO
                    </a>
                </li>
            </ul>
        </section>
</main>
              
            
!

CSS

              
                html {
  scroll-behavior: smooth;
}
body {
  font-family: arial, sans-serif;
  line-height: 1.5;
  color: #4d4e53;
  overflow-x: hidden;
}
  .icon{
    position: fixed;
    top: 1.3em;
    right: 1.5em;
    height: 3.1em;
    width: 3.1em;
    z-index: 100002;
    background: #4d4e53;
    cursor: pointer;
}
.icon:before {
  content: 'close';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  color: #fff;
  text-align: center;
  line-height: 50px;
  text-transform: uppercase;
  font-weight: 700;
  font-size: 14px;
}
input[type="checkbox"]:checked ~ .icon:before {
  content: 'menu';
}
#toggle {
  display: none;
}
header {
  color: black;
  margin: 10px;
  text-align: center;
  font-size: 2em;
  font-weight: thin;
}
#navbar header {
  line-height: 1;
  font-size: 1.6em;
  color: #FFF;
}
#navbar {
  margin-top: 30px;
  position: fixed;
  left: 0;
  top: 0;
  height: 100%;
  width: 100%;
  background: #4d4e53;
  border-right: solid;
  border-color: rgba(0, 22, 22, 0.4);
  z-index: 100000;
  transition: 0.5s;
}
#navbar ul {
  transition: 0.5s;
  height: 88%;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
input[type="checkbox"]:checked ~ #navbar {
  left: -100%;
}
#navbar ul li {
  color: #FFF;
  border-top: 1px solid;
  list-style: none;
  position: relative;
  width: 100%;
}
#navbar ul li a {
  display: block;
  padding: 10px 30px;
  color: #FFF;
  text-decoration: none;
  cursor: pointer;
  transition: 0.5s;
}
#navbar ul li a:hover {
  transform: translateX(10px);
}
  .box {
    display: block;
    text-align: left;
    white-space: pre;
    position: relative;
    line-height: 2;
    background-color: #f7f7f7;
    padding: 2%;
    margin: 1%;
    overflow: auto;
  }
  input[type="checkbox"]:checked ~ #main-doc {
    left: 0;
  }
#main-doc {
    box-sizing: border-box;
    position: relative;
    transition: 0.7s;
    left: 100%;
    text-align: justify;
}
@media only screen and (min-width: 990px) {
  #main-doc {
    padding: 15%;
    padding-top: 1.5%;
    padding-bottom: 0;
    left: 14%;
  }
  #navbar header {
    color: black;
  }
  #navbar {
    width: 16em;
    background: #FFF;
  }
  #navbar ul li {
  color: #4d4e53;
}
  #navbar ul li a {
  color: #4d4e53;
  }
}
@media only screen and (max-width: 990px) {
  #main-doc {
    width: 100%;
    max-width: 100%;
    left: 100%;
    overflow: hidden;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console