Skip to content

Commit

Permalink
*: apply some lint (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Sep 19, 2022
1 parent a922101 commit ea3cd6f
Show file tree
Hide file tree
Showing 27 changed files with 169 additions and 221 deletions.
82 changes: 0 additions & 82 deletions .github/workflows/build.yml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: make
on:
workflow_call:
inputs:
debug:
type: boolean
description: "set tmate on failure"
required: true
target:
type: string
description: "makefile target"
required: true
ref:
type: string
description: "checkout specific ref"
required: true
all_platform:
type: boolean
description: "test on all platforms or not"
default: false

defaults:
run:
shell: bash

jobs:
make:
strategy:
matrix:
platform: ${{ inputs.all_platform && fromJSON('["ubuntu-latest", "macos-latest", "windows-latest"]') || fromJSON('["ubuntu-latest"]') }}
runs-on: ${{ matrix.platform }}
steps:
- if: ${{ runner.os == 'Windows' }}
name: Use GNU tar for faster cache restore
shell: cmd
run: |
echo "Adding GNU tar to PATH"
echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
- name: "checkout repo"
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: "setup golang"
uses: actions/setup-go@v3
with:
go-version-file: go.mod
check-latest: true
- name: "set vars"
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: "try to use build cache"
uses: actions/cache@v3
with:
path: |
${{ env.GOCACHE }}
${{ env.GOMODCACHE }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: make ${{ inputs.target }}
- name: "set up tmate session if necessary"
if: ${{ failure() && inputs.debug }}
uses: mxschmitt/action-tmate@v3
15 changes: 13 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@ concurrency:
cancel-in-progress: true

jobs:
cmd:
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
ref: ${{ inputs.ref || github.ref }}
target: "cmd"
all_platform: true

build:
uses: ./.github/workflows/build.yml
needs: cmd
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
ref: ${{ inputs.ref || github.ref }}
target: "build"

test:
needs: build
uses: ./.github/workflows/test.yml
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
ref: ${{ inputs.ref || github.ref }}
target: "test"
41 changes: 0 additions & 41 deletions .github/workflows/test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/tiproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {
logEncoder := rootCmd.PersistentFlags().String("log_encoder", "", "log in format of tidb, console, or json")
logLevel := rootCmd.PersistentFlags().String("log_level", "", "log level")

rootCmd.RunE = func(cmd *cobra.Command, args []string) error {
rootCmd.RunE = func(cmd *cobra.Command, _ []string) error {
proxyConfigData, err := ioutil.ReadFile(*configFile)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func GetRootCmd() *cobra.Command {
logEncoder := rootCmd.PersistentFlags().String("log_encoder", "tidb", "log in format of tidb, console, or json")
logLevel := rootCmd.PersistentFlags().String("log_level", "info", "log level")
rootCmd.PersistentFlags().Bool("indent", true, "whether indent the returned json")
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
zapcfg := zap.NewDevelopmentConfig()
zapcfg.Encoding = *logEncoder
if level, err := zap.ParseAtomicLevel(*logLevel); err == nil {
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func GetNamespaceCmd(ctx *Context) *cobra.Command {
rootCmd.AddCommand(
&cobra.Command{
Use: "list",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
resp, err := doRequest(cmd.Context(), ctx, http.MethodGet, namespacePrefix, nil)
if err != nil {
return err
Expand Down Expand Up @@ -132,7 +132,7 @@ func GetNamespaceCmd(ctx *Context) *cobra.Command {
Use: "put",
}
ns := putNamespace.Flags().String("ns", "-", "file")
putNamespace.RunE = func(cmd *cobra.Command, args []string) error {
putNamespace.RunE = func(cmd *cobra.Command, _ []string) error {
in := cmd.InOrStdin()
if *ns != "-" {
f, err := os.Open(*ns)
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
)

type Context struct {
CUrls []string
Logger *zap.Logger
Client *http.Client
CUrls []string
}

func doRequest(ctx context.Context, bctx *Context, method string, url string, rd io.Reader) (string, error) {
Expand Down
16 changes: 8 additions & 8 deletions lib/config/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
)

type Config struct {
Workdir string `yaml:"workdir,omitempty" toml:"workdir,omitempty" json:"workdir,omitempty"`
Proxy ProxyServer `yaml:"proxy,omitempty" toml:"proxy,omitempty" json:"proxy,omitempty"`
API API `yaml:"api,omitempty" toml:"api,omitempty" json:"api,omitempty"`
Advance Advance `yaml:"advance,omitempty" toml:"advance,omitempty" json:"advance,omitempty"`
Workdir string `yaml:"workdir,omitempty" toml:"workdir,omitempty" json:"workdir,omitempty"`
Security Security `yaml:"security,omitempty" toml:"security,omitempty" json:"security,omitempty"`
Metrics Metrics `yaml:"metrics,omitempty" toml:"metrics,omitempty" json:"metrics,omitempty"`
Log Log `yaml:"log,omitempty" toml:"log,omitempty" json:"log,omitempty"`
Security Security `yaml:"security,omitempty" toml:"security,omitempty" json:"security,omitempty"`
Advance Advance `yaml:"advance,omitempty" toml:"advance,omitempty" json:"advance,omitempty"`
}

type Metrics struct {
Expand All @@ -43,23 +43,23 @@ type ProxyServerOnline struct {
}

type ProxyServer struct {
ProxyServerOnline
Addr string `yaml:"addr,omitempty" toml:"addr,omitempty" json:"addr,omitempty"`
PDAddrs string `yaml:"pd-addrs,omitempty" toml:"pd-addrs,omitempty" json:"pd-addrs,omitempty"`
ProxyProtocol string `yaml:"proxy-protocol,omitempty" toml:"proxy-protocol,omitempty" json:"proxy-protocol,omitempty"`
ProxyServerOnline
}

type API struct {
Addr string `yaml:"addr,omitempty" toml:"addr,omitempty" json:"addr,omitempty"`
EnableBasicAuth bool `yaml:"enable-basic-auth,omitempty" toml:"enable-basic-auth,omitempty" json:"enable-basic-auth,omitempty"`
User string `yaml:"user,omitempty" toml:"user,omitempty" json:"user,omitempty"`
Password string `yaml:"password,omitempty" toml:"password,omitempty" json:"password,omitempty"`
EnableBasicAuth bool `yaml:"enable-basic-auth,omitempty" toml:"enable-basic-auth,omitempty" json:"enable-basic-auth,omitempty"`
}

type Advance struct {
PeerPort string `yaml:"peer-port,omitempty" toml:"peer-port,omitempty" json:"peer-port,omitempty"`
IgnoreWrongNamespace bool `yaml:"ignore-wrong-namespace,omitempty" toml:"ignore-wrong-namespace,omitempty" json:"ignore-wrong-namespace,omitempty"`
WatchInterval string `yaml:"watch-interval,omitempty" toml:"watch-interval,omitempty" json:"watch-interval,omitempty"`
IgnoreWrongNamespace bool `yaml:"ignore-wrong-namespace,omitempty" toml:"ignore-wrong-namespace,omitempty" json:"ignore-wrong-namespace,omitempty"`
}

type Log struct {
Expand All @@ -78,8 +78,8 @@ type LogFile struct {
type TLSConfig struct {
Cert string `yaml:"cert,omitempty" toml:"cert,omitempty" json:"cert,omitempty"`
Key string `yaml:"key,omitempty" toml:"key,omitempty" json:"key,omitempty"`
AutoCerts bool `yaml:"auto-certs,omitempty" toml:"auto-certs,omitempty" json:"auto-certs,omitempty"`
CA string `yaml:"ca,omitempty" toml:"ca,omitempty" json:"ca,omitempty"`
AutoCerts bool `yaml:"auto-certs,omitempty" toml:"auto-certs,omitempty" json:"auto-certs,omitempty"`
SkipCA bool `yaml:"skip-ca,omitempty" toml:"skip-ca,omitempty" json:"skip-ca,omitempty"`
}

Expand All @@ -92,11 +92,11 @@ func (c TLSConfig) HasCA() bool {
}

type Security struct {
RSAKeySize int `yaml:"rsa-key-size,omitempty" toml:"rsa-key-size,omitempty" json:"rsa-key-size,omitempty"`
ServerTLS TLSConfig `yaml:"server-tls,omitempty" toml:"server-tls,omitempty" json:"server-tls,omitempty"`
PeerTLS TLSConfig `yaml:"peer-tls,omitempty" toml:"peer-tls,omitempty" json:"peer-tls,omitempty"`
ClusterTLS TLSConfig `yaml:"cluster-tls,omitempty" toml:"cluster-tls,omitempty" json:"cluster-tls,omitempty"`
SQLTLS TLSConfig `yaml:"sql-tls,omitempty" toml:"sql-tls,omitempty" json:"sql-tls,omitempty"`
RSAKeySize int `yaml:"rsa-key-size,omitempty" toml:"rsa-key-size,omitempty" json:"rsa-key-size,omitempty"`
}

func NewConfig(data []byte) (*Config, error) {
Expand Down
6 changes: 3 additions & 3 deletions lib/util/cmd/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ var (
)

type tidbEncoder struct {
line *buffer.Buffer
zapcore.EncoderConfig
openNamespaces int
line *buffer.Buffer
}

func NewTiDBEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder {
Expand All @@ -42,11 +42,11 @@ func NewTiDBEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder {
if cfg.LineEnding == "" {
cfg.LineEnding = zapcore.DefaultLineEnding
}
return &tidbEncoder{cfg, 0, _pool.Get()}
return &tidbEncoder{_pool.Get(), cfg, 0}
}

func (c tidbEncoder) clone() *tidbEncoder {
return &tidbEncoder{c.EncoderConfig, 0, _pool.Get()}
return &tidbEncoder{_pool.Get(), c.EncoderConfig, 0}
}

func (c tidbEncoder) Clone() zapcore.Encoder {
Expand Down
2 changes: 1 addition & 1 deletion lib/util/errors/merror.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var (
)

type MError struct {
uerr []error
cerr error
uerr []error
}

func (e *MError) Format(st fmt.State, verb rune) {
Expand Down
17 changes: 7 additions & 10 deletions pkg/manager/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ var (
)

type ConfigManager struct {
wg waitgroup.WaitGroup
cancel context.CancelFunc
logger *zap.Logger
kv mvcc.WatchableKV
basePath string

// config
ignoreWrongNamespace bool
wg waitgroup.WaitGroup
kv mvcc.WatchableKV
cancel context.CancelFunc
logger *zap.Logger
chProxy chan *config.ProxyServerOnline
basePath string
watchInterval time.Duration

chProxy chan *config.ProxyServerOnline
ignoreWrongNamespace bool
}

func NewConfigManager() *ConfigManager {
Expand Down
Loading

0 comments on commit ea3cd6f

Please sign in to comment.