前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Golang: Starting my journey

Golang: Starting my journey

作者头像
Miigon
发布2022-10-27 15:53:35
2970
发布2022-10-27 15:53:35
举报
文章被收录于专栏:Miigon's BlogMiigon's Blog

Golang

Disclaimer: This series is meant to compare the features and quirks of Golang with other languages like C, because that’s basically how I learned the language. However, this means that the series might not be complete and detailed enough to be a tutorial for beginners.

Golang Wikipedia Golang Official Documentation How to Write Go Code For advanced devs: The Go Programming Language Specification For beginners: Golang Official Tour (Highly recommended) For best practices: Effective Go (Highly recommended)

Go is a statically typed, compiled programming language with memory safety, garbage collection, structual typing, and CSP-style concurrency.

It’s simple, robust and efficient. We see more and more adaptation in recent years, in big companies like Tencent, Bilibili, Alibaba and ByteDance.

About the series

In this article series, I will document my learning process of the Go language. At the time of writing this article, I have very little Go language experience. However, I do have a good amount of C++, C# and Python experiences.

I do think that the best place to get information regarding a new language, library or framework is the official documentation and/or wiki, so in this series, most of the information will come from official sources, instead of from someone else’s blog posts or other third party sources.

Noted that this series is merely my own learning process, instead of a full tutorial for the language. I might write a full tutorial in English and/or Chinese after this one.

In this particular article, We’ll go through the process of installing Golang, as well as compiling our first program.

Downloading and Installing

Here’s the official download link of Golang: https://golang.org/dl/

If you are running Windows, you can download the installer at the link above. But if you are using Linux or macOS, it’s highly recommended to install via a package manager:

For macOS with Homebrew:

代码语言:javascript
复制
> brew install go

For Ubuntu or Debian:

代码语言:javascript
复制
> sudo apt-get install golang

After installing, you should be able to check the installed version:

代码语言:javascript
复制
> go version
go version go1.15.6 darwin/amd64

At the time of writting this article, the newest version is go 1.15.6 That’s also the version this series will be based upon.

How to compile and run programs

Here’s a demo program from https://golang.org:

代码语言:javascript
复制
package main

import "fmt"

func main() {
	fmt.Println("Hello, 世界")
}

Save the above code to file helloworld.go, then run the code by one of two ways:

1. go build

代码语言:javascript
复制
> go build helloworld.go        # default output: `./helloworld`
> ./helloworld
Hello, 世界

The default output filename is the same as the source file, just without the .go extension.

You can also specify the output file name by using -o:

代码语言:javascript
复制
> go build -o hello helloworld.go
> ./hello
Hello, 世界

2. go run

go run can be see as a shortcut of go build and then ./helloworld. Note: It still compiles the program just like normal.

代码语言:javascript
复制
> go run helloworld.go
Hello, 世界

Don’t mistake it as interpreting the code, it is NOT! It is just a shortcut command to compile and run the code in one step.

Conclusion

In ths article we discussed how to install Go and compile our first program. Next article we will start discussing the syntax and grammar of Go.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Golang
  • About the series
  • Downloading and Installing
  • How to compile and run programs
    • 1. go build
      • 2. go run
      • Conclusion
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档