LoginSignup
2
2

More than 3 years have passed since last update.

GAE/Goアプリをアップグレード(go1.9→go1.11)するときに必要だった変更や、参考になった記事

Posted at

GAE/Goアプリをアップグレード(go1.9→go1.11)するときに必要だった変更や、参考になった記事をまとめておく。

app.yamlの変更点

go1.9のapp.yaml
runtime: go
application: hogehoge
version: 1
api_version: go1

handlers:
- url: /admin/.*
  script: _go_app 
  login: admin
  secure: always

- url: /static
  static_dir: static

- url: /.*
  script: _go_app
  secure: always

threadsafe: true

automatic_scaling:
  min_idle_instances: automatic   # idle状態にあるインスタンスの最小値
  max_idle_instances: 1           # idle状態にあるインスタンスの最大値
  min_pending_latency: 3000ms     # リクエストを処理するまでに許される待ち時間の最小
  max_pending_latency: automatic   
go1.11のapp.yaml
runtime: go111
handlers:
- url: /static
  static_dir: static

- url: /.*
  script: auto
  secure: always

automatic_scaling:
  min_idle_instances: automatic   # idle状態にあるインスタンスの最小値
  max_idle_instances: 1           # idle状態にあるインスタンスの最大値
  min_pending_latency: 3000ms     # リクエストを処理するまでに許される待ち時間の最小
  max_pending_latency: automatic

diff

+ runtime: go111
- runtime: go
- application: hogehoge
- version: 1
- api_version: go1

- url: /admin/.*
-   script: _go_app 
-   login: admin
-   secure: always

- threadsafe: true

ファイル、フォルダー構成の変更点

Before
+---app
   |   app.go
   |   app.yaml
   |   
   +---static
   |           
   \---templates

After
 .gcloudignore
 app.go
 app.yaml
 go.mod
 go.sum
+---static
|           
\---templates

appディレクトリをなくし、ルートディレクトリにapp.yaml等を移動させた理由

nouhau/app-engine/note/gaego19-migration-gaego111 at master · gcpug/nouhau

Go 1.9までは app.yaml の位置がWorking Dirでしたが、Go 1.11の場合、Productionはgo.modがある位置がWorking Dirになるようになります

app.goの変更点

- func init() {
+ func main() {
    router := mux.NewRouter().StrictSlash(true)
    routerV1(router)

    http.Handle("/", router)
+   appengine.Main()
}

参考記事

1.9→1.11アップグレードについて

Modulesについて

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2