Commit 2fc04a08 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: Give ConnOptions its own String

Connection options could be prepared/logged not only in DB.Open, so
instead of teaching only DB.Open how to print them, teach ConnOptions to
represent itself in human-readable form.
parent 218a9c6f
// Copyright (C) 2018 Nexedi SA and Contributors.
// Copyright (C) 2018-2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -24,7 +24,6 @@ package zodb
import (
"context"
"fmt"
"sort"
"sync"
"time"
......@@ -75,6 +74,27 @@ type ConnOptions struct {
NoSync bool // don't sync with storage to get its last tid.
}
// String represents connection options in human-readable form.
//
// For example:
//
// (@head, sync)
func (opt *ConnOptions) String() string {
s := "(@"
if opt.At != 0 {
s += opt.At.String()
} else {
s += "head"
}
s += ", "
if opt.NoSync {
s += "no"
}
s += "sync)"
return s
}
// Open opens new connection to the database.
//
// By default the connection is opened to current latest database state; opt.At
......@@ -89,18 +109,10 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
return
}
var argv []interface{}
if opt.At != 0 {
argv = append(argv, fmt.Sprintf("at=%s", opt.At))
}
if opt.NoSync {
argv = append(argv, "nosync")
}
err = &OpError{
URL: db.stor.URL(),
Op: "open db",
Args: argv,
Args: opt,
Err: err,
}
}()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment