Google Cloud 宣布支持Go 1.11

The Go Blog Announcing App Engine’s New Go 1.11 Runtime

16 October 2018

App Engine launched experimental support for Go in 2011. In the subsequent years, the Go community has grown significantly and has settled on idiomatic patterns for cloud-based applications. Today, Google Cloud is announcing a new Go 1.11 runtime for the App Engine standard environment that provides all the power of App Engine—things like paying only for what you use, automatic scaling, and managed infrastructure—while supporting idiomatic Go.

Starting with Go 1.11, Go on App Engine has no limits on application structure, supported packages, context.Context values, or HTTP clients. Write your Go application however you prefer, add an app.yaml file, and your app is ready to deploy on App Engine. Specifying Dependencies describes how the new runtime supports vendoring and modules(experimental) for dependency management.

Along with Cloud Functions support for Go (more on that in a future post), App Engine provides a compelling way to run Go code on Google Cloud Platform (GCP) with no concern for the underlying infrastructure.

Let’s take a look at creating a small application for App Engine. For the example here, we assume a GOPATH-based workflow, although Go modules have experimental support as well.

First, you create the application in your GOPATH:

 1// This server can run on App Engine.
 2package main
 3
 4import (
 5    "fmt"
 6    "log"
 7    "net/http"
 8    "os"
 9)
10
11func main() {
12    port := os.Getenv("PORT")
13    if port == "" {
14        port = "8080"
15    }
16    http.HandleFunc("/", hello)
17
18    log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
19}
20
21func hello(w http.ResponseWriter, r *http.Request) {
22    w.Write([]byte("Hello, 世界"))
23}

The code contains an idiomatic setup for a small HTTP server that responds with “Hello, 世界.” If you have previous App Engine experience, you’ll notice the absence of any call to appengine.Main(), which is now entirely optional. Furthermore, the application code is completely portable—there are no ties to the infrastructure that your application is deployed on.

If you need to use external dependencies, you can add those dependencies to a vendor directory or to a go.modfile, both of which the new runtime supports.

With the application code complete, create an app.yaml file to specify the runtime:

1runtime: go111

Finally, set your machine up with a Google Cloud Platform account:

  • Create an account with https://cloud.google.com.
  • Create a project.
  • Install the Cloud SDK on your system.

With all the setup complete, you can deploy using one command:

1gcloud app deploy

We think Go developers will find the new Go 1.11 runtime for App Engine an exciting addition to the available options to run Go applications. There is a free tier. Check out the getting started guide or the migration guide and deploy an app to the new runtime today!

By Eno Compton and Tyler Bui-Palsulich

Related articles

  • Go on App Engine: tools, tests, and concurrency
  • The App Engine SDK and workspaces (GOPATH)
  • Go updates in App Engine 1.7.1
  • Go videos from Google I/O 2012
  • From zero to Go: launching on the Google homepage in 24 hours
  • The Go Programming Language turns two
  • Writing scalable App Engine applications
  • Go App Engine SDK 1.5.5 released
  • Two Go Talks: "Lexical Scanning in Go" and "Cuddle: an App Engine Demo"
  • Go for App Engine is now generally available
  • Go at Google I/O 2011: videos
  • Go and Google App Engine
  • Go at I/O: Frequently Asked Questions

版权申明:内容来源网络,版权归原创者所有。除非无法确认,我们都会标明作者及出处,如有侵权烦请告知,我们会立即删除并表示歉意。谢谢。

原文发布于微信公众号 - Golang语言社区(Golangweb)

原文发表时间:2018-10-21

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏陈满iOS

CocoaPods与Ruby安装,配置,及使用详细记录(Mac环境)

附:笔者介绍另一种导入第三方库工具Carthage的文章,可以另外点击进入查看http://www.jianshu.com/p/1de99aeedbf6

1433
来自专栏Linyb极客之路

使用Spring Boot开发的10个免费开源项目

本文推荐一些使用Spring Boot开发的免费开源项目,可用于学习目的,能够查看源代码并获得真实项目的实践经验。除了Spring Boot,您还将学习Spri...

2.6K5
来自专栏杨建荣的学习笔记

巧用shell脚本统计磁盘使用情况(r4笔记第12天)

在系统环境中存在大量的文件时,统计磁盘空间的工作变得尤为重要。 首先是传统的文件统计,通常使用-s选项,但是只能得到一个概要的信息,如果想定位哪些文件消耗的空间...

3117
来自专栏bboysoul

社会工程学信息收集工具(Userrecon)

这个工具最主要的功能就是可以让你在知道用户名的情况下批量去各个社交网站上查找这个用户名的主页,方便收集对象的主页

3704
来自专栏ml

flume安装及配置介绍(二)

注: 环境: skylin-linux Flume的下载方式:   wget http://www.apache.org/dyn/closer.lua/flu...

35011
来自专栏杂烩

组件化项目搭建(非专业,无聊的一次尝试)三 原

        现在dao已经独立出去了,办公室里的一部分人员分出去,但还有一些干等着呢。得了,继续弄吧,业务这层,包含的还有控制器这一层,所以直接使用spri...

882
来自专栏阿杜的世界

《Spring Boot Cookbook》阅读笔记六、应用打包和部署七、应用监控和数据可视化

从技术雷达 : 关于技术趋势的分析报告和Profile of successful Java developer in 2016这两篇文章中都可以看出,作为Ja...

963
来自专栏张善友的专栏

Windows Server AppFabric Beta 2 已经发布

Windows Server AppFabric Beta 2是一个包含完全功能的AppFabric版本(This build represents our “...

1815
来自专栏Golang语言社区

Google Cloud 宣布支持Go 1.11

The Go Blog Announcing App Engine’s New Go 1.11 Runtime

1814
来自专栏名山丶深处

springboot集成redis(mybatis、分布式session)

2098

扫码关注云+社区

领取腾讯云代金券