Skip to content

Commit

Permalink
Merge pull request #178 from axw/gorm-go1.9
Browse files Browse the repository at this point in the history
module/apmgorm: require Go 1.9+
  • Loading branch information
axw authored Aug 20, 2018
2 parents 8109cf2 + bccfb96 commit 8f4b9d2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ check-goimports:

.PHONY: check-dockerfile-testing
check-dockerfile-testing:
ifeq ($(shell go run ./scripts/mingoversion.go -print 1.9),true)
go run ./scripts/gendockerfile.go -d
endif

.PHONY: check-lint
check-lint:
Expand Down
2 changes: 2 additions & 0 deletions module/apmgorm/apmgorm_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.9

package apmgorm_test

import (
Expand Down
2 changes: 2 additions & 0 deletions module/apmgorm/context.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.9

package apmgorm

import (
Expand Down
2 changes: 2 additions & 0 deletions module/apmgorm/doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// +build go1.9

// Package apmgorm provides wrappers for tracing GORM operations.
package apmgorm
2 changes: 2 additions & 0 deletions module/apmgorm/open.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.9

package apmgorm

import (
Expand Down
75 changes: 75 additions & 0 deletions scripts/mingoversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// +build ignore

package main

import (
"flag"
"fmt"
"os"
"regexp"
"runtime"
"strconv"
)

var (
printFlag = flag.Bool("print", false, "Print true or false, and always exit with 0 except in case of usage errors")
)

func main() {
flag.Parse()
if flag.NArg() == 0 {
fmt.Fprintf(os.Stderr, "Usage: %s <minimum-version>\n", os.Args)
os.Exit(2)
}

re := regexp.MustCompile(`^(?:go)?(\d+).(\d+)(?:\.(\d+))?$`)
arg := flag.Arg(0)
argSubmatch := re.FindStringSubmatch(arg)
if argSubmatch == nil {
fmt.Fprintln(os.Stderr, "Invalid minimum-version: expected x.y or x.y.z")
os.Exit(2)
}

runtimeVersion := runtime.Version()
goSubmatch := re.FindStringSubmatch(runtimeVersion)
if goSubmatch == nil {
fmt.Fprintln(os.Stderr, "Failed to parse runtime.Version(%s)", runtimeVersion)
os.Exit(3)
}

result := true
minVersion := makeInts(argSubmatch[1:])
goVersion := makeInts(goSubmatch[1:])
for i := range minVersion {
n := goVersion[i] - minVersion[i]
if n < 0 {
if *printFlag {
result = false
} else {
fmt.Fprintf(os.Stderr, "%s < %s\n", runtimeVersion, arg)
os.Exit(1)
}
}
if n > 0 {
break
}
}
if *printFlag {
fmt.Println(result)
}
}

func makeInts(s []string) []int {
ints := make([]int, len(s))
for i, s := range s {
if s == "" {
s = "0"
}
n, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
ints[i] = n
}
return ints
}

0 comments on commit 8f4b9d2

Please sign in to comment.