Skip to content

Commit

Permalink
codecgen: Use build tags to determine whether vendoring is enabled or…
Browse files Browse the repository at this point in the history
… not.

Defaults genCheckVendor to false.

For 1.5 and 1.6, set genCheckVendor appropriately using
the environmental variable GO15VENDOREXPERIMENT.

Also, support "interface {}" as synonym for "interface{}"
to accomodate some changes seen in tip.

Fixes #147
  • Loading branch information
ugorji committed Mar 14, 2016
1 parent 03b46f3 commit 9072926
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 3 additions & 5 deletions codec/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"io"
"io/ioutil"
"math/rand"
"os"
"reflect"
"regexp"
"sort"
Expand Down Expand Up @@ -126,6 +125,7 @@ var (
genExpectArrayOrMapErr = errors.New("unexpected type. Expecting array/map/slice")
genBase64enc = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789__")
genQNameRegex = regexp.MustCompile(`[A-Za-z_.]+`)
genCheckVendor bool
)

// genRunner holds some state used during a Gen run.
Expand Down Expand Up @@ -1626,8 +1626,6 @@ func (x *genV) MethodNamePfx(prefix string, prim bool) string {

}

var genCheckVendor = os.Getenv("GO15VENDOREXPERIMENT") == "1"

// genImportPath returns import path of a non-predeclared named typed, or an empty string otherwise.
//
// This handles the misbehaviour that occurs when 1.5-style vendoring is enabled,
Expand Down Expand Up @@ -1678,7 +1676,7 @@ func genNonPtr(t reflect.Type) reflect.Type {

func genTitleCaseName(s string) string {
switch s {
case "interface{}":
case "interface{}", "interface {}":
return "Intf"
default:
return strings.ToUpper(s[0:1]) + s[1:]
Expand Down Expand Up @@ -1781,7 +1779,7 @@ func (x genInternal) FastpathLen() (l int) {

func genInternalZeroValue(s string) string {
switch s {
case "interface{}":
case "interface{}", "interface {}":
return "nil"
case "bool":
return "false"
Expand Down
12 changes: 12 additions & 0 deletions codec/gen_15.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.

// +build go1.5,!go1.6

package codec

import "os"

func init() {
genCheckVendor = os.Getenv("GO15VENDOREXPERIMENT") == "1"
}
12 changes: 12 additions & 0 deletions codec/gen_16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.

// +build go1.6

package codec

import "os"

func init() {
genCheckVendor = os.Getenv("GO15VENDOREXPERIMENT") != "0"
}

0 comments on commit 9072926

Please sign in to comment.