Skip to content

Commit cce3f19

Browse files
authored
Minor documentation fixes (#341)
1 parent 20f6ae0 commit cce3f19

15 files changed

+61
-89
lines changed

.golangci.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -371,30 +371,10 @@ issues:
371371

372372
# Excluding configuration per-path, per-linter, per-text and per-source
373373
exclude-rules:
374-
# Exclude some linters from running on tests files.
375-
# - path: _test\.go
376-
# linters:
377-
# - gocyclo
378-
# - errcheck
379-
# - dupl
380-
# - gosec
381-
382-
# Exclude known linters from partially hard-vendored code,
383-
# which is impossible to exclude via "nolint" comments.
384-
# - path: internal/hmac/
385-
# text: "weak cryptographic primitive"
386-
# linters:
387-
# - gosec
388-
389-
# Exclude some staticcheck messages
390-
# - linters:
391-
# - staticcheck
392-
# text: "SA9003:"
393-
394-
# Exclude lll issues for long lines with go:generate
395-
# - linters:
396-
# - lll
397-
# source: "^//go:generate "
374+
# Exclude doc links
375+
- linters:
376+
- lll
377+
source: "^// \\[.*\\]: http"
398378

399379
# Independently from option `exclude` we use default exclude patterns,
400380
# it can be disabled by this option. To list all

client.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,16 @@ import (
2626

2727
// CreateClient returns a new client. The client connects lazily. Call
2828
// Client.EnsureConnected() to force a connection.
29-
func CreateClient(ctx context.Context, opts gelcfg.Options) (*Client, error) { // nolint:gocritic,lll
30-
return CreateClientDSN(ctx, "", opts)
29+
func CreateClient(opts gelcfg.Options) (*Client, error) { // nolint:gocritic,lll
30+
return CreateClientDSN("", opts)
3131
}
3232

3333
// CreateClientDSN returns a new client. See also CreateClient.
3434
//
35-
// dsn is either an instance name
36-
// https://www.edgedb.com/docs/clients/connection
37-
// or it specifies a single string in the following format:
35+
// dsn is either an instance name or a [DSN].
3836
//
39-
// gel://user:password@host:port/database?option=value.
40-
//
41-
// The following options are recognized: host, port, user, database, password.
42-
func CreateClientDSN(_ context.Context, dsn string, opts gelcfg.Options) (*Client, error) { // nolint:gocritic,lll
37+
// [DSN]: https://docs.geldata.com/reference/reference/dsn#ref-dsn
38+
func CreateClientDSN(dsn string, opts gelcfg.Options) (*Client, error) { // nolint:gocritic,lll
4339
pool, err := gel.NewPool(dsn, opts)
4440
if err != nil {
4541
return nil, err
@@ -71,7 +67,7 @@ func (c *Client) EnsureConnected(ctx context.Context) error {
7167
}
7268

7369
// Close closes all connections in the client.
74-
// Calling close blocks until all acquired connections have been released,
70+
// Calling Close() blocks until all acquired connections have been released,
7571
// and returns an error if called more than once.
7672
func (c *Client) Close() error { return c.pool.Close() }
7773

@@ -270,19 +266,11 @@ func (c *Client) ExecuteSQL(
270266
return gel.FirstError(err, c.pool.Release(conn, err))
271267
}
272268

273-
// Tx runs a [geltypes.TxBlock] in a transaction retrying failed attempts.
269+
// Tx runs action in a transaction retrying failed attempts.
274270
//
275-
// Retries are governed by retry rules.
276-
// The default rule can be set with WithRetryRule().
277-
// For more fine grained control a retry rule can be set
278-
// for each defined RetryCondition using WithRetryCondition().
279-
// When a transaction fails but is retryable
280-
// the rule for the failure condition is used to determine if the transaction
281-
// should be tried again based on RetryRule.Attempts and the amount of time
282-
// to wait before retrying is determined by RetryRule.Backoff.
283-
// If either field is unset (see RetryRule) then the default rule is used.
284-
// If the object's default is unset the fall back is 3 attempts
285-
// and exponential backoff.
271+
// Retries are governed by [gelcfg.RetryOptions] and [gelcfg.RetryRule].
272+
// retry options can be set using [Client.WithRetryOptions].
273+
// See [gelcfg.RetryRule] for more details on how they work.
286274
func (c *Client) Tx(ctx context.Context, action geltypes.TxBlock) error {
287275
conn, err := c.pool.Acquire(ctx)
288276
if err != nil {

client_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
func TestConnectClient(t *testing.T) {
3434
ctx := context.Background()
35-
p, err := CreateClient(ctx, opts)
35+
p, err := CreateClient(opts)
3636
require.NoError(t, err)
3737

3838
var result string
@@ -56,7 +56,7 @@ func TestConnectClient(t *testing.T) {
5656

5757
func TestClientRejectsTransaction(t *testing.T) {
5858
ctx := context.Background()
59-
p, err := CreateClient(ctx, opts)
59+
p, err := CreateClient(opts)
6060
require.NoError(t, err)
6161

6262
expected := "gel.DisabledCapabilityError: " +
@@ -87,7 +87,7 @@ func TestConnectClientZeroConcurrency(t *testing.T) {
8787
o.Concurrency = 0
8888

8989
ctx := context.Background()
90-
p, err := CreateClient(ctx, o)
90+
p, err := CreateClient(o)
9191
require.NoError(t, err)
9292
require.NoError(t, p.EnsureConnected(ctx))
9393

@@ -108,8 +108,7 @@ func TestConnectClientZeroConcurrency(t *testing.T) {
108108
}
109109

110110
func TestCloseClientConcurently(t *testing.T) {
111-
ctx := context.Background()
112-
p, err := CreateClient(ctx, opts)
111+
p, err := CreateClient(opts)
113112
require.NoError(t, err)
114113

115114
errs := make(chan error)
@@ -130,7 +129,7 @@ func TestCloseClientConcurently(t *testing.T) {
130129
func TestClientTx(t *testing.T) {
131130
ctx := context.Background()
132131

133-
p, err := CreateClient(ctx, opts)
132+
p, err := CreateClient(opts)
134133
require.NoError(t, err)
135134
defer p.Close() // nolint:errcheck
136135

connect_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
func TestAuth(t *testing.T) {
3535
ctx := context.Background()
36-
p, err := CreateClient(ctx, gelcfg.Options{
36+
p, err := CreateClient(gelcfg.Options{
3737
Host: opts.Host,
3838
Port: opts.Port,
3939
User: "user_with_password",
@@ -118,7 +118,7 @@ func convertUint16ToUint8(value uint16) (uint8, uint8) {
118118

119119
func TestConnectTimeout(t *testing.T) {
120120
ctx := context.Background()
121-
p, err := CreateClient(ctx, gelcfg.Options{
121+
p, err := CreateClient(gelcfg.Options{
122122
Host: opts.Host,
123123
Port: opts.Port,
124124
User: opts.User,
@@ -148,7 +148,7 @@ func TestConnectTimeout(t *testing.T) {
148148

149149
func TestConnectRefused(t *testing.T) {
150150
ctx := context.Background()
151-
p, err := CreateClient(ctx, gelcfg.Options{
151+
p, err := CreateClient(gelcfg.Options{
152152
Host: "localhost",
153153
Port: 23456,
154154
WaitUntilAvailable: 1 * time.Nanosecond,
@@ -173,7 +173,7 @@ func TestConnectRefused(t *testing.T) {
173173

174174
func TestConnectInvalidName(t *testing.T) {
175175
ctx := context.Background()
176-
p, err := CreateClient(ctx, gelcfg.Options{
176+
p, err := CreateClient(gelcfg.Options{
177177
Host: "invalid.example.org",
178178
Port: 23456,
179179
WaitUntilAvailable: 1 * time.Nanosecond,
@@ -208,7 +208,7 @@ func TestConnectInvalidName(t *testing.T) {
208208

209209
func TestConnectRefusedUnixSocket(t *testing.T) {
210210
ctx := context.Background()
211-
p, err := CreateClient(ctx, gelcfg.Options{
211+
p, err := CreateClient(gelcfg.Options{
212212
Host: "/tmp/non-existent",
213213
WaitUntilAvailable: 1 * time.Nanosecond,
214214
})

doc.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
//
5757
// You may also connect to a database using a DSN:
5858
//
59-
// url := "gel://edgedb@localhost/edgedb"
60-
// client, err := gel.CreateClientDSN(ctx, url, opts)
59+
// dsn := "gel://edgedb@localhost/edgedb"
60+
// client, err := gel.CreateClientDSN(ctx, dsn, opts)
6161
//
6262
// Or you can use Option fields.
6363
//
@@ -73,7 +73,7 @@
7373
//
7474
// gel never returns underlying errors directly.
7575
// If you are checking for things like context expiration
76-
// use errors.Is() or errors.As().
76+
// use [errors.Is] or [errors.As].
7777
//
7878
// err := client.Query(...)
7979
// if errors.Is(err, context.Canceled) { ... }
@@ -91,7 +91,7 @@
9191
// # Datatypes
9292
//
9393
// The following list shows the marshal/unmarshal
94-
// mapping between Gel types and go types:
94+
// mapping between Gel types and go types. See also [geltypes]:
9595
//
9696
// Gel Go
9797
// --------- ---------
@@ -128,7 +128,7 @@
128128
// one directly to the other.
129129
//
130130
// Shape fields that are not required must use optional types for receiving
131-
// query results. The gelcfg.Optional struct can be embedded to make structs
131+
// query results. The [gelcfg.Optional] struct can be embedded to make structs
132132
// optional.
133133
//
134134
// type User struct {
@@ -171,9 +171,9 @@
171171
// # Custom Marshalers
172172
//
173173
// Interfaces for user defined marshaler/unmarshalers are documented in the
174-
// internal/marshal package.
174+
// [github.com/geldata/gel-go/internal/marshal] package.
175175
//
176-
// [Gel]: https://www.edgedb.com
177-
// [json]: https://www.edgedb.com/docs/edgeql/insert#bulk-inserts
178-
// [client connection docs]: https://www.edgedb.com/docs/clients/connection
176+
// [Gel]: https://www.geldata.com
177+
// [json]: https://docs.geldata.com/reference/edgeql/insert#bulk-inserts
178+
// [client connection docs]: https://docs.geldata.com/learn/clients#connection
179179
package gel

doc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type User struct {
3636
func Example() {
3737
opts := gelcfg.Options{Concurrency: 4}
3838
ctx := context.Background()
39-
db, err := gel.CreateClientDSN(ctx, "gel://edgedb@localhost/test", opts)
39+
db, err := gel.CreateClientDSN("gel://edgedb@localhost/test", opts)
4040
if err != nil {
4141
log.Fatal(err)
4242
}

gelcfg/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// promote warnings to errors by returning them etc.
3030
type WarningHandler = func([]error) error
3131

32-
// LogWarnings is a gelcfg.WarningHandler that logs warnings.
32+
// LogWarnings is a [WarningHandler] that logs warnings.
3333
func LogWarnings(errors []error) error {
3434
for _, err := range errors {
3535
log.Println("Gel warning:", err.Error())
@@ -38,7 +38,7 @@ func LogWarnings(errors []error) error {
3838
return nil
3939
}
4040

41-
// WarningsAsErrors is a gelcfg.WarningHandler that returns warnings as
41+
// WarningsAsErrors is a [WarningHandler] that returns warnings as
4242
// errors.
4343
func WarningsAsErrors(warnings []error) error {
4444
return errors.Join(warnings...)

gelcfg/queryoptions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewQueryOptions() QueryOptions {
2222
return QueryOptions{fromFactory: true}
2323
}
2424

25-
// QueryOptions controls some limitations that the server can impose on
25+
// QueryOptions controls limitations that the server can impose on
2626
// queries.
2727
type QueryOptions struct {
2828
fromFactory bool

gelcfg/retryoptions.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ import (
2424
)
2525

2626
// RetryCondition represents scenarios that can cause a transaction
27-
// run in Tx() methods to be retried.
27+
// or a single query run outside a geltypes.TxBlock to be retried.
2828
type RetryCondition int
2929

30-
// The following conditions can be configured with a custom RetryRule.
31-
// See RetryOptions.
3230
const (
3331
// TxConflict indicates that the server could not complete a transaction
3432
// because it encountered a deadlock or serialization error.
@@ -39,14 +37,14 @@ const (
3937
NetworkError
4038
)
4139

42-
// NewRetryOptions returns the default retry options.
40+
// NewRetryOptions returns the default RetryOptions.
4341
func NewRetryOptions() RetryOptions {
4442
return RetryOptions{fromFactory: true}.WithDefault(NewRetryRule())
4543
}
4644

47-
// RetryOptions configures how Tx() retries failed transactions. Use
48-
// NewRetryOptions to get a default RetryOptions value instead of creating one
49-
// yourself.
45+
// RetryOptions configures how failed transactions or queries outside of
46+
// transactions are retried. Use [NewRetryOptions] to get a default
47+
// RetryOptions value instead of creating one yourself.
5048
type RetryOptions struct {
5149
fromFactory bool
5250
txConflict RetryRule

gelcfg/retryrule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
var rnd = snc.NewRand()
2828

2929
// RetryBackoff returns the duration to wait after the nth attempt
30-
// before making the next attempt when retrying a transaction.
30+
// before retrying a transaction.
3131
type RetryBackoff func(n int) time.Duration
3232

3333
func defaultBackoff(attempt int) time.Duration {

0 commit comments

Comments
 (0)