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

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

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏杂烩

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

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

882
来自专栏Golang语言社区

Google Cloud 宣布支持Go 1.11

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

1472
来自专栏bboysoul

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

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

3704
来自专栏Laoqi's Linux运维专列

MySQL高可用架构之MHA

4393
来自专栏张善友的专栏

Windows Server AppFabric Beta 2 已经发布

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

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

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

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

3117
来自专栏A周立SpringCloud

Spring Cloud各组件配置属性总结

我们知道,Spring Cloud是个工具集,整合了各种组件。有的组件Spring Cloud是拿来主义,有的组件Spring Cloud又进行了一些增强(例如...

3605
来自专栏阿杜的世界

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

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

963
来自专栏一个会写诗的程序员的博客

第3讲 Kotlin + Spring Boot 集成 MyBatis 进行数据库层开发【视频教程】《Kotlin + Spring Boot:下一代 Java 服务端开发》系列课程 ——《Kotli

993
来自专栏一个会写诗的程序员的博客

《Spring Boot极简教程》第7章 Spring Boot集成模板引擎

其实,没有任何一个模板引擎(jsp,velocity,thymeleaf,freemarker,etc)可以完全实现MVC绝对的分层,只有“自由度”上的界定罢了...

1104

扫码关注云+社区

领取腾讯云代金券