专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

golang基础- 初体验

golang 简介

golang是一门强类型,高并发,易上手的编程语言。

为什么选择 golang

golang被称为云时代的c++,其极高的开发效率,天然的高并发能力,入门容易但天花板又很高。近几年来,golang在中国的火热程度极具上升,笔者所呆过的腾讯,新加坡上市外企均有大量部门转型为golang开发。

环境安装

1、 下载goland
2、 配置GOPATH等环境变量
3、 代码路径严格按照golang推荐。

代码执行

示例代码

package main

func main() int {
    print "hello, world\n"
    return 0
}

控制台直接运行 go run hello.go

什么是package

golang 有package的概念,即目前这个程序属于哪个包。

A package is nothing but a directory with some code files, which exposes different variables (features) from a single point of reference

直观上说包就是包含了一些代码文件的目录。

为什么要有package:

Imagine you have more than a thousand functions which you need constantly while working on any project. Some of these functions have common behavior. For example, toUpperCase and toLowerCase function transforms case of a string, so you write them in a single file (probably case.go). There are other functions which do some other operations on string data type, so you write them in a separate file as well. Since you have many files which do something with string data type, so you created a directory named string and put all string related files into it. Finally, you put all of these directories in one parent directory which will be your package. The whole package structure looks like below. package main

代码结构示例

108_1.png

package-name
├── string
|  ├── case.go
|  ├── trim.go
|  └── misc.go
└── number
   ├── arithmetics.go
   └── primes.go

编译程序 go build hello.go

编译出来的二进制,可以脱离代码运行。不过不能跨平台。即windows编译出来的,无法在linux运行。

文章永久链接:https://tech.souyunku.com/38362

未经允许不得转载:搜云库技术团队 » golang基础- 初体验

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们