• 【Golang】不要在生产环境使用 http.DefaultServerMux

    # 【Golang】不要在生产环境使用 http.DefaultServerMux 我看到许多文章和帖子都显示了一种方便简单的方法来这样创建 go 的 Web 服务: ```golang package main import ( "fmt" "log" "net/http" ) func main() { http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Requ...

  • Go 语言中的集成测试:第二部分 - 设计和编写测试

    ## 序幕 这篇文章是集成测试系列两个部分中的第二部分。你可以先读 [第一部分:使用 Docker 在有限的环境中执行测试](https://studygolang.com/articles/21759)。本文中的示例可以从 [代码仓库](https://github.com/george-e-shaw-iv/integration-tests-example) 获取。 ## 简介 > “比起测试行为,设计测试行为是已知的最好的错误预防程序之一。” —— Boris Beizer 在执行...

  • 只用 3 步构建 Go docker 最小镜像

    ![DockerGopher](https://raw.githubusercontent.com/studygolang/gctt-images/master/build-mini-docker-image/DockerGopher.png) ## Go——仅需三个步骤即可构建最小的 Docker 映像 当您为 docker 构建 Go 应用程序时,通常从诸如 `golang:1.13` 之类的映像开始。但将这个映像实际运行时会浪费资源。让我们看一下如何将 Go 应用程序构建为绝对...

  • Go 编译器概述

    ![](https://raw.githubusercontent.com/studygolang/gctt-images2/master/go-overview-of-compile/go-compiler.png "'Golang 之旅'插图,由 Go Gopher 的 Renee French 创作") > *本文基于 Go 1.13* Go 编译器是 Go 生态系统中的一个重要工具,因为它是将程序构建为可执行二进制文件的基本步骤之一。编译器的历程是漫长的,它先用 C 语言编写...

  • 120
    理解 Go 的空接口

    <!-- https://raw.githubusercontent.com/studygolang/gctt-images2/master/go-vet-command-is-more-powerful-than-you-think/go-vet.png 图片链接模板 --> !["Golang 之旅"插图,由 Go Gopher 的 Renee French 创作](https://raw.githubusercontent.com/studygolang/gctt-images2/mas...

  • 为什么要使用 go module proxy

    在看过 `Go module` 的简介之后,我以为我已经知道了这个功能我需要知道的一切。但是很快,我意识到并不是这样。最近,人们开始提倡使用 `Go module proxy`。在研究了利弊之后,我得出结论,这将是近年来 Go 语言`最重要`的变化之一。 但为什么会这样呢?是什么让 `Go module` 代理如此特别? 使用 `Go modules` 时,如果向干净的缓存的计算机上添加新依赖项或构建 `Go module`,它将基于 `go.mod` 将下载(go get)所有依赖项,...

  • 无缓冲和有缓冲通道

    !["Go 之旅 插图,由 Go Gopher 的 Renee French 创作](https://raw.githubusercontent.com/studygolang/gctt-images2/master/buffered-and-unbufferd-channel/next-recvier.png) Go 中的通道(channel)机制十分强大,但是理解内在的概念甚至可以使它更强大。实际上,选择缓冲通道或无缓冲通道将改变应用程序的行为和性能。 ## 无缓冲通道 无...

  • 120
    Go Vet 命令:超出预期的强大

    !["Golang 之旅"插图,由 Go Gopher 的 Renee French 创作](https://raw.githubusercontent.com/studygolang/gctt-images2/master/go-vet-command-is-more-powerful-than-you-think/go-vet.png) Go `vet` 命令在编写代码时非常有用。它可以帮助您检测应用程序中任何可疑、异常或无用的代码。该命令实际上由几个子分析器组成,甚至可以与您的自定义...

  • 120
    Go:关于 Cobra 的想法

    !["Golang之旅"插图,来自 Go Gopher 的 Renee French 创作](https://raw.githubusercontent.com/studygolang/gctt-images2/master/go-thoughts-about-cobra/A%20Journey%20With%20Go.png) Cobra 是 Golang 生态系统中最着名的项目之一。它简单,高效,并得到 Go 社区的大力支持。让我们来深入探索一下。 ## 设计 Cobra ...

  • 120
    现代垃圾收集策略 —— Go 的 GC 策略

    ![ ](https://raw.githubusercontent.com/studygolang/gctt-images2/master/modern-garbage-collection/gc.jpeg) 在 [Hacker News](https://news.ycombinator.com/item?id=13218550) 和 [Reddit](https://www.reddit.com/r/golang/comments/5j7phw/modern_garbage_coll...

  • Go语言中的微服务

    # Go语言中的微服务 ## 摘要 我最近在墨尔本 Golang 聚会上就如何开发微服务和框架做了一次演讲。在本文中,我将与您分享我的想法(此外,它对我来说是一个很好的复习)。 在这里,我要介绍以下框架: * [Go Micro](https://micro.mu/) * [Go Kit](https://gokit.io/) * [Gizmo](https://github.com/NYTimes/gizmo) * [Kite](https://github.co...

  • 为什么 Go 适合微服务

    ![Go Crew at SafetyCulture](https://raw.githubusercontent.com/studygolang/gctt-images/master/go-is-good-microservice/1_K95qdWukzkEadEpxqiNdEQ.jpeg) 去年早些时候,我们决定改用 Go(Golang) 作为我们([SafetyCulture](https://safetyculture.com/))开发微服务的选择。在这之前,我们的微服务使用 No...