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
run: |
bash script/build.sh -s -P -p "windows,linux,darwin"
bash script/build.sh -s -p "windows,linux,darwin"
- name: Upload artifact
uses: actions/upload-artifact@v4

@ -28,7 +28,7 @@ jobs:
- name: Build
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"
with:

@ -22,7 +22,7 @@ jobs:
- name: Build
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"
with:

@ -11,7 +11,7 @@ WORKDIR /synctv
COPY ./ ./
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

@ -9,17 +9,17 @@ import (
)
type Consul struct {
ServerName string `json:"serverName"`
Token string `json:"token"`
PathPrefix string `json:"pathPrefix"`
Namespace string `json:"namespace"`
Partition string `json:"partition"`
ServiceName string `json:"serviceName"`
Token string `json:"token"`
PathPrefix string `json:"pathPrefix"`
Namespace string `json:"namespace"`
Partition string `json:"partition"`
}
type Etcd struct {
ServerName string `json:"serverName"`
Username string `json:"username"`
Password string `json:"password"`
ServiceName string `json:"serviceName"`
Username string `json:"username"`
Password string `json:"password"`
}
type Backend struct {
@ -38,7 +38,7 @@ func (b *Backend) Validate() error {
if b.Endpoint == "" {
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")
}
if b.TimeOut != "" {

@ -488,7 +488,7 @@ func NewGrpcClientConn(ctx context.Context, conf *model.Backend) (*grpc.ClientCo
if conf.Endpoint == "" {
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")
}
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))
}
if conf.Consul.ServerName != "" {
if conf.Consul.ServiceName != "" {
c := api.DefaultConfig()
c.Address = conf.Endpoint
c.Token = conf.Consul.Token
@ -529,12 +529,12 @@ func NewGrpcClientConn(ctx context.Context, conf *model.Backend) (*grpc.ClientCo
if err != nil {
return nil, err
}
endpoint := fmt.Sprintf("discovery:///%s", conf.Consul.ServerName)
endpoint := fmt.Sprintf("discovery:///%s", conf.Consul.ServiceName)
dis := consul.New(client)
opts = append(opts, ggrpc.WithEndpoint(endpoint), ggrpc.WithDiscovery(dis))
log.Infof("new grpc client with consul: %s", conf.Endpoint)
} else if conf.Etcd.ServerName != "" {
endpoint := fmt.Sprintf("discovery:///%s", conf.Etcd.ServerName)
} else if conf.Etcd.ServiceName != "" {
endpoint := fmt.Sprintf("discovery:///%s", conf.Etcd.ServiceName)
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{conf.Endpoint},
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.Address = conf.Endpoint
c.Token = conf.Consul.Token
@ -644,12 +644,12 @@ func NewHttpClientConn(ctx context.Context, conf *model.Backend) (*http.Client,
if err != nil {
return nil, err
}
endpoint := fmt.Sprintf("discovery:///%s", conf.Consul.ServerName)
endpoint := fmt.Sprintf("discovery:///%s", conf.Consul.ServiceName)
dis := consul.New(client)
opts = append(opts, http.WithEndpoint(endpoint), http.WithDiscovery(dis))
log.Infof("new http client with consul: %s", conf.Endpoint)
} else if conf.Etcd.ServerName != "" {
endpoint := fmt.Sprintf("discovery:///%s", conf.Etcd.ServerName)
} else if conf.Etcd.ServiceName != "" {
endpoint := fmt.Sprintf("discovery:///%s", conf.Etcd.ServiceName)
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{conf.Endpoint},
Username: conf.Etcd.Username,

@ -13,7 +13,7 @@ function ChToScriptFileDir() {
function EnvHelp() {
echo "SKIP_INIT_WEB"
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() {
@ -24,7 +24,7 @@ function Help() {
echo "-m set build mode (default: pie)"
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 trim path (default: disable)"
echo "-P set disable trim path (default: disable)"
echo "-d set build result dir (default: build)"
echo "-T set tags (default: jsoniter)"
echo "Env Help:"
@ -74,7 +74,7 @@ function ParseArgs() {
PLATFORM="$OPTARG"
;;
P)
TRIM_PATH="true"
DISABLE_TRIM_PATH="true"
;;
d)
BUILD_DIR="$OPTARG"
@ -179,7 +179,7 @@ function Build() {
else
EXT=""
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" ../
else
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=""
fi
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" ../
else
CGO_ENABLED=$CGO_ENABLED go build -tags "$TAGS" -ldflags "$LDFLAGS" -o "$BUILD_DIR/$BIN_NAME$EXT" ../

Loading…
Cancel
Save