Skip to content
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
41 changes: 24 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ on:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
go: ["1.21.x", "1.22.x", "1.23.x"]
go: ["1.26.x", "1.25.x"]
arch: ["amd64", "386"]

env:
GOARCH: "${{matrix.arch}}"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- uses: WillAbides/setup-go-faster@v1.7.0
- uses: WillAbides/setup-go-faster@v1
with:
go-version: ${{matrix.go}}

Expand All @@ -31,24 +31,31 @@ jobs:
run: ./test.sh

staticcheck:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: dominikh/staticcheck-action@v1.3.1
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: "2024.1.1"
install-go: false
version: v2.12

code-coverage:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7

- name: install goveralls
run: go install github.com/mattn/goveralls@latest
- uses: actions/setup-go@v7
with:
go-version: stable

- name: generate coverage
run: go test -covermode=count -coverprofile=coverage.out ./...

- name: send coverage
env:
COVERALLS_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: ./coverage.sh --coveralls
uses: coverallsapp/github-action@v2
with:
file: coverage.out
format: golang
4 changes: 1 addition & 3 deletions apps/nsq_tail/nsq_tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/nsqio/go-nsq"
"github.com/nsqio/nsq/internal/app"
Expand Down Expand Up @@ -71,7 +70,7 @@ func (th *TailHandler) HandleMessage(m *nsq.Message) error {
func main() {
cfg := nsq.NewConfig()

flag.Var(&nsq.ConfigFlag{cfg}, "consumer-opt", "option to passthrough to nsq.Consumer (may be given multiple times, http://godoc.org/github.com/nsqio/go-nsq#Config)")
flag.Var(&nsq.ConfigFlag{Config: cfg}, "consumer-opt", "option to passthrough to nsq.Consumer (may be given multiple times, http://godoc.org/github.com/nsqio/go-nsq#Config)")
flag.Parse()

if *showVersion {
Expand All @@ -80,7 +79,6 @@ func main() {
}

if *channel == "" {
rand.Seed(time.Now().UnixNano())
*channel = fmt.Sprintf("tail%06d#ephemeral", rand.Int()%999999)
}
Comment thread
jehiah marked this conversation as resolved.

Expand Down
18 changes: 9 additions & 9 deletions apps/nsq_to_file/file_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (f *FileLogger) Close() {

for i := f.rev + 1; ; i++ {
f.logf(lg.WARN, "[%s/%s] destination file already exists: %s", f.topic, f.opts.Channel, dst)
dst := strings.Replace(dstTmpl, "<REV>", fmt.Sprintf("-%06d", i), -1)
dst := strings.ReplaceAll(dstTmpl, "<REV>", fmt.Sprintf("-%06d", i))
err := exclusiveRename(src, dst)
if err != nil {
if os.IsExist(err) {
Expand Down Expand Up @@ -251,7 +251,7 @@ func (f *FileLogger) Sync() error {
func (f *FileLogger) currentFilename() string {
t := time.Now()
datetime := strftime(f.opts.DatetimeFormat, t)
return strings.Replace(f.filenameFormat, "<DATETIME>", datetime, -1)
return strings.ReplaceAll(f.filenameFormat, "<DATETIME>", datetime)
}

func (f *FileLogger) needsRotation() bool {
Expand Down Expand Up @@ -302,7 +302,7 @@ func (f *FileLogger) updateFile() {

var fi os.FileInfo
for ; ; f.rev++ {
absFilename := strings.Replace(fullPath, "<REV>", fmt.Sprintf("-%06d", f.rev), -1)
absFilename := strings.ReplaceAll(fullPath, "<REV>", fmt.Sprintf("-%06d", f.rev))

// If we're using a working directory for in-progress files,
// proactively check for duplicate file names in the output dir to
Expand Down Expand Up @@ -397,8 +397,8 @@ func computeFilenameFormat(opts *Options, topic string) (string, error) {

identifier := shortHostname
if len(opts.HostIdentifier) != 0 {
identifier = strings.Replace(opts.HostIdentifier, "<SHORT_HOST>", shortHostname, -1)
identifier = strings.Replace(identifier, "<HOSTNAME>", hostname, -1)
identifier = strings.ReplaceAll(opts.HostIdentifier, "<SHORT_HOST>", shortHostname)
identifier = strings.ReplaceAll(identifier, "<HOSTNAME>", hostname)
}

cff := opts.FilenameFormat
Expand All @@ -408,11 +408,11 @@ func computeFilenameFormat(opts *Options, topic string) (string, error) {
}
} else {
// remove <REV> as we don't need it
cff = strings.Replace(cff, "<REV>", "", -1)
cff = strings.ReplaceAll(cff, "<REV>", "")
}
cff = strings.Replace(cff, "<TOPIC>", topic, -1)
cff = strings.Replace(cff, "<HOST>", identifier, -1)
cff = strings.Replace(cff, "<PID>", fmt.Sprintf("%d", os.Getpid()), -1)
cff = strings.ReplaceAll(cff, "<TOPIC>", topic)
cff = strings.ReplaceAll(cff, "<HOST>", identifier)
cff = strings.ReplaceAll(cff, "<PID>", fmt.Sprintf("%d", os.Getpid()))
if opts.GZIP && !strings.HasSuffix(cff, ".gz") {
cff = cff + ".gz"
}
Expand Down
10 changes: 7 additions & 3 deletions apps/nsq_to_file/nsq_to_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func flagSet() *flag.FlagSet {

func main() {
fs := flagSet()
fs.Parse(os.Args[1:])
if err := fs.Parse(os.Args[1:]); err != nil {
log.Fatal(err)
}

if args := fs.Args(); len(args) > 0 {
log.Fatalf("unknown arguments: %s", args)
Expand Down Expand Up @@ -119,9 +121,11 @@ func main() {
}

cfg := nsq.NewConfig()
cfgFlag := nsq.ConfigFlag{cfg}
cfgFlag := nsq.ConfigFlag{Config: cfg}
for _, opt := range opts.ConsumerOpts {
cfgFlag.Set(opt)
if err := cfgFlag.Set(opt); err != nil {
log.Fatal(err)
}
}
cfg.UserAgent = fmt.Sprintf("nsq_to_file/%s go-nsq/%s", version.Binary, nsq.VERSION)
cfg.MaxInFlight = opts.MaxInFlight
Expand Down
20 changes: 15 additions & 5 deletions apps/nsq_to_http/nsq_to_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ func (p *PostPublisher) Publish(addr string, msg []byte) error {
if err != nil {
return err
}
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
_ = resp.Body.Close()
return err
}
if err := resp.Body.Close(); err != nil {
return err
}

if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("got status code %d", resp.StatusCode)
Expand All @@ -146,8 +151,13 @@ func (p *GetPublisher) Publish(addr string, msg []byte) error {
if err != nil {
return err
}
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
_ = resp.Body.Close()
return err
}
if err := resp.Body.Close(); err != nil {
return err
}

if resp.StatusCode != 200 {
return fmt.Errorf("got status code %d", resp.StatusCode)
Expand All @@ -162,7 +172,7 @@ func main() {

cfg := nsq.NewConfig()

flag.Var(&nsq.ConfigFlag{cfg}, "consumer-opt", "option to passthrough to nsq.Consumer (may be given multiple times, http://godoc.org/github.com/nsqio/go-nsq#Config)")
flag.Var(&nsq.ConfigFlag{Config: cfg}, "consumer-opt", "option to passthrough to nsq.Consumer (may be given multiple times, http://godoc.org/github.com/nsqio/go-nsq#Config)")
flag.Parse()

httpclient = &http.Client{Transport: http_api.NewDeadlineTransport(*httpConnectTimeout, *httpRequestTimeout), Timeout: *httpRequestTimeout}
Expand Down
4 changes: 2 additions & 2 deletions apps/nsq_to_nsq/nsq_to_nsq.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ func main() {
cCfg := nsq.NewConfig()
pCfg := nsq.NewConfig()

flag.Var(&nsq.ConfigFlag{cCfg}, "consumer-opt", "option to passthrough to nsq.Consumer (may be given multiple times, see http://godoc.org/github.com/nsqio/go-nsq#Config)")
flag.Var(&nsq.ConfigFlag{pCfg}, "producer-opt", "option to passthrough to nsq.Producer (may be given multiple times, see http://godoc.org/github.com/nsqio/go-nsq#Config)")
flag.Var(&nsq.ConfigFlag{Config: cCfg}, "consumer-opt", "option to passthrough to nsq.Consumer (may be given multiple times, see http://godoc.org/github.com/nsqio/go-nsq#Config)")
flag.Var(&nsq.ConfigFlag{Config: pCfg}, "producer-opt", "option to passthrough to nsq.Producer (may be given multiple times, see http://godoc.org/github.com/nsqio/go-nsq#Config)")

flag.Parse()

Expand Down
8 changes: 6 additions & 2 deletions apps/nsqadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func (p *program) Start() error {
opts := nsqadmin.NewOptions()

flagSet := nsqadminFlagSet(opts)
flagSet.Parse(os.Args[1:])
if err := flagSet.Parse(os.Args[1:]); err != nil {
return err
}

if flagSet.Lookup("version").Value.(flag.Getter).Get().(bool) {
fmt.Println(version.String("nsqadmin"))
Expand All @@ -114,7 +116,9 @@ func (p *program) Start() error {
go func() {
err := p.nsqadmin.Main()
if err != nil {
p.Stop()
if stopErr := p.Stop(); stopErr != nil {
logFatal("failed to stop nsqadmin - %s", stopErr)
}
os.Exit(1)
}
}()
Expand Down
5 changes: 4 additions & 1 deletion apps/nsqadmin/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ func TestConfigFlagParsing(t *testing.T) {
opts.Logger = test.NewTestLogger(t)

flagSet := nsqadminFlagSet(opts)
flagSet.Parse([]string{})
err := flagSet.Parse([]string{})
if err != nil {
t.Fatalf("%s", err)
}

cfg := config{"log_level": "debug"}
cfg.Validate()
Expand Down
12 changes: 6 additions & 6 deletions apps/nsqd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"context"
"flag"
"fmt"
"math/rand"
"os"
"sync"
"syscall"
"time"

"github.com/BurntSushi/toml"
"github.com/judwhite/go-svc"
Expand All @@ -34,9 +32,9 @@ func (p *program) Init(env svc.Environment) error {
opts := nsqd.NewOptions()

flagSet := nsqdFlagSet(opts)
flagSet.Parse(os.Args[1:])

rand.Seed(time.Now().UTC().UnixNano())
if err := flagSet.Parse(os.Args[1:]); err != nil {
return err
}

if flagSet.Lookup("version").Value.(flag.Getter).Get().(bool) {
fmt.Println(version.String("nsqd"))
Expand Down Expand Up @@ -78,7 +76,9 @@ func (p *program) Start() error {
go func() {
err := p.nsqd.Main()
if err != nil {
p.Stop()
if stopErr := p.Stop(); stopErr != nil {
logFatal("failed to stop nsqd - %s", stopErr)
}
os.Exit(1)
}
}()
Expand Down
21 changes: 17 additions & 4 deletions apps/nsqd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,33 @@ func TestConfigFlagParsing(t *testing.T) {
opts.Logger = test.NewTestLogger(t)

flagSet := nsqdFlagSet(opts)
flagSet.Parse([]string{})
err := flagSet.Parse([]string{})
if err != nil {
t.Fatalf("%s", err)
}

var cfg config
f, err := os.Open("../../contrib/nsqd.cfg.example")
if err != nil {
t.Fatalf("%s", err)
}
defer f.Close()
toml.NewDecoder(f).Decode(&cfg)
defer func() {
if err := f.Close(); err != nil {
t.Fatalf("%s", err)
}
}()
_, err = toml.NewDecoder(f).Decode(&cfg)
if err != nil {
t.Fatalf("%s", err)
}
cfg["log_level"] = "debug"
cfg.Validate()

options.Resolve(opts, flagSet, cfg)
nsqd.New(opts)
_, err = nsqd.New(opts)
if err != nil {
t.Fatalf("%s", err)
}

if opts.TLSMinVersion != tls.VersionTLS10 {
t.Errorf("min %#v not expected %#v", opts.TLSMinVersion, tls.VersionTLS10)
Expand Down
8 changes: 6 additions & 2 deletions apps/nsqlookupd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func (p *program) Start() error {
opts := nsqlookupd.NewOptions()

flagSet := nsqlookupdFlagSet(opts)
flagSet.Parse(os.Args[1:])
if err := flagSet.Parse(os.Args[1:]); err != nil {
return err
}

if flagSet.Lookup("version").Value.(flag.Getter).Get().(bool) {
fmt.Println(version.String("nsqlookupd"))
Expand All @@ -88,7 +90,9 @@ func (p *program) Start() error {
go func() {
err := p.nsqlookupd.Main()
if err != nil {
p.Stop()
if stopErr := p.Stop(); stopErr != nil {
logFatal("failed to stop nsqlookupd - %s", stopErr)
}
os.Exit(1)
}
}()
Expand Down
5 changes: 4 additions & 1 deletion apps/nsqlookupd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ func TestConfigFlagParsing(t *testing.T) {
opts.Logger = test.NewTestLogger(t)

flagSet := nsqlookupdFlagSet(opts)
flagSet.Parse([]string{})
err := flagSet.Parse([]string{})
if err != nil {
t.Fatalf("%s", err)
}

cfg := config{"log_level": "debug"}
cfg.Validate()
Expand Down
2 changes: 1 addition & 1 deletion apps/to_nsq/to_nsq.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {

func main() {
cfg := nsq.NewConfig()
flag.Var(&nsq.ConfigFlag{cfg}, "producer-opt", "option to passthrough to nsq.Producer (may be given multiple times, http://godoc.org/github.com/nsqio/go-nsq#Config)")
flag.Var(&nsq.ConfigFlag{Config: cfg}, "producer-opt", "option to passthrough to nsq.Producer (may be given multiple times, http://godoc.org/github.com/nsqio/go-nsq#Config)")
rate := flag.Int64("rate", 0, "Throttle messages to n/second. 0 to disable")

flag.Parse()
Expand Down
Loading