Opt: default trim path and service name

pull/47/head
zijiren233 2 years ago
parent 539950a46f
commit e54a5fbf2e

@ -29,7 +29,7 @@ jobs:
- name: Build - name: Build
run: | run: |
bash script/build.sh -s -P -p "windows,linux,darwin" bash script/build.sh -s -p "windows,linux,darwin"
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

@ -28,7 +28,7 @@ jobs:
- name: Build - name: Build
run: | run: |
bash script/build.sh -v "v${{ steps.get_version.outputs.VERSION }}" -P -p "windows,linux,darwin" bash script/build.sh -v "v${{ steps.get_version.outputs.VERSION }}" -p "windows,linux,darwin"
- uses: "marvinpinto/action-automatic-releases@latest" - uses: "marvinpinto/action-automatic-releases@latest"
with: with:

@ -22,7 +22,7 @@ jobs:
- name: Build - name: Build
run: | run: |
bash script/build.sh -v dev -P -p "windows,linux,darwin" bash script/build.sh -v dev -p "windows,linux,darwin"
- uses: "marvinpinto/action-automatic-releases@latest" - uses: "marvinpinto/action-automatic-releases@latest"
with: with:

@ -11,7 +11,7 @@ WORKDIR /synctv
COPY ./ ./ COPY ./ ./
RUN apk add --no-cache bash curl gcc git go musl-dev && \ RUN apk add --no-cache bash curl gcc git go musl-dev && \
bash script/build.sh -P -v ${VERSION} bash script/build.sh -v ${VERSION}
From alpine:latest From alpine:latest

@ -9,17 +9,17 @@ import (
) )
type Consul struct { type Consul struct {
ServerName string `json:"serverName"` ServiceName string `json:"serviceName"`
Token string `json:"token"` Token string `json:"token"`
PathPrefix string `json:"pathPrefix"` PathPrefix string `json:"pathPrefix"`
Namespace string `json:"namespace"` Namespace string `json:"namespace"`
Partition string `json:"partition"` Partition string `json:"partition"`
} }
type Etcd struct { type Etcd struct {
ServerName string `json:"serverName"` ServiceName string `json:"serviceName"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
} }
type Backend struct { type Backend struct {
@ -38,7 +38,7 @@ func (b *Backend) Validate() error {
if b.Endpoint == "" { if b.Endpoint == "" {
return errors.New("new http client failed, endpoint is empty") return errors.New("new http client failed, endpoint is empty")
} }
if b.Consul.ServerName != "" && b.Etcd.ServerName != "" { if b.Consul.ServiceName != "" && b.Etcd.ServiceName != "" {
return errors.New("new grpc client failed, consul and etcd can't be used at the same time") return errors.New("new grpc client failed, consul and etcd can't be used at the same time")
} }
if b.TimeOut != "" { if b.TimeOut != "" {

@ -488,7 +488,7 @@ func NewGrpcClientConn(ctx context.Context, conf *model.Backend) (*grpc.ClientCo
if conf.Endpoint == "" { if conf.Endpoint == "" {
return nil, errors.New("new grpc client failed, endpoint is empty") return nil, errors.New("new grpc client failed, endpoint is empty")
} }
if conf.Consul.ServerName != "" && conf.Etcd.ServerName != "" { if conf.Consul.ServiceName != "" && conf.Etcd.ServiceName != "" {
return nil, errors.New("new grpc client failed, consul and etcd can't be used at the same time") return nil, errors.New("new grpc client failed, consul and etcd can't be used at the same time")
} }
middlewares := []middleware.Middleware{kcircuitbreaker.Client(kcircuitbreaker.WithCircuitBreaker(func() circuitbreaker.CircuitBreaker { middlewares := []middleware.Middleware{kcircuitbreaker.Client(kcircuitbreaker.WithCircuitBreaker(func() circuitbreaker.CircuitBreaker {
@ -518,7 +518,7 @@ func NewGrpcClientConn(ctx context.Context, conf *model.Backend) (*grpc.ClientCo
opts = append(opts, ggrpc.WithTimeout(timeout)) opts = append(opts, ggrpc.WithTimeout(timeout))
} }
if conf.Consul.ServerName != "" { if conf.Consul.ServiceName != "" {
c := api.DefaultConfig() c := api.DefaultConfig()
c.Address = conf.Endpoint c.Address = conf.Endpoint
c.Token = conf.Consul.Token c.Token = conf.Consul.Token
@ -529,12 +529,12 @@ func NewGrpcClientConn(ctx context.Context, conf *model.Backend) (*grpc.ClientCo
if err != nil { if err != nil {
return nil, err return nil, err
} }
endpoint := fmt.Sprintf("discovery:///%s", conf.Consul.ServerName) endpoint := fmt.Sprintf("discovery:///%s", conf.Consul.ServiceName)
dis := consul.New(client) dis := consul.New(client)
opts = append(opts, ggrpc.WithEndpoint(endpoint), ggrpc.WithDiscovery(dis)) opts = append(opts, ggrpc.WithEndpoint(endpoint), ggrpc.WithDiscovery(dis))
log.Infof("new grpc client with consul: %s", conf.Endpoint) log.Infof("new grpc client with consul: %s", conf.Endpoint)
} else if conf.Etcd.ServerName != "" { } else if conf.Etcd.ServiceName != "" {
endpoint := fmt.Sprintf("discovery:///%s", conf.Etcd.ServerName) endpoint := fmt.Sprintf("discovery:///%s", conf.Etcd.ServiceName)
cli, err := clientv3.New(clientv3.Config{ cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{conf.Endpoint}, Endpoints: []string{conf.Endpoint},
Username: conf.Etcd.Username, Username: conf.Etcd.Username,
@ -633,7 +633,7 @@ func NewHttpClientConn(ctx context.Context, conf *model.Backend) (*http.Client,
})) }))
} }
if conf.Consul.ServerName != "" { if conf.Consul.ServiceName != "" {
c := api.DefaultConfig() c := api.DefaultConfig()
c.Address = conf.Endpoint c.Address = conf.Endpoint
c.Token = conf.Consul.Token c.Token = conf.Consul.Token
@ -644,12 +644,12 @@ func NewHttpClientConn(ctx context.Context, conf *model.Backend) (*http.Client,
if err != nil { if err != nil {
return nil, err return nil, err
} }
endpoint := fmt.Sprintf("discovery:///%s", conf.Consul.ServerName) endpoint := fmt.Sprintf("discovery:///%s", conf.Consul.ServiceName)
dis := consul.New(client) dis := consul.New(client)
opts = append(opts, http.WithEndpoint(endpoint), http.WithDiscovery(dis)) opts = append(opts, http.WithEndpoint(endpoint), http.WithDiscovery(dis))
log.Infof("new http client with consul: %s", conf.Endpoint) log.Infof("new http client with consul: %s", conf.Endpoint)
} else if conf.Etcd.ServerName != "" { } else if conf.Etcd.ServiceName != "" {
endpoint := fmt.Sprintf("discovery:///%s", conf.Etcd.ServerName) endpoint := fmt.Sprintf("discovery:///%s", conf.Etcd.ServiceName)
cli, err := clientv3.New(clientv3.Config{ cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{conf.Endpoint}, Endpoints: []string{conf.Endpoint},
Username: conf.Etcd.Username, Username: conf.Etcd.Username,

@ -13,7 +13,7 @@ function ChToScriptFileDir() {
function EnvHelp() { function EnvHelp() {
echo "SKIP_INIT_WEB" echo "SKIP_INIT_WEB"
echo "WEB_VERSION set web dependency version (default: build version)" echo "WEB_VERSION set web dependency version (default: build version)"
echo "TRIM_PATH enable trim path (default: disable)" echo "DISABLE_TRIM_PATH enable trim path (default: disable)"
} }
function Help() { function Help() {
@ -24,7 +24,7 @@ function Help() {
echo "-m set build mode (default: pie)" echo "-m set build mode (default: pie)"
echo "-l set ldflags (default: -s -w --extldflags \"-static -fpic -Wl,-z,relro,-z,now\")" echo "-l set ldflags (default: -s -w --extldflags \"-static -fpic -Wl,-z,relro,-z,now\")"
echo "-p set platform (default: host platform, support: all, linux, darwin, windows)" echo "-p set platform (default: host platform, support: all, linux, darwin, windows)"
echo "-P set trim path (default: disable)" echo "-P set disable trim path (default: disable)"
echo "-d set build result dir (default: build)" echo "-d set build result dir (default: build)"
echo "-T set tags (default: jsoniter)" echo "-T set tags (default: jsoniter)"
echo "Env Help:" echo "Env Help:"
@ -74,7 +74,7 @@ function ParseArgs() {
PLATFORM="$OPTARG" PLATFORM="$OPTARG"
;; ;;
P) P)
TRIM_PATH="true" DISABLE_TRIM_PATH="true"
;; ;;
d) d)
BUILD_DIR="$OPTARG" BUILD_DIR="$OPTARG"
@ -179,7 +179,7 @@ function Build() {
else else
EXT="" EXT=""
fi fi
if [ "$TRIM_PATH" ]; then if [ ! "$DISABLE_TRIM_PATH" ]; then
CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME-$GOOS-$GOARCH$EXT" ../ CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GOARCH=$GOARCH go build -trimpath -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME-$GOOS-$GOARCH$EXT" ../
else else
CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GOARCH=$GOARCH go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME-$GOOS-$GOARCH$EXT" ../ CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GOARCH=$GOARCH go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME-$GOOS-$GOARCH$EXT" ../
@ -199,7 +199,7 @@ function BuildSingle() {
EXT="" EXT=""
fi fi
echo "build $GOOS/$GOARCH" echo "build $GOOS/$GOARCH"
if [ "$TRIM_PATH" ]; then if [ ! "$DISABLE_TRIM_PATH" ]; then
CGO_ENABLED=$CGO_ENABLED go build -trimpath -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME$EXT" ../ CGO_ENABLED=$CGO_ENABLED go build -trimpath -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME$EXT" ../
else else
CGO_ENABLED=$CGO_ENABLED go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME$EXT" ../ CGO_ENABLED=$CGO_ENABLED go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME$EXT" ../

Loading…
Cancel
Save