diff --git a/cmd/gen-go-sample/main.go b/cmd/gen-go-sample/main.go index e364b64df8f..d005d2f4bc6 100644 --- a/cmd/gen-go-sample/main.go +++ b/cmd/gen-go-sample/main.go @@ -24,10 +24,12 @@ import ( "os" "sort" "strings" + "time" "github.com/golang/protobuf/proto" "github.com/golang/protobuf/protoc-gen-go/descriptor" "github.com/googleapis/gapic-generator-go/internal/errors" + "github.com/googleapis/gapic-generator-go/internal/license" "github.com/googleapis/gapic-generator-go/internal/pbinfo" "github.com/googleapis/gapic-generator-go/internal/printer" yaml "gopkg.in/yaml.v2" @@ -144,8 +146,8 @@ func (g *generator) commit(gofmt bool) error { firstNonStd := sort.Search(len(imports), func(i int) bool { return strings.IndexByte(imports[i].Path, '.') >= 0 }) - // TODO(pongad): add license var file bytes.Buffer + fmt.Fprintf(&file, license.Apache, time.Now().Year()) file.WriteString("package main\n") file.WriteString("import(\n") for i, imp := range imports { diff --git a/gengapic/doc_file.go b/gengapic/doc_file.go index f38c4519c97..3d6c28c96c0 100644 --- a/gengapic/doc_file.go +++ b/gengapic/doc_file.go @@ -19,6 +19,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/golang/protobuf/protoc-gen-go/descriptor" + "github.com/googleapis/gapic-generator-go/internal/license" "google.golang.org/genproto/googleapis/api/annotations" ) @@ -29,7 +30,7 @@ import ( func (g *generator) genDocFile(pkgPath, pkgName string, year int, scopes []string) { p := g.printf - p(apacheLicense, year) + p(license.Apache, year) p("") p("// Package %s is an auto-generated package for the", pkgName) diff --git a/gengapic/gengapic.go b/gengapic/gengapic.go index 59c54855778..d70d97f69b0 100644 --- a/gengapic/gengapic.go +++ b/gengapic/gengapic.go @@ -27,6 +27,7 @@ import ( "github.com/golang/protobuf/protoc-gen-go/descriptor" plugin "github.com/golang/protobuf/protoc-gen-go/plugin" "github.com/googleapis/gapic-generator-go/internal/errors" + "github.com/googleapis/gapic-generator-go/internal/license" "github.com/googleapis/gapic-generator-go/internal/pbinfo" "github.com/googleapis/gapic-generator-go/internal/printer" "google.golang.org/genproto/googleapis/api/annotations" @@ -178,7 +179,7 @@ func (g *generator) printf(s string, a ...interface{}) { func (g *generator) commit(fileName, pkgName string) { var header strings.Builder - fmt.Fprintf(&header, apacheLicense, time.Now().Year()) + fmt.Fprintf(&header, license.Apache, time.Now().Year()) fmt.Fprintf(&header, "package %s\n\n", pkgName) var imps []pbinfo.ImportSpec diff --git a/gengapic/license.go b/internal/license/license.go similarity index 94% rename from gengapic/license.go rename to internal/license/license.go index 007a6590df0..99fd8bc9a0c 100644 --- a/gengapic/license.go +++ b/internal/license/license.go @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package gengapic +package license -const apacheLicense = `// Copyright %d Google LLC +const Apache = `// Copyright %d Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.