Skip to content

Commit

Permalink
zstrings.Split2() → strings.Cut(), ioutil → os
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Nov 17, 2022
1 parent 6e4ff79 commit f497462
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cmd/goatcounter/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func doServe(ctx context.Context, db zdb.DB,
if i > 0 {
fmt.Fprint(zli.Stdout, ", ")
}
fmt.Fprintf(zli.Stdout, "%s (%s)", t.Task, time.Now().Sub(t.Started).Round(time.Second))
fmt.Fprintf(zli.Stdout, "%s (%s)", t.Task, time.Since(t.Started).Round(time.Second))
}
}

Expand Down Expand Up @@ -350,8 +350,8 @@ func flagsServe(f zli.Flags, v *zvalidate.Validator) (string, string, bool, bool

if *ratelimit != "" {
for _, r := range strings.Split(*ratelimit, ",") {
name, spec := zstring.Split2(r, ":")
reqs, secs := zstring.Split2(spec, "/")
name, spec, _ := strings.Cut(r, ":")
reqs, secs, _ := strings.Cut(spec, "/")

v := zvalidate.New()
v.Required("name", name)
Expand Down
4 changes: 2 additions & 2 deletions locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"context"
"io"
"net"
"strings"

"github.com/oschwald/geoip2-golang"
"zgo.at/errors"
"zgo.at/zdb"
"zgo.at/zlog"
"zgo.at/zstd/zstring"
)

var geodb *geoip2.Reader
Expand Down Expand Up @@ -74,7 +74,7 @@ func (l *Location) ByCode(ctx context.Context, code string) error {
err := zdb.Get(ctx, l, `select * from locations where iso_3166_2 = $1`, code)
if zdb.ErrNoRows(err) {
l.ISO3166_2 = code
l.Country, l.Region = zstring.Split2(code, "-")
l.Country, l.Region, _ = strings.Cut(code, "-")
l.CountryName, l.RegionName = findGeoName(l.Country, l.Region)
err = l.insert(ctx)
}
Expand Down
3 changes: 1 addition & 2 deletions logscan/logscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"zgo.at/errors"
"zgo.at/follow"
"zgo.at/zlog"
"zgo.at/zstd/zstring"
)

var reFormat = regexp.MustCompile(`\\\$[\w-_]+`)
Expand Down Expand Up @@ -148,7 +147,7 @@ func processExcludes(exclude []string) ([]excludePattern, error) {
e = e[1:]
}

p.field, p.pattern = zstring.Split2(e, ":")
p.field, p.pattern, _ = strings.Cut(e, ":")
if !slices.Contains(fields, p.field) {
return nil, fmt.Errorf("invalid field %q in exclude pattern %q", p.field, e)
}
Expand Down
3 changes: 1 addition & 2 deletions logscan/logscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package logscan
import (
"context"
"io"
"io/ioutil"
"os"
"os/exec"
"reflect"
Expand All @@ -31,7 +30,7 @@ func TestErrors(t *testing.T) {
}

func TestNew(t *testing.T) {
files, err := ioutil.ReadDir("./testdata")
files, err := os.ReadDir("./testdata")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"zgo.at/zlog"
"zgo.at/zstd/zbool"
"zgo.at/zstd/zcrypto"
"zgo.at/zstd/zstring"
"zgo.at/zstd/ztime"
"zgo.at/zstd/ztype"
)
Expand Down Expand Up @@ -314,7 +313,7 @@ func (u *User) Find(ctx context.Context, ident string) error {
return errors.Wrap(u.ByID(ctx, id), "User.Find")
}

s, email := zstring.Split2(ident, ",")
s, email, _ := strings.Cut(ident, ",")

var site Site
err = site.Find(ctx, s)
Expand Down

0 comments on commit f497462

Please sign in to comment.