From da3e7a29d460873d3d9b2fcc5ce53cc2b3d17108 Mon Sep 17 00:00:00 2001 From: CXM Date: Tue, 31 May 2022 21:34:28 +0800 Subject: [PATCH 1/4] fix: asset --- Dockerfile | 2 +- comic.ttf => assets/comic.ttf | Bin internal/routers/api/home.go | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename comic.ttf => assets/comic.ttf (100%) diff --git a/Dockerfile b/Dockerfile index 38ea62e6..109cbea6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ ENV TZ=Asia/Shanghai RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates COPY --from=build-env /paopao-ce/paopao-ce /usr/bin/paopao-ce -COPY --from=build-env /paopao-ce/comic.ttf /comic.ttf +COPY --from=build-env /paopao-ce/assets/comic.ttf /assets/comic.ttf COPY --from=build-env /paopao-ce/configs /configs EXPOSE 8000 diff --git a/comic.ttf b/assets/comic.ttf similarity index 100% rename from comic.ttf rename to assets/comic.ttf diff --git a/internal/routers/api/home.go b/internal/routers/api/home.go index fb48f07d..e33441e5 100644 --- a/internal/routers/api/home.go +++ b/internal/routers/api/home.go @@ -44,7 +44,7 @@ func SyncSearchIndex(c *gin.Context) { func GetCaptcha(c *gin.Context) { cap := captcha.New() - if err := cap.SetFont("comic.ttf"); err != nil { + if err := cap.SetFont("assets/comic.ttf"); err != nil { panic(err.Error()) } From 6f6e1553d340193b0c95a36646e7962867151efc Mon Sep 17 00:00:00 2001 From: CXM Date: Tue, 31 May 2022 21:34:55 +0800 Subject: [PATCH 2/4] chore(deps): fix deprecated package --- go.mod | 2 +- pkg/sign/sign.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index cb0ddd07..88d8a726 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/go-redis/redis/v8 v8.11.4 github.com/go-resty/resty/v2 v2.7.0 github.com/gofrs/uuid v3.3.0+incompatible - github.com/golang/protobuf v1.5.2 github.com/google/go-cmp v0.5.7 // indirect github.com/satori/go.uuid v1.2.0 // indirect github.com/sirupsen/logrus v1.8.1 @@ -28,6 +27,7 @@ require ( golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect + google.golang.org/protobuf v1.27.1 gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/resty.v1 v1.12.0 gorm.io/driver/mysql v1.3.2 diff --git a/pkg/sign/sign.go b/pkg/sign/sign.go index ebce41d1..717b8e54 100644 --- a/pkg/sign/sign.go +++ b/pkg/sign/sign.go @@ -6,8 +6,8 @@ import ( "time" "github.com/fbsobreira/gotron-sdk/pkg/proto/core" - "github.com/golang/protobuf/proto" "github.com/rocboss/paopao-ce/pkg/crypto" + "google.golang.org/protobuf/proto" ) // SignTransaction 签名交易 From 0fcc85df24db6d53ba8ba571e9ed376543a0775d Mon Sep 17 00:00:00 2001 From: CXM Date: Tue, 31 May 2022 21:37:53 +0800 Subject: [PATCH 3/4] feat: hello banner --- go.mod | 1 + go.sum | 2 ++ main.go | 11 ++++++++++- pkg/util/banner.go | 12 ++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 pkg/util/banner.go diff --git a/go.mod b/go.mod index 88d8a726..2fc783ce 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/disintegration/imaging v1.6.2 github.com/ethereum/go-ethereum v1.10.16 + github.com/fatih/color v1.13.0 github.com/fbsobreira/gotron-sdk v0.0.0-20211102183839-58a64f4da5f4 github.com/gin-contrib/cors v1.3.1 github.com/gin-gonic/gin v1.7.7 diff --git a/go.sum b/go.sum index 19759b67..9aaf5068 100644 --- a/go.sum +++ b/go.sum @@ -201,6 +201,7 @@ github.com/ethereum/go-ethereum v1.10.16 h1:3oPrumn0bCW/idjcxMn5YYVCdK7VzJYIvwGZ github.com/ethereum/go-ethereum v1.10.16/go.mod h1:Anj6cxczl+AHy63o4X9O8yWNHuN5wMpfb8MAnHkWn7Y= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fbsobreira/gotron-sdk v0.0.0-20211102183839-58a64f4da5f4 h1:zlN+of+l+or/Y6CYgpX99wwaTf4zN0myVj6YAXiE3xk= @@ -485,6 +486,7 @@ github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= diff --git a/main.go b/main.go index 3bf3441f..8aa7adf9 100644 --- a/main.go +++ b/main.go @@ -4,9 +4,15 @@ import ( "fmt" "net/http" + "github.com/fatih/color" "github.com/gin-gonic/gin" "github.com/rocboss/paopao-ce/global" "github.com/rocboss/paopao-ce/internal/routers" + "github.com/rocboss/paopao-ce/pkg/util" +) + +var ( + version, buildDate, commitID string ) func main() { @@ -21,6 +27,9 @@ func main() { MaxHeaderBytes: 1 << 20, } - fmt.Printf("\x1b[36m%s\x1b[0m\n", "PaoPao service listen on http://"+global.ServerSetting.HttpIp+":"+global.ServerSetting.HttpPort) + util.PrintHelloBanner(fmt.Sprintf("paopao %s (build:%s %s)", version, commitID, buildDate)) + fmt.Fprintf(color.Output, "PaoPao service listen on %s\n", + color.GreenString(fmt.Sprintf("http://%s:%s", global.ServerSetting.HttpIp, global.ServerSetting.HttpPort)), + ) s.ListenAndServe() } diff --git a/pkg/util/banner.go b/pkg/util/banner.go new file mode 100644 index 00000000..d41b5ae1 --- /dev/null +++ b/pkg/util/banner.go @@ -0,0 +1,12 @@ +package util + +import "fmt" + +func PrintHelloBanner(text string) { + + fmt.Println(" ____ __ __ ____ __ __ ") + fmt.Println("( _ \\ / _\\ / \\( _ \\ / _\\ / \\ ") + fmt.Println(" ) __// \\( O )) __// \\( O )") + fmt.Println("(__) \\_/\\_/ \\__/(__) \\_/\\_/ \\__/ ") + fmt.Println(text) +} From b4329e5f5cf9fd6f288e1396a95b6f2447ea47a8 Mon Sep 17 00:00:00 2001 From: CXM Date: Tue, 31 May 2022 21:38:09 +0800 Subject: [PATCH 4/4] fix: build script --- .gitignore | 6 ++++-- Makefile | 26 ++++++++++++++++++++++++++ build.sh | 35 +++++++++++++++++++++++++++++++++++ version | 0 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100644 build.sh create mode 100644 version diff --git a/.gitignore b/.gitignore index 4b772892..4f7e39cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +.idea .vscode -__debug_bin +!*.example +dist/ config.yaml *.log -paopao-api \ No newline at end of file +paopao-ce* diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..0c3a847f --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +.PHONY: all build clean fmt help +BUILD_VERSION := $(shell cat version) +BUILD_DATE := $(shell date +'%Y-%m-%d %H:%M:%S') +SHA_SHORT := $(shell git rev-parse --short HEAD) +all: fmt build +build: + @go mod download + @echo Build paopao-ce + bash build.sh paopao-ce +clean: + @go clean + @find ./dist -type f -exec rm -r {} + + @find ./tmp -type f -exec rm -r {} + +fmt: + @echo Formatting... + @go fmt ./global/... + @go fmt ./internal/... + @go fmt ./pkg/... + @go vet -composites=false ./global/... + @go vet -composites=false ./internal/... + @go vet -composites=false ./pkg/... +help: + @echo "make: make" + @echo "make build: build executables" +.EXPORT_ALL_VARIABLES: +GO111MODULE = on diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..a0284a5e --- /dev/null +++ b/build.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2155 +set -e +DIST_PREFIX=${1} +DEBUG_MODE=${2} +TARGET_DIR="dist" +PLATFORMS="darwin/arm64 linux/amd64 windows/amd64" + +rm -rf ${TARGET_DIR} +mkdir ${TARGET_DIR} + +for pl in ${PLATFORMS}; do + export CGO_ENABLED=0 + export GOOS=$(echo "${pl}" | cut -d'/' -f1) + export GOARCH=$(echo "${pl}" | cut -d'/' -f2) + export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH} + if [ "${GOOS}" == "windows" ]; then + export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}.exe + fi + + echo "build => ${TARGET}" + if [ "${DEBUG_MODE}" == "debug" ]; then + go build -trimpath -gcflags "all=-N -l" -o "${TARGET}" \ + -ldflags "-X 'main.version=${BUILD_VERSION}' \ + -X 'main.buildDate=${BUILD_DATE}' \ + -X 'main.commitID=${SHA_SHORT}'\ + -w -s" + else + go build -trimpath -o "${TARGET}" \ + -ldflags "-X 'main.version=${BUILD_VERSION}' \ + -X 'main.buildDate=${BUILD_DATE}' \ + -X 'main.commitID=${SHA_SHORT}'\ + -w -s" + fi +done diff --git a/version b/version new file mode 100644 index 00000000..e69de29b