Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/contrib/config/consul/…
Browse files Browse the repository at this point in the history
…github.com/hashicorp/consul/api-1.20.0
  • Loading branch information
daemon365 authored Mar 23, 2023
2 parents a6e9602 + f47a238 commit 8a54822
Show file tree
Hide file tree
Showing 68 changed files with 189 additions and 158 deletions.
12 changes: 12 additions & 0 deletions .github/stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
daysUntilStale: 30
daysUntilClose: 3
exemptLabels:
- pinned
- security
- bug
staleLabel: wontfix
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
closeComment: true
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3.5.0
uses: actions/setup-go@v4.0.0
with:
go-version: ${{ matrix.go }}

Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/issue-translator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'issue-translator'
on:
issue_comment:
types: [created]
issues:
types: [opened]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: usthe/[email protected]
with:
IS_MODIFY_TITLE: true
CUSTOM_BOT_NOTE: Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions api/metadata/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *Server) load() error {
}

// ListServices return all services
func (s *Server) ListServices(ctx context.Context, in *ListServicesRequest) (*ListServicesReply, error) {
func (s *Server) ListServices(_ context.Context, _ *ListServicesRequest) (*ListServicesReply, error) {
s.lock.Lock()
defer s.lock.Unlock()
if err := s.load(); err != nil {
Expand All @@ -122,7 +122,7 @@ func (s *Server) ListServices(ctx context.Context, in *ListServicesRequest) (*Li
}

// GetServiceDesc return service meta by name
func (s *Server) GetServiceDesc(ctx context.Context, in *GetServiceDescRequest) (*GetServiceDescReply, error) {
func (s *Server) GetServiceDesc(_ context.Context, in *GetServiceDescRequest) (*GetServiceDescReply, error) {
s.lock.Lock()
defer s.lock.Unlock()
if err := s.load(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type mockRegistry struct {
service map[string]*registry.ServiceInstance
}

func (r *mockRegistry) Register(ctx context.Context, service *registry.ServiceInstance) error {
func (r *mockRegistry) Register(_ context.Context, service *registry.ServiceInstance) error {
if service == nil || service.ID == "" {
return errors.New("no service id")
}
Expand All @@ -30,7 +30,7 @@ func (r *mockRegistry) Register(ctx context.Context, service *registry.ServiceIn
}

// Deregister the registration.
func (r *mockRegistry) Deregister(ctx context.Context, service *registry.ServiceInstance) error {
func (r *mockRegistry) Deregister(_ context.Context, service *registry.ServiceInstance) error {
r.lk.Lock()
defer r.lk.Unlock()
if r.service[service.ID] == nil {
Expand Down
14 changes: 6 additions & 8 deletions cmd/kratos/internal/base/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func kratosHomeWithDir(dir string) string {
}

func copyFile(src, dst string, replaces []string) error {
var err error
srcinfo, err := os.Stat(src)
if err != nil {
return err
Expand All @@ -58,19 +57,18 @@ func copyFile(src, dst string, replaces []string) error {
}

func copyDir(src, dst string, replaces, ignores []string) error {
var err error
var fds []os.DirEntry
var srcinfo os.FileInfo

if srcinfo, err = os.Stat(src); err != nil {
srcinfo, err := os.Stat(src)
if err != nil {
return err
}

if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil {
err = os.MkdirAll(dst, srcinfo.Mode())
if err != nil {
return err
}

if fds, err = os.ReadDir(src); err != nil {
fds, err := os.ReadDir(src)
if err != nil {
return err
}
for _, fd := range fds {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/base/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *Repo) Pull(ctx context.Context) error {
cmd.Dir = r.Path()
_, err := cmd.CombinedOutput()
if err != nil {
return nil
return err
}
cmd = exec.CommandContext(ctx, "git", "pull")
cmd.Dir = r.Path()
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/change/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
token = os.Getenv("GITHUB_TOKEN")
}

func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
owner, repo := ParseGithubURL(repoURL)
api := GithubAPI{Owner: owner, Repo: repo, Token: token}
version := "latest"
Expand Down
6 changes: 3 additions & 3 deletions cmd/kratos/internal/project/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os"
"path"

"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"

"github.com/AlecAivazis/survey/v2"
"github.com/fatih/color"

"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)

// Project is a project template.
Expand All @@ -23,11 +23,11 @@ func (p *Project) New(ctx context.Context, dir string, layout string, branch str
to := path.Join(dir, p.Name)
if _, err := os.Stat(to); !os.IsNotExist(err) {
fmt.Printf("🚫 %s already exists\n", p.Name)
override := false
prompt := &survey.Confirm{
Message: "📂 Do you want to override the folder ?",
Help: "Delete the existing folder and create the project.",
}
var override bool
e := survey.AskOne(prompt, &override)
if e != nil {
return e
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
CmdNew.Flags().BoolVarP(&nomod, "nomod", "", nomod, "retain go mod")
}

func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
wd, err := os.Getwd()
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/proto/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var CmdAdd = &cobra.Command{
Run: run,
}

func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("Please enter the proto file or directory")
return
Expand Down
6 changes: 3 additions & 3 deletions cmd/kratos/internal/proto/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"regexp"
"strings"

"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"

"github.com/spf13/cobra"

"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)

// CmdClient represents the source command.
Expand All @@ -30,7 +30,7 @@ func init() {
CmdClient.Flags().StringVarP(&protoPath, "proto_path", "p", protoPath, "proto path")
}

func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("Please enter the proto file or directory")
return
Expand Down
4 changes: 2 additions & 2 deletions cmd/kratos/internal/proto/proto.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package proto

import (
"github.com/spf13/cobra"

"github.com/go-kratos/kratos/cmd/kratos/v2/internal/proto/add"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/proto/client"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/proto/server"

"github.com/spf13/cobra"
)

// CmdProto represents the proto command.
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/proto/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
CmdServer.Flags().StringVarP(&targetDir, "target-dir", "t", "internal/service", "generate target directory")
}

func run(cmd *cobra.Command, args []string) {
func run(_ *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "Please specify the proto file. Example: kratos proto server api/xxx.proto")
return
Expand Down
15 changes: 14 additions & 1 deletion cmd/kratos/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ var CmdRun = &cobra.Command{
Long: "Run project. Example: kratos run",
Run: Run,
}
var targetDir string

func init() {
CmdRun.Flags().StringVarP(&targetDir, "work", "w", "", "target working directory")
}

// Run run project.
func Run(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -64,10 +69,11 @@ func Run(cmd *cobra.Command, args []string) {
dir = cmdPath[dir]
}
}
fd := exec.Command("go", append([]string{"run", "."}, programArgs...)...)
fd := exec.Command("go", append([]string{"run", dir}, programArgs...)...)
fd.Stdout = os.Stdout
fd.Stderr = os.Stderr
fd.Dir = dir
changeWorkingDirectory(fd, targetDir)
if err := fd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "\033[31mERROR: %s\033[m\n", err.Error())
return
Expand Down Expand Up @@ -131,3 +137,10 @@ func findCMD(base string) (map[string]string, error) {
}
return map[string]string{"": base}, nil
}

func changeWorkingDirectory(cmd *exec.Cmd, targetDir string) {
targetDir = strings.TrimSpace(targetDir)
if targetDir != "" {
cmd.Dir = targetDir
}
}
6 changes: 3 additions & 3 deletions cmd/kratos/internal/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package upgrade
import (
"fmt"

"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"

"github.com/spf13/cobra"

"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
)

// CmdUpgrade represents the upgrade command.
Expand All @@ -17,7 +17,7 @@ var CmdUpgrade = &cobra.Command{
}

// Run upgrade the kratos tools.
func Run(cmd *cobra.Command, args []string) {
func Run(_ *cobra.Command, _ []string) {
err := base.GoInstall(
"github.com/go-kratos/kratos/cmd/kratos/v2@latest",
"github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest",
Expand Down
4 changes: 2 additions & 2 deletions cmd/kratos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package main
import (
"log"

"github.com/spf13/cobra"

"github.com/go-kratos/kratos/cmd/kratos/v2/internal/change"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/project"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/proto"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/run"
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/upgrade"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go-errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
}
}

func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool {
func genErrorsReason(_ *protogen.Plugin, _ *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool {
defaultCode := proto.GetExtension(enum.Desc.Options(), errors.E_DefaultCode)
code := 0
if ok := defaultCode.(int32); ok != 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go-http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
}
}

func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, omitempty bool) {
func genService(_ *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, omitempty bool) {
if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {
g.P("//")
g.P(deprecationComment)
Expand Down
2 changes: 1 addition & 1 deletion config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func WithResolver(r Resolver) Option {

// WithLogger with config logger.
// Deprecated: use global logger instead.
func WithLogger(l log.Logger) Option {
func WithLogger(_ log.Logger) Option {
return func(o *options) {}
}

Expand Down
19 changes: 9 additions & 10 deletions contrib/config/apollo/apollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/apolloconfig/agollo/v4"
"github.com/apolloconfig/agollo/v4/constant"
apolloConfig "github.com/apolloconfig/agollo/v4/env/config"
apolloconfig "github.com/apolloconfig/agollo/v4/env/config"
"github.com/apolloconfig/agollo/v4/extension"

"github.com/go-kratos/kratos/v2/config"
Expand Down Expand Up @@ -112,8 +112,8 @@ func NewSource(opts ...Option) config.Source {
for _, o := range opts {
o(&op)
}
client, err := agollo.StartWithConfig(func() (*apolloConfig.AppConfig, error) {
return &apolloConfig.AppConfig{
client, err := agollo.StartWithConfig(func() (*apolloconfig.AppConfig, error) {
return &apolloconfig.AppConfig{
AppID: op.appid,
Cluster: op.cluster,
NamespaceName: op.namespace,
Expand Down Expand Up @@ -166,14 +166,13 @@ func (e *apollo) load() []*config.KeyValue {
}
kvs = append(kvs, kv)
continue
} else {
kv, err := e.getConfig(ns)
if err != nil {
log.Errorf("apollo get config failed,err:%v", err)
continue
}
kvs = append(kvs, kv)
}
kv, err := e.getConfig(ns)
if err != nil {
log.Errorf("apollo get config failed,err:%v", err)
continue
}
kvs = append(kvs, kv)
}
return kvs
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/config/apollo/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *customChangeListener) OnChange(changeEvent *storage.ChangeEvent) {
c.in <- change
}

func (c *customChangeListener) OnNewestChange(changeEvent *storage.FullChangeEvent) {}
func (c *customChangeListener) OnNewestChange(_ *storage.FullChangeEvent) {}

func newWatcher(a *apollo) (config.Watcher, error) {
changeCh := make(chan []*config.KeyValue)
Expand Down
2 changes: 1 addition & 1 deletion contrib/config/consul/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type watcher struct {
cancel context.CancelFunc
}

func (w *watcher) handle(idx uint64, data interface{}) {
func (w *watcher) handle(_ uint64, data interface{}) {
if data == nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions contrib/config/kubernetes/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.16

require (
github.com/go-kratos/kratos/v2 v2.4.0
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
k8s.io/api v0.26.3
k8s.io/apimachinery v0.26.3
k8s.io/client-go v0.26.3
)

replace github.com/go-kratos/kratos/v2 => ../../../
Loading

0 comments on commit 8a54822

Please sign in to comment.