SWEet

A Software Engineer Is Eating Technologies

GAEにデプロイするとき今のバージョンのzapは使っちゃだめ

GAEでgolangwebサービスをデプロイしようとしたとき

github.com

unique id発行のために上のライブラリを使っていたんですが、内部でzapを使っていました。

github.com

zapは以下のようにgo1.9から追加されたtype aliasを使っています。

package zap

import (
    "fmt"
    "math"
    "time"

    "go.uber.org/zap/zapcore"
)

// Field is an alias for Field. Aliasing this type dramatically
// improves the navigability of this package's API documentation.
type Field = zapcore.Field

// Skip constructs a no-op field, which is often useful when handling invalid
// inputs in other Field constructors.
func Skip() Field {
    return Field{Type: zapcore.SkipType}
}

この場合、GAEにデプロイするときに次のようなエラーでこけます。

File upload done.
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Deployment contains files that cannot be compiled: Compile failed:
/work_dir/go.uber.org/zap/field.go:33: syntax error: unexpected = in type declaration
2018/05/24 22:16:54 go-app-builder: build timing: 72×compile (9m48.835s total), 0×link (0s total)
2018/05/24 22:16:54 go-app-builder: failed running compile: exit status 2

GAEのruntimeが1.8までしかまだ対応してないからですね。

というわけでzap使いたい場合はGAEが1.9に上がるまで待ちましょう。 今回はkatsubushiの代わりにxidを使うことにしました。

github.com