fix judge path func

This commit is contained in:
ehlxr 2018-04-13 22:39:01 +08:00
parent f499fd0449
commit 68a92c68af
3 changed files with 31 additions and 22 deletions

View File

@ -1,3 +1,5 @@
.PHONY: default init build install release dep get_deps clean build_amd64 build_386 upx
# https://golang.org/doc/install/source#environment # https://golang.org/doc/install/source#environment
GOOS := $(shell go env | awk -F= '$$1=="GOOS" {print $$2}' | awk -F '"' '{print $$2}') # 此处 awk 需使用两个 $ GOOS := $(shell go env | awk -F= '$$1=="GOOS" {print $$2}' | awk -F '"' '{print $$2}') # 此处 awk 需使用两个 $
GOARCH := $(shell go env | awk -F= '$$1=="GOARCH" {print $$2}' | awk -F '"' '{print $$2}') GOARCH := $(shell go env | awk -F= '$$1=="GOARCH" {print $$2}' | awk -F '"' '{print $$2}')
@ -7,7 +9,13 @@ PKG =
# GOARCH := $(strip $(GOARCH)).exe # GOARCH := $(strip $(GOARCH)).exe
# endif # endif
.PHONY: build default:
@echo "JWT info: please choose a target for 'make'"
@echo "available target: init build install release dep get_deps clean build_amd64 build_386 upx"
init: get-deps dep clean
go install -ldflags "-s -w"
build: build:
@ go build -ldflags "-s -w" -o dist/jwt_$(strip $(GOOS))_$(strip $(if \ @ go build -ldflags "-s -w" -o dist/jwt_$(strip $(GOOS))_$(strip $(if \
$(findstring windows,$(GOOS)),\ $(findstring windows,$(GOOS)),\
@ -15,25 +23,33 @@ build:
$(strip $(GOARCH))\ $(strip $(GOARCH))\
)) ))
.PHONY: amd64 install:
amd64: go install -ldflags "-s -w"
release: amd64 386
dep:
dep ensure
get_deps:
go get -u github.com/golang/dep/cmd/dep
clean:
go clean -i
rm -rf dist/jwt* jbls
build_amd64:
@ $(foreach OS,\ @ $(foreach OS,\
$(OSS),\ $(OSS),\
$(shell CGO_ENABLED=0 GOOS=$(OS) GOARCH=amd64 go build -ldflags "-s -w" -o dist/jwt_$(OS)_amd64$(if $(findstring windows,$(OS)),.exe))) $(shell CGO_ENABLED=0 GOOS=$(OS) GOARCH=amd64 go build -ldflags "-s -w" -o dist/jwt_$(OS)_amd64$(if $(findstring windows,$(OS)),.exe)))
@ echo done @ echo done
.PHONY: 386 build_386:
386:
@ $(foreach OS,\ @ $(foreach OS,\
$(OSS),\ $(OSS),\
$(shell CGO_ENABLED=0 GOOS=$(OS) GOARCH=386 go build -ldflags "-s -w" -o dist/jwt_$(OS)_386$(if $(findstring windows,$(OS)),.exe))) $(shell CGO_ENABLED=0 GOOS=$(OS) GOARCH=386 go build -ldflags "-s -w" -o dist/jwt_$(OS)_386$(if $(findstring windows,$(OS)),.exe)))
@ echo done @ echo done
.PHONY: clean
clean:
@ rm -rf dist/jwt* jbls
# 压缩。需要安装 https://github.com/upx/upx # 压缩。需要安装 https://github.com/upx/upx
.PHONY: upx
upx: upx:
@ upx $(if $(PKG),$(PKG),dist/jwt*) upx $(if $(PKG),$(PKG),dist/jwt*)

View File

@ -1,6 +1,5 @@
{ {
"foo": "bar", "ceres.enncloud.cn/app.id": "SunAR6mmR",
"exp": "2108-02-03", "ceres.enncloud.cn/namespace": "g-ceres",
"info": "jjjkk", "sub": "ceres.enncloud.cn:app:SunAR6mmR"
"other": "靠捡垃圾困了就睡打发士大夫斯柯达房间爱劳动法"
} }

View File

@ -25,7 +25,6 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -65,12 +64,7 @@ func loadData(p string) ([]byte, error) {
} }
func isPath(path string) (bool, string) { func isPath(path string) (bool, string) {
p, err := filepath.Abs("") absPath, err := filepath.Abs(path)
if err != nil {
log.Fatal(err)
}
absPath := filepath.Join(p, strings.Replace(path, p, "", 1))
_, err = os.Stat(absPath) _, err = os.Stat(absPath)
if err == nil { if err == nil {
return true, absPath return true, absPath