跳到主要内容

Quick Go:特种兵式入门Go 语言

· 阅读需 2 分钟
Benjamin

Go 是什么

Go(又称Golang)是Google开发的一种静态强类型、编译型、并发型,并具有垃圾回收功能的编程语言。

The Go programming language is an open source project to make programmers more productive.

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. 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.

想尝试一下 go,但是缺乏一个动力或者说具体的目的。 忽然想起来,某个网站项目后端原先是flask简单搭了个架子就直接付诸生产环境了,这回就用 go 重构一下。

配置 Go 开发环境

VSCode + Go Extension 不多说,网上一搜一大把。

VsCode Go插件配置最佳实践指南

初次见面

初次见面(以前是用 go 是写过什么其它东西的,但是应该最后咕了,没有啥印象),从一个http服务器开始,这时候,go是相当优雅。

package main

import (
"fmt"
"net/http"
)

func HelloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
}

func main() {
http.HandleFunc("/", HelloHandler)
http.ListenAndServe(":8000", nil)
}

自签名 ssl 证书

...

花了大半天时间写并调试完了 api,整体体验下来 Go 是相当优雅,是一款相当适合强迫症选手的语言。我很愿意在之后的工作中尝试 Go。

部分参考

Loading Comments...