release v1.0.1
This commit is contained in:
parent
899d0dc08f
commit
ede4bd17e9
@ -45,7 +45,7 @@ var versionCmd = &cobra.Command{
|
|||||||
Long: `
|
Long: `
|
||||||
Print version of jwt`,
|
Print version of jwt`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
banner, _ := base64.StdEncoding.DecodeString(bannerBase64)
|
banner, _ := base64.StdEncoding.DecodeString(metadata.BannerBase64)
|
||||||
fmt.Printf(versionTpl, banner, metadata.Version, metadata.BuildTime, metadata.GitCommit, metadata.GoVersion)
|
fmt.Printf(versionTpl, banner, metadata.Version, metadata.BuildTime, metadata.GitCommit, metadata.GoVersion)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ var (
|
|||||||
GitCommit string
|
GitCommit string
|
||||||
GoVersion string
|
GoVersion string
|
||||||
|
|
||||||
bannerBase64 = "DQogICBfXyAgICAgX18gICAgIF9fICAgICBfX19fX18gIA0KICAvXCBcICAgL1wgXCAgXyBcIFwgICAvXF9fICBfXCANCiBfXF9cIFwgIFwgXCBcLyAiLlwgXCAgXC9fL1wgXC8gDQovXF9fX19fXCAgXCBcX18vIi5+XF9cICAgIFwgXF9cIA0KXC9fX19fXy8gICBcL18vICAgXC9fLyAgICAgXC9fLyANCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgDQo="
|
BannerBase64 = "DQogICAgX18gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgX18gDQogICAvIC9fICBfX18gIF8gIF9fICAgICAgX19fX19fX19fICBfX19fIF8gICBfX19fXyAgX19fX18vIC9fDQogIC8gX18gXC8gXyBcfCB8L18vX19fX18vIF9fXy8gX18gXC8gX18gXCB8IC8gLyBfIFwvIF9fXy8gX18vDQogLyAvIC8gLyAgX18vPiAgPC9fX19fXy8gL19fLyAvXy8gLyAvIC8gLyB8LyAvICBfXy8gLyAgLyAvXyAgDQovXy8gL18vXF9fXy9fL3xffCAgICAgIFxfX18vXF9fX18vXy8gL18vfF9fXy9cX19fL18vICAgXF9fLyAgDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgDQo="
|
||||||
)
|
)
|
||||||
|
|
||||||
var TEN_TO_ANY map[int]string = map[int]string{0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "a", 11: "b", 12: "c", 13: "d", 14: "e", 15: "f", 16: "g", 17: "h", 18: "i", 19: "j", 20: "k", 21: "l", 22: "m", 23: "n", 24: "o", 25: "p", 26: "q", 27: "r", 28: "s", 29: "t", 30: "u", 31: "v", 32: "w", 33: "x", 34: "y", 35: "z", 36: ":", 37: ";", 38: "<", 39: "=", 40: ">", 41: "?", 42: "@", 43: "[", 44: "]", 45: "^", 46: "_", 47: "{", 48: "|", 49: "}", 50: "A", 51: "B", 52: "C", 53: "D", 54: "E", 55: "F", 56: "G", 57: "H", 58: "I", 59: "J", 60: "K", 61: "L", 62: "M", 63: "N", 64: "O", 65: "P", 66: "Q", 67: "R", 68: "S", 69: "T", 70: "U", 71: "V", 72: "W", 73: "X", 74: "Y", 75: "Z"}
|
var TEN_TO_ANY map[int]string = map[int]string{0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "a", 11: "b", 12: "c", 13: "d", 14: "e", 15: "f", 16: "g", 17: "h", 18: "i", 19: "j", 20: "k", 21: "l", 22: "m", 23: "n", 24: "o", 25: "p", 26: "q", 27: "r", 28: "s", 29: "t", 30: "u", 31: "v", 32: "w", 33: "x", 34: "y", 35: "z", 36: ":", 37: ";", 38: "<", 39: "=", 40: ">", 41: "?", 42: "@", 43: "[", 44: "]", 45: "^", 46: "_", 47: "{", 48: "|", 49: "}", 50: "A", 51: "B", 52: "C", 53: "D", 54: "E", 55: "F", 56: "G", 57: "H", 58: "I", 59: "J", 60: "K", 61: "L", 62: "M", 63: "N", 64: "O", 65: "P", 66: "Q", 67: "R", 68: "S", 69: "T", 70: "U", 71: "V", 72: "W", 73: "X", 74: "Y", 75: "Z"}
|
||||||
|
149
server/server.go
149
server/server.go
@ -1,48 +1,119 @@
|
|||||||
BUILD_VERSION := $(shell cat version)
|
// Copyright © 2018 ehlxr <ehlxr.me@gmail.com>
|
||||||
BUILD_TIME := $(shell date "+%F %T")
|
//
|
||||||
COMMIT_SHA1 := $(shell git rev-parse HEAD)
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
DIST_DIR := $(ROOT_DIR)/dist/
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
VERSION_PATH := $(shell cat `go env GOMOD` | awk '/^module/{print $$2}')/cmd
|
package server
|
||||||
LD_GIT_COMMIT := -X '$(VERSION_PATH).GitCommit=$(COMMIT_SHA1)'
|
|
||||||
LD_BUILD_TIME := -X '$(VERSION_PATH).BuildTime=$(BUILD_TIME)'
|
|
||||||
LD_GO_VERSION := -X '$(VERSION_PATH).GoVersion=`go version`'
|
|
||||||
LD_GATEWAY_VERSION := -X '$(VERSION_PATH).Version=$(BUILD_VERSION)'
|
|
||||||
LD_FLAGS := "$(LD_GIT_COMMIT) $(LD_BUILD_TIME) $(LD_GO_VERSION) $(LD_GATEWAY_VERSION) -w -s"
|
|
||||||
|
|
||||||
.PHONY : build release clean install upx
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
build:
|
"github.com/ehlxr/hex-convert/gen"
|
||||||
ifneq ($(shell type gox >/dev/null 2>&1;echo $$?), 0)
|
|
||||||
@echo "Can't find gox command, will start installation..."
|
|
||||||
GO111MODULE=off go get -v -u github.com/mitchellh/gox
|
|
||||||
endif
|
|
||||||
# @$(if $(findstring 0,$(shell type gox >/dev/null 2>&1;echo $$?)),,echo "Can't find gox command, will start installation...";GO111MODULE=off go get -v -u github.com/mitchellh/gox)
|
|
||||||
gox -ldflags $(LD_FLAGS) -osarch="darwin/amd64 linux/386 linux/amd64 windows/amd64" \
|
|
||||||
-output="$(DIST_DIR){{.Dir}}_{{.OS}}_{{.Arch}}"
|
|
||||||
|
|
||||||
clean:
|
"github.com/ehlxr/hex-convert/converter"
|
||||||
rm -rf $(DIST_DIR)*
|
)
|
||||||
|
|
||||||
install:
|
func decimal(w http.ResponseWriter, req *http.Request) {
|
||||||
go install -ldflags $(LD_FLAGS)
|
scale, _ := strconv.Atoi(req.FormValue("scale"))
|
||||||
|
data := req.FormValue("data")
|
||||||
|
|
||||||
# 压缩。需要安装 https://github.com/upx/upx
|
result, err := converter.ToDecimal(scale, data)
|
||||||
upx:
|
if err != nil {
|
||||||
upx $(DIST_DIR)**
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
release: build upx
|
log.Println(result)
|
||||||
ifneq ($(shell type ghr >/dev/null 2>&1;echo $$?), 0)
|
_, _ = fmt.Fprintf(w, "<a href='/'>首页</a><br> %s", strconv.Itoa(result))
|
||||||
@echo "Can't find ghr command, will start installation..."
|
}
|
||||||
GO111MODULE=off go get -v -u github.com/tcnksm/ghr
|
|
||||||
endif
|
|
||||||
# @$(if $(findstring 0,$(shell type ghr >/dev/null 2>&1;echo $$?)),,echo "Can't find ghr command, will start installation...";GO111MODULE=off go get -v -u github.com/tcnksm/ghr)
|
|
||||||
ghr -u ehlxr -t $(GITHUB_RELEASE_TOKEN) -replace -delete --debug ${BUILD_VERSION} $(DIST_DIR)
|
|
||||||
|
|
||||||
# this tells 'make' to export all variables to child processes by default.
|
func binary(w http.ResponseWriter, req *http.Request) {
|
||||||
.EXPORT_ALL_VARIABLES:
|
scale, _ := strconv.Atoi(req.FormValue("scale"))
|
||||||
|
data := req.FormValue("data")
|
||||||
|
|
||||||
GO111MODULE = on
|
result, err := converter.ToBinary(scale, data)
|
||||||
GOPROXY = https://goproxy.cn,direct
|
if err != nil {
|
||||||
GOSUMDB = sum.golang.google.cn
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(result)
|
||||||
|
_, _ = fmt.Fprintf(w, "<a href='/'>首页</a><br> %s", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func submit(w http.ResponseWriter, req *http.Request) {
|
||||||
|
scale, _ := strconv.Atoi(req.FormValue("scale"))
|
||||||
|
data := req.FormValue("data")
|
||||||
|
|
||||||
|
var bd, od, dd, hd string
|
||||||
|
if scale != 2 && scale != 8 && scale != 10 && scale != 16 {
|
||||||
|
bd, od, dd, hd = "", "", "", ""
|
||||||
|
} else {
|
||||||
|
bd, _ = converter.ToBinary(scale, data)
|
||||||
|
d, err := converter.ToDecimal(scale, data)
|
||||||
|
if err == nil {
|
||||||
|
dd = strconv.Itoa(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
od, _ = converter.ToOctal(scale, data)
|
||||||
|
hd, _ = converter.ToHex(scale, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("%s %s %s %s", bd, od, dd, hd)
|
||||||
|
_, _ = fmt.Fprintf(w, "<a href='/'>首页</a><br>二进制:%s 八进制:%s 十进制:%s 十六进制:%s", bd, od, dd, hd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func index(w http.ResponseWriter, r *http.Request) {
|
||||||
|
f, err := gen.Assets.Open("/index.tpl")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
fd, err := ioutil.ReadAll(f)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = fmt.Fprintf(w, string(fd))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Start(host string, port int) error {
|
||||||
|
http.HandleFunc("/", index)
|
||||||
|
http.HandleFunc("/d", decimal)
|
||||||
|
http.HandleFunc("/b", binary)
|
||||||
|
http.HandleFunc("/s", submit)
|
||||||
|
|
||||||
|
addr := fmt.Sprintf("%s:%d", host, port)
|
||||||
|
if strings.Contains(addr, "0.0.0.0") {
|
||||||
|
addr = strings.Replace(addr, "0.0.0.0", "", 1)
|
||||||
|
host = strings.Replace(host, "0.0.0.0", "127.0.0.1", 1)
|
||||||
|
}
|
||||||
|
fmt.Printf("server start on: %s\n", fmt.Sprintf("http://%s:%d", host, port))
|
||||||
|
|
||||||
|
if err := http.ListenAndServe(addr, nil); err != nil {
|
||||||
|
return fmt.Errorf("ListenAndServe: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user