Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows cmdutil #83

Merged
merged 4 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ linters-settings:
# 2. you use go >= 1.10
# 3. you do repeated runs (false for CI) or cache $GOPATH/pkg or `go env GOCACHE` dir in CI.
use-installed-packages: false
golint:
revive:
jdknives marked this conversation as resolved.
Show resolved Hide resolved
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gofmt:
Expand Down Expand Up @@ -139,7 +139,7 @@ linters-settings:

linters:
enable:
- golint
- revive
- goimports
- varcheck
- unparam
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ matrix:

install:
- go get -u github.com/FiloSottile/vendorcheck
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.31.0
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.40.1
- go mod vendor

script:
Expand Down
4 changes: 2 additions & 2 deletions cmd/dmsg-discovery/internal/store/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func (ms *MockStore) AvailableServers(ctx context.Context, maxCount int) ([]*dis

// CountEntries implements Storer CountEntries method for MockStore
func (ms *MockStore) CountEntries(ctx context.Context) (int64, int64, error) {
var numberOfServers int64 = 0
var numberOfClients int64 = 0
var numberOfServers int64
var numberOfClients int64
ms.serversLock.RLock()
defer ms.serversLock.RUnlock()

Expand Down
32 changes: 1 addition & 31 deletions cmdutil/service_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import (
"fmt"
"io"
"io/ioutil"
"log/syslog"
"os"
"strings"
"unicode"

jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -132,14 +129,7 @@ func (sf *ServiceFlags) Logger() *logging.Logger {
logging.SetLevel(logLvl)

if sf.Syslog != "" {
hook, err := logrussyslog.NewSyslogHook(sf.SyslogNet, sf.Syslog, sysLvl, sf.Tag)
if err != nil {
log.WithError(err).
WithField("net", sf.SyslogNet).
WithField("addr", sf.Syslog).
Fatal("Failed to connect to syslog daemon.")
}
logging.AddHook(hook)
sf.sysLogHook(log, sysLvl)
}

return log
Expand Down Expand Up @@ -239,26 +229,6 @@ func ValidTag(tag string) error {
return nil
}

// LevelFromString returns a logrus.Level and syslog.Priority from a string identifier.
func LevelFromString(s string) (logrus.Level, syslog.Priority, error) {
switch strings.ToLower(s) {
case "debug":
return logrus.DebugLevel, syslog.LOG_DEBUG, nil
case "info", "notice":
return logrus.InfoLevel, syslog.LOG_INFO, nil
case "warn", "warning":
return logrus.WarnLevel, syslog.LOG_WARNING, nil
case "error":
return logrus.ErrorLevel, syslog.LOG_ERR, nil
case "fatal", "critical":
return logrus.FatalLevel, syslog.LOG_CRIT, nil
case "panic":
return logrus.PanicLevel, syslog.LOG_EMERG, nil
default:
return logrus.DebugLevel, syslog.LOG_DEBUG, ErrInvalidLogString
}
}

func alreadyDone(done *bool) bool {
if *done {
return true
Expand Down
4 changes: 2 additions & 2 deletions cmdutil/signal_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"os"
"os/signal"
"syscall"

"github.com/sirupsen/logrus"
)
Expand All @@ -18,7 +17,8 @@ func SignalContext(ctx context.Context, log logrus.FieldLogger) (context.Context
ctx, cancel := context.WithCancel(ctx)

ch := make(chan os.Signal)
signal.Notify(ch, []os.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT}...)
listenSigs := listenSignals()
signal.Notify(ch, listenSigs...)

go func() {
select {
Expand Down
13 changes: 13 additions & 0 deletions cmdutil/signal_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !windows

package cmdutil

import (
"os"

"golang.org/x/sys/unix"
)

func listenSignals() []os.Signal {
return []os.Signal{unix.SIGINT, unix.SIGTERM, unix.SIGQUIT}
}
13 changes: 13 additions & 0 deletions cmdutil/signal_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build windows

package cmdutil

import (
"os"

"golang.org/x/sys/windows"
)

func listenSignals() []os.Signal {
return []os.Signal{windows.SIGINT, windows.SIGTERM, windows.SIGQUIT}
}
43 changes: 43 additions & 0 deletions cmdutil/sysloghook_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// +build !windows

package cmdutil

import (
"log/syslog"
"strings"

"github.com/sirupsen/logrus"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/skycoin/src/util/logging"
)

func (sf *ServiceFlags) sysLogHook(log *logging.Logger, sysLvl int) {
hook, err := logrussyslog.NewSyslogHook(sf.SyslogNet, sf.Syslog, syslog.Priority(sysLvl), sf.Tag)
if err != nil {
log.WithError(err).
WithField("net", sf.SyslogNet).
WithField("addr", sf.Syslog).
Fatal("Failed to connect to syslog daemon.")
}
logging.AddHook(hook)
}

// LevelFromString returns a logrus.Level and syslog.Priority from a string identifier.
func LevelFromString(s string) (logrus.Level, int, error) {
switch strings.ToLower(s) {
case "debug":
return logrus.DebugLevel, int(syslog.LOG_DEBUG), nil
case "info", "notice":
return logrus.InfoLevel, int(syslog.LOG_INFO), nil
case "warn", "warning":
return logrus.WarnLevel, int(syslog.LOG_WARNING), nil
case "error":
return logrus.ErrorLevel, int(syslog.LOG_ERR), nil
case "fatal", "critical":
return logrus.FatalLevel, int(syslog.LOG_CRIT), nil
case "panic":
return logrus.PanicLevel, int(syslog.LOG_EMERG), nil
default:
return logrus.DebugLevel, int(syslog.LOG_DEBUG), ErrInvalidLogString
}
}
33 changes: 33 additions & 0 deletions cmdutil/sysloghook_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// +build windows

package cmdutil

import (
"strings"

"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"
)

func (sf *ServiceFlags) sysLogHook(_ *logging.Logger, _ int) {
}

// LevelFromString returns a logrus.Level and syslog.Priority from a string identifier.
func LevelFromString(s string) (logrus.Level, int, error) {
switch strings.ToLower(s) {
case "debug":
return logrus.DebugLevel, 0, nil
case "info", "notice":
return logrus.InfoLevel, 0, nil
case "warn", "warning":
return logrus.WarnLevel, 0, nil
case "error":
return logrus.ErrorLevel, 0, nil
case "fatal", "critical":
return logrus.FatalLevel, 0, nil
case "panic":
return logrus.PanicLevel, 0, nil
default:
return logrus.DebugLevel, 0, ErrInvalidLogString
}
}
9 changes: 5 additions & 4 deletions vendor/github.com/creack/pty/ioctl_solaris.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions vendor/github.com/creack/pty/pty_solaris.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/creack/pty/util_solaris.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/creack/pty/ztypes_openbsd_386.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/json-iterator/go/any.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/json-iterator/go/reflect_array.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/json-iterator/go/reflect_dynamic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/json-iterator/go/reflect_extension.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/json-iterator/go/reflect_json_number.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/github.com/json-iterator/go/reflect_map.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading