Гоу программирование язык программирования

Tutorial: Get started with Go

In this tutorial, you’ll get a brief introduction to Go programming. Along the way, you will:

  • Install Go (if you haven’t already).
  • Write some simple «Hello, world» code.
  • Use the go command to run your code.
  • Use the Go package discovery tool to find packages you can use in your own code.
  • Call functions of an external module.

Prerequisites

  • Some programming experience. The code here is pretty simple, but it helps to know something about functions.
  • A tool to edit your code. Any text editor you have will work fine. Most text editors have good support for Go. The most popular are VSCode (free), GoLand (paid), and Vim (free).
  • A command terminal. Go works well using any terminal on Linux and Mac, and on PowerShell or cmd in Windows.

Install Go

Write some code

Get started with Hello, World.

    Open a command prompt and cd to your home directory. On Linux or Mac:

  • Declare a main package (a package is a way to group functions, and it’s made up of all the files in the same directory).
  • Import the popular fmt package, which contains functions for formatting text, including printing to the console. This package is one of the standard library packages you got when you installed Go.
  • Implement a main function to print a message to the console. A main function executes by default when you run the main package.
  1. Make your printed message a little more interesting with a function from an external module.
    1. Visit pkg.go.dev and search for a «quote» package.
    2. Locate and click the rsc.io/quote package in search results (if you see rsc.io/quote/v3, ignore it for now).
    3. In the Documentation section, under Index, note the list of functions you can call from your code. You’ll use the Go function.
    4. At the top of this page, note that package quote is included in the rsc.io/quote module.

    Write more code

    With this quick introduction, you got Go installed and learned some of the basics. To write some more code with another tutorial, take a look at Create a Go module.

    Источник

    Build simple, secure, scalable systems with Go

    “At the time, no single team member knew Go, but within a month, everyone was writing in Go and we were building out the endpoints. It was the flexibility, how easy it was to use, and the really cool concept behind Go (how Go handles native concurrency, garbage collection, and of course safety+speed.) that helped engage us during the build. Also, who can beat that cute mascot!”

    «A small language that compiles fast makes for a happy developer. The Go language is small, compiles really fast, and as a result it lets your mind focus on the actual problem and less on the tool you are using to solve it. Code, test, debug cycles are so quick that you forget you are not working with an interpreted language. Looking at our code, you see less boilerplate and more business logic.«

    Go has excellent characteristics for scalability and services written using it typically have very small memory footprints. Because code is compiled into a single static binary, services can also be containerised with ease, making it much simpler to build and deploy. These attributes make Go an ideal choice for companies building microservices, as you can easily deploy into a highly available and scalable environment such as Kubernetes.”

    «In our tightly managed environments where we run Go code, we have seen a CPU reduction of approximately 10% with cleaner and maintainable code.»

    «Tooling has always been a problem with our legacy code base. but we have found that Go has excellent tooling, plus built-in testing, benchmarking, and profiling frameworks. It is easy to write efficient and resilient applications. After working on Go, most of our developers don’t want to go back to other languages.«

    «. when a programming language is designed for exactly the environment most of us use right now—scalable, cloud-based servers that are optimized for performance—a lot can go right.»

    Источник

    Читайте также:  Android bluetooth разработка приложений
Оцените статью