Refecter: cmd
This commit is contained in:
parent
9a86322741
commit
a546e12f9b
|
@ -0,0 +1,38 @@
|
|||
name: build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
platform: [ubuntu-latest]
|
||||
go-version: ["1.21"]
|
||||
name: Build
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
make build-all
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: vendors
|
||||
path: build
|
|
@ -0,0 +1,40 @@
|
|||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
release:
|
||||
strategy:
|
||||
matrix:
|
||||
platform: [ubuntu-latest]
|
||||
go-version: ["1.21"]
|
||||
name: Release
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Get version
|
||||
id: get_version
|
||||
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
bash script/build.sh -v "v${{ steps.get_version.outputs.VERSION }}" -p "windows,linux,darwin"
|
||||
|
||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
||||
with:
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
automatic_release_tag: "v${{ steps.get_version.outputs.VERSION }}"
|
||||
title: "Version ${{ steps.get_version.outputs.VERSION }}"
|
||||
prerelease: ${{ contains(steps.get_version.outputs.VERSION, 'rc') || contains(steps.get_version.outputs.VERSION, 'beta') || contains(steps.get_version.outputs.VERSION, 'alpha') }}
|
||||
files: |
|
||||
build/*
|
|
@ -0,0 +1,34 @@
|
|||
name: release_dev
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release_dev:
|
||||
strategy:
|
||||
matrix:
|
||||
platform: [ubuntu-latest]
|
||||
go-version: ["1.21"]
|
||||
name: Release
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
bash script/build.sh -v dev -p "windows,linux,darwin"
|
||||
|
||||
- uses: "marvinpinto/action-automatic-releases@latest"
|
||||
with:
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
automatic_release_tag: "dev"
|
||||
title: "Dev Build"
|
||||
prerelease: true
|
||||
files: |
|
||||
build/*
|
|
@ -0,0 +1,51 @@
|
|||
name: release_docker
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
release_docker:
|
||||
name: Release Docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: synctvorg/synctv
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Get version
|
||||
id: get_version
|
||||
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
build-args:
|
||||
VERSION=v${{ steps.get_version.outputs.VERSION }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64
|
|
@ -30,13 +30,13 @@ Thumbs.db
|
|||
*.cert
|
||||
*.key
|
||||
*.log
|
||||
bin/
|
||||
build/
|
||||
|
||||
# Develop tools
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
|
||||
/configs
|
||||
config.yaml
|
||||
|
||||
*_init_test.go
|
||||
|
|
34
Dockerfile
34
Dockerfile
|
@ -1,24 +1,30 @@
|
|||
FROM golang:1.18 AS builder
|
||||
From alpine:latest as builder
|
||||
|
||||
COPY . /src
|
||||
WORKDIR /src
|
||||
WORKDIR /vendors
|
||||
|
||||
COPY ./ ./
|
||||
|
||||
RUN apk add --no-cache bash curl gcc git go musl-dev
|
||||
|
||||
RUN make build
|
||||
|
||||
FROM debian:stable-slim
|
||||
From alpine:latest
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
netbase &&
|
||||
rm -rf /var/lib/apt/lists/ &&
|
||||
apt-get autoremove -y && apt-get autoclean -y
|
||||
ENV PUID=0 PGID=0 UMASK=022
|
||||
|
||||
COPY --from=builder /src/bin /app
|
||||
COPY --from=builder /vendors/bin/vendors /usr/local/bin/vendors
|
||||
|
||||
WORKDIR /app
|
||||
COPY script/entrypoint.sh /entrypoint.sh
|
||||
|
||||
RUN apk add --no-cache bash ca-certificates su-exec tzdata && \
|
||||
rm -rf /var/cache/apk/* && \
|
||||
chmod +x /entrypoint.sh && \
|
||||
mkdir -p /vendors
|
||||
|
||||
WORKDIR /vendors
|
||||
|
||||
EXPOSE 8000
|
||||
EXPOSE 9000
|
||||
VOLUME /data/conf
|
||||
|
||||
CMD ["./server", "-conf", "/data/conf"]
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
||||
|
||||
CMD [ "server" ]
|
31
Makefile
31
Makefile
|
@ -1,6 +1,5 @@
|
|||
GOHOSTOS:=$(shell go env GOHOSTOS)
|
||||
GOPATH:=$(shell go env GOPATH)
|
||||
VERSION=$(shell git describe --tags --always)
|
||||
|
||||
ifeq ($(GOHOSTOS), windows)
|
||||
#the `find.exe` is different from `find` in bash/shell.
|
||||
|
@ -20,6 +19,7 @@ endif
|
|||
init:
|
||||
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||
go install github.com/favadi/protoc-go-inject-tag@latest
|
||||
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
|
||||
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
|
||||
go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
|
||||
|
@ -32,6 +32,7 @@ config:
|
|||
--proto_path=./third_party \
|
||||
--go_out=paths=source_relative:./conf \
|
||||
$(CONFIG_PROTO_FILES)
|
||||
protoc-go-inject-tag -input=./conf/*.pb.go
|
||||
|
||||
.PHONY: api
|
||||
# generate api proto
|
||||
|
@ -47,7 +48,33 @@ api:
|
|||
.PHONY: build
|
||||
# build
|
||||
build:
|
||||
mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
|
||||
bash script/build.sh
|
||||
|
||||
.PHONY: build-all
|
||||
# build all
|
||||
build-all:
|
||||
bash script/build.sh -p all
|
||||
|
||||
.PHONY: build-darwin
|
||||
# build darwin
|
||||
build-darwin:
|
||||
bash script/build.sh -p darwin
|
||||
|
||||
.PHONY: build-linux
|
||||
# build linux
|
||||
build-linux:
|
||||
bash script/build.sh -p linux
|
||||
|
||||
.PHONY: build-windows
|
||||
# build windows
|
||||
build-windows:
|
||||
bash script/build.sh -p windows
|
||||
|
||||
.PHONY: run
|
||||
# run
|
||||
run:
|
||||
make build
|
||||
./build/vendors server
|
||||
|
||||
.PHONY: generate
|
||||
# generate
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
# Vendors
|
||||
|
||||
## Bilibili
|
||||
## Run
|
||||
```bash
|
||||
make init
|
||||
make build
|
||||
./build/vendors server
|
||||
```
|
|
@ -1,91 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/synctv-org/vendors/conf"
|
||||
"github.com/synctv-org/vendors/utils"
|
||||
|
||||
"github.com/go-kratos/kratos/v2"
|
||||
"github.com/go-kratos/kratos/v2/config"
|
||||
"github.com/go-kratos/kratos/v2/config/file"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/go-kratos/kratos/v2/middleware/tracing"
|
||||
"github.com/go-kratos/kratos/v2/registry"
|
||||
|
||||
_ "go.uber.org/automaxprocs"
|
||||
)
|
||||
|
||||
// go build -ldflags "-X main.Version=x.y.z"
|
||||
var (
|
||||
// Name is the name of the compiled software.
|
||||
Name string
|
||||
// Version is the version of the compiled software.
|
||||
Version string
|
||||
// flagconf is the config flag.
|
||||
flagconf string
|
||||
|
||||
id, _ = os.Hostname()
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml")
|
||||
flag.StringVar(&Name, "name", "", "server name")
|
||||
}
|
||||
|
||||
func newApp(logger log.Logger, s *utils.GrpcGatewayServer, r registry.Registrar) *kratos.App {
|
||||
es, err := s.Endpoints()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return kratos.New(
|
||||
kratos.ID(id),
|
||||
kratos.Name(Name),
|
||||
kratos.Version(Version),
|
||||
kratos.Metadata(map[string]string{}),
|
||||
kratos.Logger(logger),
|
||||
kratos.Server(
|
||||
s,
|
||||
),
|
||||
kratos.Registrar(r),
|
||||
kratos.Endpoint(es...),
|
||||
)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
logger := log.With(log.NewStdLogger(os.Stdout),
|
||||
"ts", log.DefaultTimestamp,
|
||||
"caller", log.DefaultCaller,
|
||||
"service.id", id,
|
||||
"service.name", Name,
|
||||
"service.version", Version,
|
||||
"trace.id", tracing.TraceID(),
|
||||
"span.id", tracing.SpanID(),
|
||||
)
|
||||
c := config.New(
|
||||
config.WithSource(
|
||||
file.NewSource(flagconf),
|
||||
),
|
||||
)
|
||||
defer c.Close()
|
||||
|
||||
if err := c.Load(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var bc conf.AlistServer
|
||||
if err := c.Scan(&bc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
app, cleanup, err := wireApp(bc.Alist.Server, bc.Alist.Registry, bc.Alist.Config, logger)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
if err := app.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
//go:build wireinject
|
||||
// +build wireinject
|
||||
|
||||
// The build tag makes sure the stub is not built in the final build.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/synctv-org/vendors/conf"
|
||||
reg "github.com/synctv-org/vendors/internal/registry"
|
||||
server "github.com/synctv-org/vendors/internal/server/alist"
|
||||
"github.com/synctv-org/vendors/service/alist"
|
||||
|
||||
"github.com/go-kratos/kratos/v2"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
func wireApp(*conf.Server, *conf.Registry, *conf.AlistConfig, log.Logger) (*kratos.App, func(), error) {
|
||||
panic(wire.Build(server.ProviderSet, alist.ProviderSet, reg.ProviderSet, newApp))
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate go run github.com/google/wire/cmd/wire
|
||||
//go:build !wireinject
|
||||
// +build !wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/go-kratos/kratos/v2"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/synctv-org/vendors/conf"
|
||||
"github.com/synctv-org/vendors/internal/registry"
|
||||
"github.com/synctv-org/vendors/internal/server/alist"
|
||||
"github.com/synctv-org/vendors/service/alist"
|
||||
)
|
||||
|
||||
import (
|
||||
_ "go.uber.org/automaxprocs"
|
||||
)
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func wireApp(confServer *conf.Server, confRegistry *conf.Registry, alistConfig *conf.AlistConfig, logger log.Logger) (*kratos.App, func(), error) {
|
||||
alistService := alist.NewAlistService(alistConfig)
|
||||
grpcGatewayServer := server.NewGRPCServer(confServer, alistService)
|
||||
registrar := registry.NewRegistry(confRegistry)
|
||||
app := newApp(logger, grpcGatewayServer, registrar)
|
||||
return app, func() {
|
||||
}, nil
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/synctv-org/vendors/conf"
|
||||
"github.com/synctv-org/vendors/utils"
|
||||
|
||||
"github.com/go-kratos/kratos/v2"
|
||||
"github.com/go-kratos/kratos/v2/config"
|
||||
"github.com/go-kratos/kratos/v2/config/file"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/go-kratos/kratos/v2/middleware/tracing"
|
||||
"github.com/go-kratos/kratos/v2/registry"
|
||||
"github.com/go-kratos/kratos/v2/transport"
|
||||
"github.com/go-kratos/kratos/v2/transport/http"
|
||||
|
||||
_ "go.uber.org/automaxprocs"
|
||||
)
|
||||
|
||||
// go build -ldflags "-X main.Version=x.y.z"
|
||||
var (
|
||||
// Name is the name of the compiled software.
|
||||
Name string
|
||||
// Version is the version of the compiled software.
|
||||
Version string
|
||||
// flagconf is the config flag.
|
||||
flagconf string
|
||||
|
||||
id, _ = os.Hostname()
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml")
|
||||
flag.StringVar(&Name, "name", "", "server name")
|
||||
}
|
||||
|
||||
func newApp(logger log.Logger, gs *utils.GrpcGatewayServer, hs *http.Server, r registry.Registrar) *kratos.App {
|
||||
s := make([]transport.Server, 0, 2)
|
||||
if gs != nil {
|
||||
s = append(s, gs)
|
||||
}
|
||||
if hs != nil {
|
||||
s = append(s, hs)
|
||||
}
|
||||
es := make([]*url.URL, 0, 2)
|
||||
if gs != nil {
|
||||
ges, err := gs.Endpoints()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
es = append(es, ges...)
|
||||
}
|
||||
if hs != nil {
|
||||
he, err := hs.Endpoint()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
es = append(es, he)
|
||||
}
|
||||
return kratos.New(
|
||||
kratos.ID(id),
|
||||
kratos.Name(Name),
|
||||
kratos.Version(Version),
|
||||
kratos.Metadata(map[string]string{}),
|
||||
kratos.Logger(logger),
|
||||
kratos.Server(
|
||||
s...,
|
||||
),
|
||||
kratos.Registrar(r),
|
||||
kratos.Endpoint(es...),
|
||||
)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
logger := log.With(log.NewStdLogger(os.Stdout),
|
||||
"ts", log.DefaultTimestamp,
|
||||
"caller", log.DefaultCaller,
|
||||
"service.id", id,
|
||||
"service.name", Name,
|
||||
"service.version", Version,
|
||||
"trace.id", tracing.TraceID(),
|
||||
"span.id", tracing.SpanID(),
|
||||
)
|
||||
c := config.New(
|
||||
config.WithSource(
|
||||
file.NewSource(flagconf),
|
||||
),
|
||||
)
|
||||
defer c.Close()
|
||||
|
||||
if err := c.Load(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var bc conf.BilibiliServer
|
||||
if err := c.Scan(&bc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
app, cleanup, err := wireApp(bc.Bilibili.Server, bc.Bilibili.Registry, bc.Bilibili.Config, logger)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
if err := app.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
//go:build wireinject
|
||||
// +build wireinject
|
||||
|
||||
// The build tag makes sure the stub is not built in the final build.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/synctv-org/vendors/conf"
|
||||
reg "github.com/synctv-org/vendors/internal/registry"
|
||||
server "github.com/synctv-org/vendors/internal/server/bilibili"
|
||||
"github.com/synctv-org/vendors/service/bilibili"
|
||||
|
||||
"github.com/go-kratos/kratos/v2"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
func wireApp(*conf.Server, *conf.Registry, *conf.BilibiliConfig, log.Logger) (*kratos.App, func(), error) {
|
||||
panic(wire.Build(server.ProviderSet, bilibili.ProviderSet, reg.ProviderSet, newApp))
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate go run github.com/google/wire/cmd/wire
|
||||
//go:build !wireinject
|
||||
// +build !wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/go-kratos/kratos/v2"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/synctv-org/vendors/conf"
|
||||
"github.com/synctv-org/vendors/internal/registry"
|
||||
"github.com/synctv-org/vendors/internal/server/bilibili"
|
||||
"github.com/synctv-org/vendors/service/bilibili"
|
||||
)
|
||||
|
||||
import (
|
||||
_ "go.uber.org/automaxprocs"
|
||||
)
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func wireApp(confServer *conf.Server, confRegistry *conf.Registry, bilibiliConfig *conf.BilibiliConfig, logger log.Logger) (*kratos.App, func(), error) {
|
||||
bilibiliService := bilibili.NewBilibiliService(bilibiliConfig)
|
||||
grpcGatewayServer := server.NewGRPCServer(confServer, bilibiliService)
|
||||
httpServer := server.NewHTTPServer(confServer, bilibiliService, logger)
|
||||
registrar := registry.NewRegistry(confRegistry)
|
||||
app := newApp(logger, grpcGatewayServer, httpServer, registrar)
|
||||
return app, func() {
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package flags
|
||||
|
||||
var (
|
||||
Version string
|
||||
GitCommit string
|
||||
)
|
|
@ -0,0 +1,26 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/synctv-org/vendors/cmd/server"
|
||||
)
|
||||
|
||||
var RootCmd = &cobra.Command{
|
||||
Use: "vendors",
|
||||
Short: "synctv vendors",
|
||||
Long: `synctv https://github.com/synctv-org/vendors`,
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
if err := RootCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(server.ServerCmd)
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/synctv-org/vendors/cmd/flags"
|
||||
"github.com/synctv-org/vendors/conf"
|
||||
"github.com/synctv-org/vendors/utils"
|
||||
|
||||
"github.com/caarlos0/env/v9"
|
||||
"github.com/go-kratos/kratos/v2"
|
||||
"github.com/go-kratos/kratos/v2/config"
|
||||
"github.com/go-kratos/kratos/v2/config/file"
|
||||
|
@ -17,23 +19,12 @@ import (
|
|||
_ "go.uber.org/automaxprocs"
|
||||
)
|
||||
|
||||
// go build -ldflags "-X main.Version=x.y.z"
|
||||
var (
|
||||
// Name is the name of the compiled software.
|
||||
Name string
|
||||
// Version is the version of the compiled software.
|
||||
Version string
|
||||
// flagconf is the config flag.
|
||||
flagconf string
|
||||
|
||||
id, _ = os.Hostname()
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml")
|
||||
flag.StringVar(&Name, "name", "", "server name")
|
||||
}
|
||||
|
||||
func newApp(logger log.Logger, s *utils.GrpcGatewayServer, r registry.Registrar) *kratos.App {
|
||||
es, err := s.Endpoints()
|
||||
if err != nil {
|
||||
|
@ -41,8 +32,8 @@ func newApp(logger log.Logger, s *utils.GrpcGatewayServer, r registry.Registrar)
|
|||
}
|
||||
return kratos.New(
|
||||
kratos.ID(id),
|
||||
kratos.Name(Name),
|
||||
kratos.Version(Version),
|
||||
kratos.Name(s.ServiceName()),
|
||||
kratos.Version(flags.Version),
|
||||
kratos.Metadata(map[string]string{}),
|
||||
kratos.Logger(logger),
|
||||
kratos.Server(
|
||||
|
@ -53,31 +44,48 @@ func newApp(logger log.Logger, s *utils.GrpcGatewayServer, r registry.Registrar)
|
|||
)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
var ServerCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Short: "Start synctv vendors server",
|
||||
Run: Server,
|
||||
}
|
||||
|
||||
func Server(cmd *cobra.Command, args []string) {
|
||||
var bc conf.AllServer = conf.AllServer{
|
||||
All: &conf.AllServer_All{
|
||||
Server: conf.DefaultServer(),
|
||||
},
|
||||
}
|
||||
|
||||
if flagconf != "" {
|
||||
c := config.New(
|
||||
config.WithSource(
|
||||
file.NewSource(flagconf),
|
||||
),
|
||||
)
|
||||
defer c.Close()
|
||||
|
||||
if err := c.Load(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := c.Scan(&bc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := env.Parse(bc.All); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
logger := log.With(log.NewStdLogger(os.Stdout),
|
||||
"ts", log.DefaultTimestamp,
|
||||
"caller", log.DefaultCaller,
|
||||
"service.id", id,
|
||||
"service.name", Name,
|
||||
"service.version", Version,
|
||||
"service.name", bc.All.Server.ServiceName,
|
||||
"service.version", flags.Version,
|
||||
"trace.id", tracing.TraceID(),
|
||||
"span.id", tracing.SpanID(),
|
||||
)
|
||||
c := config.New(
|
||||
config.WithSource(
|
||||
file.NewSource(flagconf),
|
||||
),
|
||||
)
|
||||
defer c.Close()
|
||||
|
||||
if err := c.Load(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var bc conf.AllServer
|
||||
if err := c.Scan(&bc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
app, cleanup, err := wireApp(bc.All.Server, bc.All.Registry, bc.All.Alist, bc.All.Bilibili, bc.All.Emby, logger)
|
||||
if err != nil {
|
||||
|
@ -89,3 +97,7 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
ServerCmd.PersistentFlags().StringVarP(&flagconf, "conf", "c", "", "config path, eg: -c config.yaml")
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
// The build tag makes sure the stub is not built in the final build.
|
||||
|
||||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/synctv-org/vendors/conf"
|
|
@ -4,7 +4,7 @@
|
|||
//go:build !wireinject
|
||||
// +build !wireinject
|
||||
|
||||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/go-kratos/kratos/v2"
|
704
conf/conf.pb.go
704
conf/conf.pb.go
File diff suppressed because it is too large
Load Diff
|
@ -7,43 +7,49 @@ import "google/protobuf/duration.proto";
|
|||
|
||||
message Registry {
|
||||
message Consul {
|
||||
string scheme = 1;
|
||||
string addr = 2;
|
||||
string prefix = 3;
|
||||
google.protobuf.Duration timeout = 4;
|
||||
string scheme = 1; // @gotags: env:"CONSUL_SCHEME"
|
||||
string addr = 2; // @gotags: env:"CONSUL_ADDR"
|
||||
string prefix = 3; // @gotags: env:"CONSUL_PREFIX"
|
||||
google.protobuf.Duration timeout = 4; // @gotags: env:"CONSUL_TIMEOUT"
|
||||
}
|
||||
message Etcd {
|
||||
repeated string endpoints = 1;
|
||||
string username = 2;
|
||||
string password = 3;
|
||||
google.protobuf.Duration timeout = 4;
|
||||
string endpoint = 1; // @gotags: env:"ETCD_ENDPOINT"
|
||||
string username = 2; // @gotags: env:"ETCD_USERNAME"
|
||||
string password = 3; // @gotags: env:"ETCD_PASSWORD"
|
||||
google.protobuf.Duration timeout = 4; // @gotags: env:"ETCD_TIMEOUT"
|
||||
}
|
||||
Consul consul = 1;
|
||||
Etcd etcd = 2;
|
||||
}
|
||||
|
||||
message TLS {
|
||||
string cert_file = 1;
|
||||
string key_file = 2;
|
||||
string ca_file = 3;
|
||||
message Web {
|
||||
message TLS {
|
||||
string cert_file = 1; // @gotags: env:"WEB_CERT_FILE"
|
||||
string key_file = 2; // @gotags: env:"WEB_KEY_FILE"
|
||||
string ca_file = 3; // @gotags: env:"WEB_CA_FILE"
|
||||
}
|
||||
string addr = 1; // @gotags: env:"WEB_ADDR"
|
||||
TLS tls = 2;
|
||||
string custom_endpoint = 3; // @gotags: env:"WEB_CUSTOM_ENDPOINT"
|
||||
}
|
||||
|
||||
message Web {
|
||||
string addr = 1;
|
||||
TLS tls = 2;
|
||||
string custom_endpoint = 3;
|
||||
}
|
||||
message GRPC {
|
||||
string addr = 1;
|
||||
message TLS {
|
||||
string cert_file = 1; // @gotags: env:"GRPC_CERT_FILE"
|
||||
string key_file = 2; // @gotags: env:"GRPC_KEY_FILE"
|
||||
string ca_file = 3; // @gotags: env:"GRPC_CA_FILE"
|
||||
}
|
||||
string addr = 1; // @gotags: env:"GRPC_ADDR"
|
||||
TLS tls = 2;
|
||||
string custom_endpoint = 3;
|
||||
string custom_endpoint = 3; // @gotags: env:"GRPC_CUSTOM_ENDPOINT"
|
||||
}
|
||||
|
||||
message Server {
|
||||
Web web = 1;
|
||||
GRPC grpc = 2;
|
||||
google.protobuf.Duration timeout = 3;
|
||||
string jwt_secret = 4;
|
||||
google.protobuf.Duration timeout = 3; // @gotags: env:"SERVER_TIMEOUT"
|
||||
string jwt_secret = 4; // @gotags: env:"SERVER_JWT_SECRET"
|
||||
string service_name = 5; // @gotags: env:"SERVICE_NAME"
|
||||
}
|
||||
|
||||
message BilibiliConfig {}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
)
|
||||
|
||||
func DefaultServer() *Server {
|
||||
return &Server{
|
||||
Grpc: &GRPC{
|
||||
Addr: ":9000",
|
||||
},
|
||||
Web: &Web{
|
||||
Addr: ":8000",
|
||||
},
|
||||
Timeout: durationpb.New(time.Second * 15),
|
||||
}
|
||||
}
|
8
go.mod
8
go.mod
|
@ -3,6 +3,7 @@ module github.com/synctv-org/vendors
|
|||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/caarlos0/env/v9 v9.0.0
|
||||
github.com/go-kratos/kratos/contrib/registry/consul/v2 v2.0.0-20231219111544-85740b179b09
|
||||
github.com/go-kratos/kratos/contrib/registry/etcd/v2 v2.0.0-20231219111544-85740b179b09
|
||||
github.com/go-kratos/kratos/v2 v2.7.2
|
||||
|
@ -11,6 +12,7 @@ require (
|
|||
github.com/google/wire v0.5.0
|
||||
github.com/hashicorp/consul/api v1.26.1
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/zencoder/go-dash/v3 v3.0.3
|
||||
github.com/zijiren233/gencontainer v0.0.0-20231213075414-f7f4c8261dca
|
||||
go.etcd.io/etcd/client/v3 v3.5.11
|
||||
|
@ -34,7 +36,6 @@ require (
|
|||
github.com/go-playground/form/v4 v4.2.1 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/subcommands v1.0.1 // indirect
|
||||
github.com/gorilla/mux v1.8.1 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
|
@ -45,13 +46,14 @@ require (
|
|||
github.com/hashicorp/golang-lru v1.0.2 // indirect
|
||||
github.com/hashicorp/serf v0.10.1 // indirect
|
||||
github.com/imdario/mergo v0.3.16 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.11 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.11 // indirect
|
||||
go.opentelemetry.io/otel v1.21.0 // indirect
|
||||
|
@ -60,11 +62,9 @@ require (
|
|||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.26.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 // indirect
|
||||
golang.org/x/mod v0.14.0 // indirect
|
||||
golang.org/x/sync v0.5.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.16.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
|
||||
|
|
37
go.sum
37
go.sum
|
@ -13,6 +13,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
|
|||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/caarlos0/env/v9 v9.0.0 h1:SI6JNsOA+y5gj9njpgybykATIylrRMklbs5ch6wO6pc=
|
||||
github.com/caarlos0/env/v9 v9.0.0/go.mod h1:ye5mlCVMYh6tZ+vCgrs/B95sj88cg5Tlnc0XIzgZ020=
|
||||
github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g=
|
||||
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
|
@ -24,6 +26,7 @@ github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr
|
|||
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
|
@ -43,12 +46,8 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
|
|||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kratos/aegis v0.2.0 h1:dObzCDWn3XVjUkgxyBp6ZeWtx/do0DPZ7LY3yNSJLUQ=
|
||||
github.com/go-kratos/aegis v0.2.0/go.mod h1:v0R2m73WgEEYB3XYu6aE2WcMwsZkJ/Rzuf5eVccm7bI=
|
||||
github.com/go-kratos/kratos/contrib/registry/consul/v2 v2.0.0-20231209151259-7e2edecabf32 h1:srmOms19bSKzKL+Yg2FzPLSb1vFAgiYI0beN12SuBq0=
|
||||
github.com/go-kratos/kratos/contrib/registry/consul/v2 v2.0.0-20231209151259-7e2edecabf32/go.mod h1:yb9i4gq3jCW5zMFqzi50J0Xh3n4MRbcMlnuDBXYpvjs=
|
||||
github.com/go-kratos/kratos/contrib/registry/consul/v2 v2.0.0-20231219111544-85740b179b09 h1:CQLh4u2gVu4T6YqQTSw7Mg0tUAZpKpCbU9E43U9Ysew=
|
||||
github.com/go-kratos/kratos/contrib/registry/consul/v2 v2.0.0-20231219111544-85740b179b09/go.mod h1:yb9i4gq3jCW5zMFqzi50J0Xh3n4MRbcMlnuDBXYpvjs=
|
||||
github.com/go-kratos/kratos/contrib/registry/etcd/v2 v2.0.0-20231209151259-7e2edecabf32 h1:olhRzSDYrloznRpg35iYZ8p4r4uUeVpxcWvu+H447zs=
|
||||
github.com/go-kratos/kratos/contrib/registry/etcd/v2 v2.0.0-20231209151259-7e2edecabf32/go.mod h1:63nLHNM8lgbZ7u4Y+KNbWdIoPW/4gT/NBUe/VRmBs9s=
|
||||
github.com/go-kratos/kratos/contrib/registry/etcd/v2 v2.0.0-20231219111544-85740b179b09 h1:4EK4o8ZmXalxUy2lVhXWIE8+AnzBR0GaBHJXzc8NqSw=
|
||||
github.com/go-kratos/kratos/contrib/registry/etcd/v2 v2.0.0-20231219111544-85740b179b09/go.mod h1:CiTe7H5Lj8WB6dGvBwS4HFukcWnobfq+vFWedIGYftA=
|
||||
github.com/go-kratos/kratos/v2 v2.7.2 h1:WVPGFNLKpv+0odMnCPxM4ZHa2hy9I5FOnwpG3Vv4w5c=
|
||||
|
@ -56,8 +55,6 @@ github.com/go-kratos/kratos/v2 v2.7.2/go.mod h1:rppuc8+pGL2UtXA29bgFHWKqaaF6b6GB
|
|||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
|
||||
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
|
||||
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
|
@ -90,10 +87,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/subcommands v1.0.1 h1:/eqq+otEXm5vhfBrbREPCSVQbvofip6kIz+mX5TUH7k=
|
||||
github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8=
|
||||
|
@ -110,8 +104,6 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
|
|||
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
|
||||
github.com/hashicorp/go-hclog v1.6.1 h1:pa92nu9bPoAqI7p+uPDCIWGAibUdlCi6TYWJEQQkLf8=
|
||||
github.com/hashicorp/go-hclog v1.6.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||
github.com/hashicorp/go-hclog v1.6.2 h1:NOtoftovWkDheyUM/8JW3QMiXyxJK3uHRK7wV04nD2I=
|
||||
github.com/hashicorp/go-hclog v1.6.2/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
|
@ -148,6 +140,8 @@ github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY
|
|||
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
|
||||
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
|
||||
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
|
@ -224,11 +218,16 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
|
|||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
|
||||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||
|
@ -275,15 +274,11 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3
|
|||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8=
|
||||
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
|
||||
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 h1:+iq7lrkxmFNBM7xx+Rae2W6uyPfhPeDWD+n+JgppptE=
|
||||
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
|
||||
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
|
@ -353,34 +348,22 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
|
|||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
|
||||
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 h1:1hfbdAfFbkmpg41000wDVqr7jUpK/Yo+LPnIxxGzmkg=
|
||||
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3/go.mod h1:5RBcpGRxr25RbDzY5w+dmaqpSEvl8Gwl1x2CICf60ic=
|
||||
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 h1:YJ5pD9rF8o9Qtta0Cmy9rdBwkSjrTCT6XTiUQVOtIos=
|
||||
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0/go.mod h1:l/k7rMz0vFTBPy+tFSGvXEd3z+BcoG1k7EHbqm+YBsY=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3 h1:EWIeHfGuUf00zrVZGEgYFxok7plSAXBGcH7NNdMAWvA=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3/go.mod h1:k2dtGpRrbsSyKcNPKKI5sstZkrNCZwpU/ns96JoHbGg=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 h1:s1w3X6gQxwrLEpxnLd/qXTVLgQE2yXwaOaoa6IlY/+o=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0/go.mod h1:CAny0tYF+0/9rmDB9fahA9YLzX3+AEVl1qXbv5hhj6c=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3 h1:kzJAXnzZoFbe5bhZd4zjUuHos/I31yH4thfMb/13oVY=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3/go.mod h1:eJVxU6o+4G1PSczBr85xmyvSNYAKvAYgkub40YGomFM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 h1:/jFB8jK5R3Sq3i/lmeZO0cATSzFfZaJq1J2Euan3XKU=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0/go.mod h1:FUoWkonphQm3RhTS+kOEhF8h0iDpm4tdXolVCeZ9KKA=
|
||||
google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k=
|
||||
google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
|
||||
google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU=
|
||||
google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package registry
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-kratos/kratos/contrib/registry/etcd/v2"
|
||||
"github.com/go-kratos/kratos/v2/registry"
|
||||
"github.com/synctv-org/vendors/conf"
|
||||
|
@ -12,7 +14,7 @@ func newEtcd(c *conf.Registry_Etcd) registry.Registrar {
|
|||
return nil
|
||||
}
|
||||
client, err := clientv3.New(clientv3.Config{
|
||||
Endpoints: c.Endpoints,
|
||||
Endpoints: strings.Split(c.Endpoint, ","),
|
||||
Username: c.Username,
|
||||
Password: c.Password,
|
||||
DialTimeout: c.Timeout.AsDuration(),
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "github.com/synctv-org/vendors/cmd"
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
#!/bin/bash
|
||||
|
||||
BIN_NAME="vendors"
|
||||
|
||||
function ChToScriptFileDir() {
|
||||
cd "$(dirname "$0")"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "cd to script file dir error"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function EnvHelp() {
|
||||
echo "DISABLE_TRIM_PATH enable trim path (default: disable)"
|
||||
}
|
||||
|
||||
function Help() {
|
||||
echo "-h get help"
|
||||
echo "-v set build version (default: dev)"
|
||||
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 "-d set build result dir (default: build)"
|
||||
echo "-T set tags (default: jsoniter)"
|
||||
echo "Env Help:"
|
||||
EnvHelp
|
||||
}
|
||||
|
||||
function Init() {
|
||||
CGO_ENABLED=0
|
||||
VERSION="dev"
|
||||
commit="$(git log --pretty=format:"%h" -1)"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "git log error"
|
||||
GIT_COMMIT="unknown"
|
||||
else
|
||||
GIT_COMMIT="$commit"
|
||||
fi
|
||||
BUILD_MODE="pie"
|
||||
LDFLAGS='-s -w --extldflags "-static -fpic -Wl,-z,relro,-z,now"'
|
||||
PLATFORM=""
|
||||
BUILD_DIR="../build"
|
||||
TAGS="jsoniter"
|
||||
}
|
||||
|
||||
function ParseArgs() {
|
||||
while getopts "hv:w:m:l:p:Pd:T:" arg; do
|
||||
case $arg in
|
||||
h)
|
||||
Help
|
||||
exit 0
|
||||
;;
|
||||
v)
|
||||
VERSION="$(echo "$OPTARG" | sed 's/ //g' | sed 's/"//g' | sed 's/\n//g')"
|
||||
;;
|
||||
w)
|
||||
WEB_VERSION="$OPTARG"
|
||||
;;
|
||||
m)
|
||||
BUILD_MODE="$OPTARG"
|
||||
;;
|
||||
l)
|
||||
LDFLAGS="$OPTARG"
|
||||
;;
|
||||
p)
|
||||
PLATFORM="$OPTARG"
|
||||
;;
|
||||
P)
|
||||
DISABLE_TRIM_PATH="true"
|
||||
;;
|
||||
d)
|
||||
BUILD_DIR="$OPTARG"
|
||||
;;
|
||||
T)
|
||||
TAGS="$OPTARG"
|
||||
;;
|
||||
?)
|
||||
echo "unkonw argument"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Comply with golang version rules
|
||||
function CheckVersionFormat() {
|
||||
if [ "$1" == "dev" ] || [ "$(echo "$1" | grep -oE "^v?[0-9]+\.[0-9]+\.[0-9]+(\-beta.*|\-rc.*|\-alpha.*)?$")" ]; then
|
||||
return 0
|
||||
else
|
||||
echo "version format error: $1"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function FixArgs() {
|
||||
CheckAllPlatform
|
||||
CheckVersionFormat "$VERSION"
|
||||
if [ ! "$SKIP_INIT_WEB" ] && [ ! "$WEB_VERSION" ]; then
|
||||
WEB_VERSION="$VERSION"
|
||||
fi
|
||||
LDFLAGS="$LDFLAGS \
|
||||
-X 'github.com/synctv-org/vendors/cmd/flags/config.Version=$VERSION' \
|
||||
-X 'github.com/synctv-org/vendors/cmd/flags/config.GitCommit=$GIT_COMMIT'"
|
||||
|
||||
# trim / at the end
|
||||
BUILD_DIR="$(echo "$BUILD_DIR" | sed 's#/$##')"
|
||||
}
|
||||
|
||||
# sqlite3 not support linux/loong64,linux/mips linux/mips64,linux/mips64le,linux/mipsle,linux/ppc64,
|
||||
LINUX_ALLOWED_PLATFORM="linux/386,linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/riscv64,linux/s390x"
|
||||
|
||||
DARWIN_ALLOWED_PLATFORM="darwin/amd64,darwin/arm64"
|
||||
|
||||
# sqlite3 not support windows/arm,windows/386
|
||||
WINDOWS_ALLOWED_PLATFORM="windows/amd64,windows/arm64"
|
||||
|
||||
ALLOWED_PLATFORM="$LINUX_ALLOWED_PLATFORM,$DARWIN_ALLOWED_PLATFORM,$WINDOWS_ALLOWED_PLATFORM"
|
||||
|
||||
function CheckPlatform() {
|
||||
platform="$1"
|
||||
for p in $(echo "$ALLOWED_PLATFORM" | tr "," "\n"); do
|
||||
if [ "$p" == "$platform" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
function CheckAllPlatform() {
|
||||
for platform in $(echo "$PLATFORM" | tr "," "\n"); do
|
||||
if [ "$platform" == "all" ]; then
|
||||
PLATFORM="all"
|
||||
return 0
|
||||
elif [ "$platform" == "linux" ]; then
|
||||
continue
|
||||
elif [ "$platform" == "darwin" ]; then
|
||||
continue
|
||||
elif [ "$platform" == "windows" ]; then
|
||||
continue
|
||||
fi
|
||||
CheckPlatform "$platform"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "platform $platform not allowd"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function Build() {
|
||||
platform="$1"
|
||||
echo "build $platform"
|
||||
GOOS=${platform%/*}
|
||||
GOARCH=${platform#*/}
|
||||
if [ "$GOOS" == "windows" ]; then
|
||||
EXT=".exe"
|
||||
else
|
||||
EXT=""
|
||||
fi
|
||||
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" ../
|
||||
fi
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "build $GOOS/$GOARCH error"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function BuildSingle() {
|
||||
GOOS="$(go env GOOS)"
|
||||
GOARCH="$(go env GOARCH)"
|
||||
if [ "$GOOS" == "windows" ]; then
|
||||
EXT=".exe"
|
||||
else
|
||||
EXT=""
|
||||
fi
|
||||
echo "build $GOOS/$GOARCH"
|
||||
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" ../
|
||||
fi
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "build $GOOS/$GOARCH error"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function BuildAll() {
|
||||
if [ ! "$1" ]; then
|
||||
BuildSingle
|
||||
return
|
||||
else
|
||||
for platform in $(echo "$1" | tr "," "\n"); do
|
||||
if [ "$platform" == "all" ]; then
|
||||
BuildAll "$ALLOWED_PLATFORM"
|
||||
elif [ "$platform" == "linux" ]; then
|
||||
BuildAll "$LINUX_ALLOWED_PLATFORM"
|
||||
elif [ "$platform" == "darwin" ]; then
|
||||
BuildAll "$DARWIN_ALLOWED_PLATFORM"
|
||||
elif [ "$platform" == "windows" ]; then
|
||||
BuildAll "$WINDOWS_ALLOWED_PLATFORM"
|
||||
else
|
||||
Build "$platform"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
ChToScriptFileDir
|
||||
Init
|
||||
ParseArgs "$@"
|
||||
FixArgs
|
||||
BuildAll "$PLATFORM"
|
|
@ -0,0 +1,13 @@
|
|||
version: '3.3'
|
||||
services:
|
||||
vendors:
|
||||
image: 'synctvorg/vendors:latest'
|
||||
container_name: synctv-vendors
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- '9000:9000/tcp'
|
||||
environment:
|
||||
- PUID=0
|
||||
- PGID=0
|
||||
- UMASK=022
|
||||
- TZ=Asia/Shanghai
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
chown -R ${PUID}:${PGID} /synctv
|
||||
|
||||
umask ${UMASK}
|
||||
|
||||
exec su-exec ${PUID}:${PGID} vendors $@
|
|
@ -66,16 +66,10 @@ func grpcHandlerFunc(gs *ggrpc.Server, other http.Handler) http.Handler {
|
|||
}
|
||||
|
||||
type GrpcGatewayServer struct {
|
||||
gs *ggrpc.Server
|
||||
hs *ghttp.Server
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func muxGrpcGatewayServer(gs *ggrpc.Server, hs *ghttp.Server) *GrpcGatewayServer {
|
||||
return &GrpcGatewayServer{
|
||||
gs: gs,
|
||||
hs: hs,
|
||||
}
|
||||
gs *ggrpc.Server
|
||||
hs *ghttp.Server
|
||||
serviceName string
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func (s *GrpcGatewayServer) Start(ctx context.Context) error {
|
||||
|
@ -113,6 +107,10 @@ func (s *GrpcGatewayServer) Endpoints() ([]*url.URL, error) {
|
|||
return []*url.URL{ge, he}, nil
|
||||
}
|
||||
|
||||
func (s *GrpcGatewayServer) ServiceName() string {
|
||||
return s.serviceName
|
||||
}
|
||||
|
||||
func NewGrpcGatewayServer(config *conf.Server) *GrpcGatewayServer {
|
||||
middlewares := []middleware.Middleware{recovery.Recovery()}
|
||||
if config.JwtSecret != "" {
|
||||
|
@ -208,5 +206,9 @@ func NewGrpcGatewayServer(config *conf.Server) *GrpcGatewayServer {
|
|||
// }
|
||||
|
||||
gs := ggrpc.NewServer(gopts...)
|
||||
return muxGrpcGatewayServer(gs, hs)
|
||||
return &GrpcGatewayServer{
|
||||
gs: gs,
|
||||
hs: hs,
|
||||
serviceName: config.ServiceName,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue