前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Google Cloud 宣布支持Go 1.11

Google Cloud 宣布支持Go 1.11

作者头像
李海彬
发布2018-11-08 15:44:33
5610
发布2018-11-08 15:44:33
举报
文章被收录于专栏:Golang语言社区Golang语言社区

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:

代码语言:javascript
复制
 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:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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

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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-10-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Golang语言社区 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Related articles
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档