Skip to content

Commit

Permalink
first page
Browse files Browse the repository at this point in the history
  • Loading branch information
stamblerre committed Jul 14, 2021
1 parent f04855a commit 6183c89
Showing 1 changed file with 34 additions and 41 deletions.
75 changes: 34 additions & 41 deletions ide.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,45 @@ date_published:

# Getting Started with Your IDE

This is a great tutorial!
This tutorial will teach you the basics of writing Go code in your IDE.
We will cover structuring your project, writing a function, and testing
and debugging your code.

## Initialize a `go.mod` file
## Creating your project

Should we do this part in the tutorial?
### Initializing a module

## Open a `go.mod` file
Let's start by creating a module, which is the unit that defines a Go project.
We can do this through a command, which we can run from the Command Palette. Access the Command Palette by going to the View Menu and selecting "Find Command", or by using the `Ctrl+Shift+P` keyboard shortcut.

Let's start by <walkthrough-editor-open-file filePath="cloudshell_open/go-tutorials/example.com/go.mod">opening the go.mod</walkthrough-editor-open-file> file for the project.
<!--Note: This doesn't work yet, because Cloud Shell IDE uses an older version of VS Code Go.-->
Select the `Go: Initialize go.mod` command by typing in the search bar. Enter the module name `example.com` when prompted. Notice that this creates 2 new files in the repository:
<walkthrough-editor-spotlight spotlightId="navigator" spotlightItem="cloudshell_open/go-tutorials/example.com/go.mod">`example.com/go.mod`</walkthrough-editor-spotlight>
and <walkthrough-editor-spotlight spotlightId="navigator" spotlightItem="cloudshell_open/go-tutorials/example.com/go.sum">`example.com/go.sum`</walkthrough-editor-spotlight>.
You can largely disregard the `go.sum` file, but you will refer to the `go.mod` file as you edit your Go project. Let's take a look at it.

This file defines our project. We are working in the
### Understanding the `go.mod` file

<!--TODO(rstambler): Switch to using regexes here.-->
<walkthrough-editor-select-line filePath="cloudshell_open/go-tutorials/example.com/go.mod"
startLine="0" startCharacterOffset="7"
endLine="0" endCharacterOffset="19">
`example.com` module
</walkthrough-editor-select-line>, and we are developing with
Let's open the <walkthrough-editor-open-file filePath="cloudshell_open/go-tutorials/example.com/go.mod">`go.mod`</walkthrough-editor-open-file> file for the project.

<!--TODO(rstambler): Switch to using regexes here.-->
<walkthrough-editor-select-line filePath="cloudshell_open/go-tutorials/example.com/go.mod"
startLine="2" startCharacterOffset="0"
endLine="2" endCharacterOffset="8">
This is the file defines our project and its dependencies. We are working in the <walkthrough-editor-select-regex filePath="cloudshell_open/go-tutorials/example.com/go.mod" regex='example.com'>`example.com` module</walkthrough-editor-select-regex>, and it is compatible with
<walkthrough-editor-select-regex filePath="cloudshell_open/go-tutorials/example.com/go.mod" regex='go \d.\d+'>
Go version 1.16
</walkthrough-editor-select-line>.

## Run `go mod tidy`

Click the `Run go mod tidy` code lens at the top of the file. (How can we highlight a code lens?)

<!--TODO(rstambler): Switch to using regexes here.-->
Note that the
<walkthrough-editor-select-line filePath="cloudshell_open/go-tutorials/example.com/go.mod"
startLine="4" startCharacterOffset="8"
endLine="4" endCharacterOffset="20">
`rsc.io/quote` module
</walkthrough-editor-select-line> has been added to the `go.mod` file.
This is because a
<walkthrough-editor-open-file filePath="cloudshell_open/go-tutorials/example.com/stringutil/quote.go">
file in the `stringutil`
</walkthrough-editor-open-file>
package depends on this module already.
</walkthrough-editor-select-regex>. Note that the Go version declared in the `go.mod` file is not necessarily the Go version you must use--it is the lowest supported version of Go for that module. You can check your current Go version by looking at the Go status bar item in the lower left-hand corner of the editor. <!--Would be nice to highlight the status bar item.-->

### Tidying your module

The `go.mod` file declares the third-party dependencies for the module, and we keep it up to date by tidying our module. The sample project already uses a third-party dependency in the Go code, so let's tidy the module now.

Any third-party dependencies in your code must be declared in your `go.mod` file.
Click the `Run go mod tidy` code lens at the top of the file. <!--Would be nice to highlight the code lens.-->

Notice that there are now additional code lenses shown in the `go.mod` file.
You can use these code lenses to upgrade your dependencies from the editor, without using the command-line.
Once the module is tidied, you will see that the
<walkthrough-editor-select-regex filePath="cloudshell_open/go-tutorials/example.com/go.mod" regex='rsc.io/quote'>`rsc.io/quote` module</walkthrough-editor-select-regex> has been added as a requirement to the `go.mod` file.
This is because a <walkthrough-editor-open-file filePath="cloudshell_open/go-tutorials/example.com/stringutil/quote.go">file in the `stringutil`
</walkthrough-editor-open-file>
package depends on this module already. The <walkthrough-editor-open-file filePath="cloudshell_open/go-tutorials/example.com/go.sum">`go.sum` file</walkthrough-editor-open-file> will also have a corresponding update.

Finally, notice that the additional code lenses now visible in the `go.mod` file. You can use these code lenses to upgrade your dependencies from the editor, without using the command-line.

## Let's start writing some Go code

Expand Down Expand Up @@ -100,15 +92,16 @@ Notice that you are offered autocompletion as you type.
### Read file contents

The first step will be to read in the contents of the file.
Begin typing the following into the body of the function:


Type the following in the function body:
Type the following in the function body:

```go
func ReverseFile(filename string) (string, error) {
contents, err := os.ReadFile
}
contents, err := os.
```

Notice the autocompletion result
and accept the autocompletion results. The "os" package will be automatically imported into your file.

<walkthrough-editor-spotlight spotlightId="menu-terminal-new-terminal">New Terminal</walkthrough-editor-spotlight>
Expand Down

0 comments on commit 6183c89

Please sign in to comment.