compatible for go 1.11 and go 1.12

pull/65/head
edwardpro 2019-03-16 18:11:17 +08:00 committed by Baokun Lee
parent c8a38458f3
commit add79fbe31
3 changed files with 44 additions and 1 deletions

View File

@ -2,11 +2,21 @@
PKG="${PWD}/internal"
GOROOT="$(go env GOROOT)"
GOVERSION=`go version | awk -F ' ' '{print $3}'|grep '1.12'`
GTGO12=0
echo "ENV GOLANG VER: $GOVERSION"
if [[ "$GOVERSION" != "" ]]
then
GTGO12=1
echo "use 1.12 mode"
else
echo "use 1.11 mode"
fi
mkdir -p "${PKG}"
cp -r "${GOROOT}/src/cmd/go/internal/"* "${PKG}"
cp -r "${GOROOT}/src/cmd/internal/browser" "${PKG}"
cp -r "${GOROOT}/src/cmd/internal/buildid" "${PKG}"
cp -r "${GOROOT}/src/cmd/internal/objabi" "${PKG}"
@ -15,8 +25,20 @@ cp -r "${GOROOT}/src/cmd/internal/test2json" "${PKG}"
cp -r "${GOROOT}/src/internal/singleflight" "${PKG}"
cp -r "${GOROOT}/src/internal/testenv" "${PKG}"
if [[ "$GTGO12" = "1" ]]
then
cp -r "${GOROOT}/src/internal/xcoff" "${PKG}"
cp -r "${GOROOT}/src/internal/goroot" "${PKG}"
cp -r "${GOROOT}/src/cmd/internal/sys" "${PKG}"
fi
find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/cmd\/go\/internal/github.com\/goproxyio\/goproxy\/internal/g' {} +
find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/cmd\/internal/github.com\/goproxyio\/goproxy\/internal/g' {} +
find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/internal\/singleflight/github.com\/goproxyio\/goproxy\/internal\/singleflight/g' {} +
find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/internal\/testenv/github.com\/goproxyio\/goproxy\/internal\/testenv/g' {} +
if [[ "$GTGO12" = "1" ]]
then
find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/internal\/goroot/github.com\/goproxyio\/goproxy\/internal\/goroot/g' {} +
find "${PKG}" -type f -name '*.go' -exec sed -i -e 's/internal\/xcoff/github.com\/goproxyio\/goproxy\/internal\/xcoff/g' {} +
fi

2
go.mod
View File

@ -1 +1,3 @@
module github.com/goproxyio/goproxy
go 1.12

19
main.go
View File

@ -8,8 +8,10 @@ import (
"log"
"net/http"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
@ -24,6 +26,23 @@ func init() {
flag.StringVar(&cacheDir, "cacheDir", "", "go modules cache dir")
flag.StringVar(&listen, "listen", "0.0.0.0:8081", "service listen address")
flag.Parse()
isGitValid := checkGitVersion()
if !isGitValid {
log.Fatal("Error in git version, please check your git installed in local, must be great 2.0")
}
}
func checkGitVersion() bool {
var err error
var ret []byte
cmd := exec.Command("git", "version")
if ret, err = cmd.Output(); err != nil {
return false
}
if strings.HasPrefix(string(ret), "git version 2") {
return true
}
return false
}
func main() {