Skip to content

Commit

Permalink
fix: update examples/...
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulYakow committed May 2, 2024
1 parent 94ca4b6 commit de0e649
Show file tree
Hide file tree
Showing 24 changed files with 47 additions and 28 deletions.
1 change: 1 addition & 0 deletions examples/basic/database_sql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
)

//nolint:gomnd
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
1 change: 1 addition & 0 deletions examples/basic/gorm/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gomnd
package main

import (
Expand Down
5 changes: 3 additions & 2 deletions examples/basic/native/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

environ "github.com/ydb-platform/ydb-go-sdk-auth-environ"
ydb "github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
)

Expand All @@ -19,6 +19,7 @@ func isYdbVersionHaveQueryService() error {
for i, component := range ydbVersion {
if i < len(minYdbVersion) {
if r := strings.Compare(component, minYdbVersion[i]); r < 0 {
//nolint:goerr113
return fmt.Errorf("example '%s' run on minimal YDB version '%v', but current version is '%s'",
os.Args[0],
strings.Join(minYdbVersion, "."),
Expand Down Expand Up @@ -46,7 +47,7 @@ func main() {
return
}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) //nolint:gomnd
defer cancel()

dsn, exists := os.LookupEnv("YDB_CONNECTION_STRING")
Expand Down
1 change: 1 addition & 0 deletions examples/basic/native/table/data.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gomnd
package main

import (
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/native/table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) //nolint:gomnd
defer cancel()

dsn, exists := os.LookupEnv("YDB_CONNECTION_STRING")
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/native/table/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func scanQuerySelect(ctx context.Context, c table.Client, prefix string) error {
table.ValueParam("$series",
types.ListValue(
types.Uint64Value(1),
types.Uint64Value(10),
types.Uint64Value(10), //nolint:gomnd
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/xorm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SQLITE_CONNECTION_STRING
YDB_CONNECTION_STRING`

func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) //nolint:gomnd
defer cancel()

var (
Expand Down
4 changes: 2 additions & 2 deletions examples/coordination/lock/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func main() {

err = db.Coordination().CreateNode(ctx, path, coordination.NodeConfig{
Path: "",
SelfCheckPeriodMillis: 1000,
SessionGracePeriodMillis: 1000,
SelfCheckPeriodMillis: 1000, //nolint:gomnd
SessionGracePeriodMillis: 1000, //nolint:gomnd
ReadConsistencyMode: coordination.ConsistencyModeStrict,
AttachConsistencyMode: coordination.ConsistencyModeStrict,
RatelimiterCountersMode: coordination.RatelimiterCountersModeDetailed,
Expand Down
8 changes: 4 additions & 4 deletions examples/coordination/workers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func init() {
"semaphore prefix",
)
flagSet.IntVar(&taskCount,
"tasks", 10,
"tasks", 10, //nolint:gomnd
"the number of tasks",
)
flagSet.IntVar(&capacity,
"capacity", 4,
"capacity", 4, //nolint:gomnd
"the maximum number of tasks a worker can run",
)
if err := flagSet.Parse(os.Args[1:]); err != nil {
Expand Down Expand Up @@ -88,8 +88,8 @@ func main() {

err = db.Coordination().CreateNode(ctx, path, coordination.NodeConfig{
Path: "",
SelfCheckPeriodMillis: 1000,
SessionGracePeriodMillis: 1000,
SelfCheckPeriodMillis: 1000, //nolint:gomnd
SessionGracePeriodMillis: 1000, //nolint:gomnd
ReadConsistencyMode: coordination.ConsistencyModeStrict,
AttachConsistencyMode: coordination.ConsistencyModeStrict,
RatelimiterCountersMode: coordination.RatelimiterCountersModeDetailed,
Expand Down
1 change: 1 addition & 0 deletions examples/decimal/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gomnd
package main

import (
Expand Down
1 change: 1 addition & 0 deletions examples/pagination/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func schoolData(city string, num uint32, addr string) types.Value {
)
}

//nolint:gomnd
func getSchoolData() types.Value {
return types.ListValue(
schoolData("Орлов", 1, "Ст.Халтурина, 2"),
Expand Down
3 changes: 2 additions & 1 deletion examples/read_table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path"

environ "github.com/ydb-platform/ydb-go-sdk-auth-environ"
ydb "github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)
Expand Down Expand Up @@ -54,6 +54,7 @@ func init() { //nolint:gochecknoinits
}
}

//nolint:gomnd
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
3 changes: 2 additions & 1 deletion examples/read_table/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type templateConfig struct {
TablePathPrefix string
}

//nolint:gomnd
func fillTable(ctx context.Context, c table.Client, prefix string) (err error) {
return c.Do(ctx,
func(ctx context.Context, s table.Session) (err error) {
Expand Down Expand Up @@ -151,7 +152,7 @@ func readTable(ctx context.Context, c table.Client, path string, opts ...options
r := row{}
for res.NextResultSet(ctx) {
for res.NextRow() {
if res.CurrentResultSet().ColumnCount() == 4 {
if res.CurrentResultSet().ColumnCount() == 4 { //nolint:gomnd
err = res.ScanNamed(
named.OptionalWithDefault("customer_id", &r.id),
named.OptionalWithDefault("order_id", &r.orderID),
Expand Down
2 changes: 1 addition & 1 deletion examples/serverless/healthcheck/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service
InsecureSkipVerify: true, //nolint:gosec
},
},
Timeout: time.Second * 10,
Timeout: time.Second * 10, //nolint:gomnd
},
}
s.db, err = ydb.Open(ctx, dsn, opts...)
Expand Down
1 change: 1 addition & 0 deletions examples/serverless/url_shortener/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
logLevel string
)

//nolint:gomnd
func init() { //nolint:gochecknoinits
required := []string{"ydb"}
flagSet := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
Expand Down
9 changes: 5 additions & 4 deletions examples/serverless/url_shortener/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
environ "github.com/ydb-platform/ydb-go-sdk-auth-environ"
ydbMetrics "github.com/ydb-platform/ydb-go-sdk-prometheus/v2"
ydb "github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
"github.com/ydb-platform/ydb-go-sdk/v3/table/result"
Expand Down Expand Up @@ -83,6 +83,7 @@ type service struct {

var once sync.Once

//nolint:gomnd
func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service, err error) {
once.Do(func() {
var (
Expand Down Expand Up @@ -306,7 +307,7 @@ func (s *service) selectLong(ctx context.Context, hash string) (url string, err
}
}

return "", fmt.Errorf("hash '%s' is not found", hash)
return "", fmt.Errorf("hash '%s' is not found", hash) //nolint:goerr113
}

func writeResponse(w http.ResponseWriter, statusCode int, body string) {
Expand Down Expand Up @@ -390,7 +391,7 @@ func (s *service) handleShorten(w http.ResponseWriter, r *http.Request) {
return
}
if !isLongCorrect(string(url)) {
err = fmt.Errorf("'%s' is not a valid URL", url)
err = fmt.Errorf("'%s' is not a valid URL", url) //nolint:goerr113
writeResponse(w, http.StatusBadRequest, err.Error())

return
Expand Down Expand Up @@ -428,7 +429,7 @@ func (s *service) handleLonger(w http.ResponseWriter, r *http.Request) {
}()
path := strings.Split(r.URL.Path, "/")
if !isShortCorrect(path[len(path)-1]) {
err = fmt.Errorf("'%s' is not a valid short path", path[len(path)-1])
err = fmt.Errorf("'%s' is not a valid short path", path[len(path)-1]) //nolint:goerr113
writeResponse(w, http.StatusBadRequest, err.Error())

return
Expand Down
2 changes: 1 addition & 1 deletion examples/topic/cdc-cache-bus-freeseats/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func createCosumers(ctx context.Context, db *ydb.Driver, consumersCount int) err
}

func connect() *ydb.Driver {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) //nolint:gomnd
defer cancel()

connectionString := os.Getenv("YDB_CONNECTION_STRING")
Expand Down
1 change: 1 addition & 0 deletions examples/topic/cdc-cache-bus-freeseats/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

const defaultConnectionString = "grpc://localhost:2136/local"

//nolint:gomnd
var (
host = flag.String("listen-host", "localhost", "host/ip for start listener")
port = flag.Int("port", 3619, "port to listen")
Expand Down
7 changes: 5 additions & 2 deletions examples/topic/cdc-cache-bus-freeseats/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)

var errNotEnthoughtFreeSeats = errors.New("not enough free seats")
var (
errNotEnthoughtFreeSeats = errors.New("not enough free seats")
errNotFound = errors.New("not found")
)

type server struct {
cache *Cache
Expand Down Expand Up @@ -133,7 +136,7 @@ SELECT freeSeats FROM bus WHERE id=$id;
if !res.NextRow() {
freeSeats = 0

return 0, errors.New("not found")
return 0, errNotFound
}

err = res.ScanWithDefaults(&freeSeats)
Expand Down
4 changes: 2 additions & 2 deletions examples/topic/cdc-fill-and-read/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

environ "github.com/ydb-platform/ydb-go-sdk-auth-environ"
ydb "github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions"
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes"
)
Expand Down Expand Up @@ -49,7 +49,7 @@ func main() {

go fillTable(ctx, db.Table(), prefix, tableName)
go func() {
time.Sleep(interval / 2)
time.Sleep(interval / 2) //nolint:gomnd
removeFromTable(ctx, db.Table(), prefix, tableName)
}()

Expand Down
4 changes: 2 additions & 2 deletions examples/topic/cdc-fill-and-read/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"time"

ydb "github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
Expand Down Expand Up @@ -86,7 +86,7 @@ VALUES
`, prefix, tableName)
for {
id := uint64(rand.Intn(maxID)) //nolint:gosec
val := "val-" + strconv.Itoa(rand.Intn(10)) //nolint:gosec
val := "val-" + strconv.Itoa(rand.Intn(10)) //nolint:gosec,gomnd
params := table.NewQueryParameters(
table.ValueParam("$id", types.Uint64Value(id)),
table.ValueParam("$value", types.UTF8Value(val)),
Expand Down
5 changes: 4 additions & 1 deletion examples/topic/topicreader/topicreader_advanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicreader"
)

var errBadDataLen = errors.New("bad data len")

// ReadMessagesWithCustomBatching example of custom of readed message batch
func ReadMessagesWithCustomBatching(ctx context.Context, db *ydb.Driver) {
reader, _ := db.Topic().StartReader("consumer", nil)
Expand All @@ -30,8 +32,9 @@ type MyMessage struct {

// UnmarshalYDBTopicMessage implements topicreader.MessageContentUnmarshaler interface
func (m *MyMessage) UnmarshalYDBTopicMessage(data []byte) error {
//nolint:gomnd
if len(data) != 6 {
return errors.New("bad data len")
return errBadDataLen
}
m.ID = data[0]
m.ChangeType = data[1]
Expand Down
3 changes: 2 additions & 1 deletion examples/ttl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"

environ "github.com/ydb-platform/ydb-go-sdk-auth-environ"
ydb "github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
)

Expand Down Expand Up @@ -52,6 +52,7 @@ func init() { //nolint:gochecknoinits
}
}

//nolint:gomnd
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
3 changes: 2 additions & 1 deletion examples/ttl_readtable/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"

environ "github.com/ydb-platform/ydb-go-sdk-auth-environ"
ydb "github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
)

Expand Down Expand Up @@ -52,6 +52,7 @@ func init() { //nolint:gochecknoinits
}
}

//nolint:gomnd
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down

0 comments on commit de0e649

Please sign in to comment.