Skip to content

v2: update public API #158

Closed
Closed

Description

Unlike other program languages like Java and Python that use access modifiers such as public, private, or protected to specify scope, Go determines if an item is exported and unexported through how it is declared. Exporting an item in this case makes it visible outside the current package. If it’s not exported, it is only visible and usable from within the package it was defined. This external visibility is controlled by capitalizing the first letter of the item declared. All declarations, such as Types, Variables, Constants, Functions, etc., that start with a capital letter are visible outside the current package.

There are many things in go-connector that exposed as a part of public API. We need to update a public API and probably make some of these things invisible for external users.

We need to document this if we want to keep these things in a public API.

NOTE: It is a breaking change and next release with these changes should bump a MAJOR version.

  • constants declared in const.go,

    go-tarantool/const.go

    Lines 4 to 31 in 31ebde8

    SelectRequest = 1
    InsertRequest = 2
    ReplaceRequest = 3
    UpdateRequest = 4
    DeleteRequest = 5
    CallRequest = 6 /* call in 1.6 format */
    AuthRequest = 7
    EvalRequest = 8
    UpsertRequest = 9
    Call17Request = 10
    PingRequest = 64
    SubscribeRequest = 66
    KeyCode = 0x00
    KeySync = 0x01
    KeySpaceNo = 0x10
    KeyIndexNo = 0x11
    KeyLimit = 0x12
    KeyOffset = 0x13
    KeyIterator = 0x14
    KeyKey = 0x20
    KeyTuple = 0x21
    KeyFunctionName = 0x22
    KeyUserName = 0x23
    KeyExpression = 0x27
    KeyDefTuple = 0x28
    KeyData = 0x30
    KeyError = 0x31
  • constants declared in consts.go,

    go-tarantool/const.go

    Lines 17 to 31 in 2c3af56

    KeyCode = 0x00
    KeySync = 0x01
    KeySpaceNo = 0x10
    KeyIndexNo = 0x11
    KeyLimit = 0x12
    KeyOffset = 0x13
    KeyIterator = 0x14
    KeyKey = 0x20
    KeyTuple = 0x21
    KeyFunctionName = 0x22
    KeyUserName = 0x23
    KeyExpression = 0x27
    KeyDefTuple = 0x28
    KeyData = 0x30
    KeyError = 0x31
  • constants declared in consts.go,

    go-tarantool/const.go

    Lines 46 to 51 in 2c3af56

    RLimitDrop = 1
    RLimitWait = 2
    OkCode = uint32(0)
    ErrorCodeBit = 0x8000
    PacketLengthBytes = 5
  • Connector interface in connector.go,
    type Connector interface {
    ConnectedNow() bool
    Close() error
    Ping() (resp *Response, err error)
    ConfiguredTimeout() time.Duration
    Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (resp *Response, err error)
    Insert(space interface{}, tuple interface{}) (resp *Response, err error)
    Replace(space interface{}, tuple interface{}) (resp *Response, err error)
    Delete(space, index interface{}, key interface{}) (resp *Response, err error)
    Update(space, index interface{}, key, ops interface{}) (resp *Response, err error)
    Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error)
    Call(functionName string, args interface{}) (resp *Response, err error)
    Call17(functionName string, args interface{}) (resp *Response, err error)
    Eval(expr string, args interface{}) (resp *Response, err error)
    GetTyped(space, index interface{}, key interface{}, result interface{}) (err error)
    SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}) (err error)
    InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error)
    ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error)
    DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error)
    UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error)
    CallTyped(functionName string, args interface{}, result interface{}) (err error)
    Call17Typed(functionName string, args interface{}, result interface{}) (err error)
    EvalTyped(expr string, args interface{}, result interface{}) (err error)
    SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *Future
    InsertAsync(space interface{}, tuple interface{}) *Future
    ReplaceAsync(space interface{}, tuple interface{}) *Future
    DeleteAsync(space, index interface{}, key interface{}) *Future
    UpdateAsync(space, index interface{}, key, ops interface{}) *Future
    UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future
    CallAsync(functionName string, args interface{}) *Future
    Call17Async(functionName string, args interface{}) *Future
    EvalAsync(expr string, args interface{}) *Future
    }
  • Deadline methods,
    type DeadlineIO struct {
    to time.Duration
    c net.Conn
    }
    func (d *DeadlineIO) Write(b []byte) (n int, err error) {
    if d.to > 0 {
    d.c.SetWriteDeadline(time.Now().Add(d.to))
    }
    n, err = d.c.Write(b)
    return
    }
    func (d *DeadlineIO) Read(b []byte) (n int, err error) {
    if d.to > 0 {
    d.c.SetReadDeadline(time.Now().Add(d.to))
    }
    n, err = d.c.Read(b)
    return
    }
  • UUID ext type constant
    const UUID_extId = 2
  • smallbuf api,

    go-tarantool/smallbuf.go

    Lines 13 to 97 in 7897baf

    func (s *smallBuf) Read(d []byte) (l int, err error) {
    l = len(s.b) - s.p
    if l == 0 && len(d) > 0 {
    return 0, io.EOF
    }
    if l > len(d) {
    l = len(d)
    }
    copy(d, s.b[s.p:])
    s.p += l
    return l, nil
    }
    func (s *smallBuf) ReadByte() (b byte, err error) {
    if s.p == len(s.b) {
    return 0, io.EOF
    }
    b = s.b[s.p]
    s.p++
    return b, nil
    }
    func (s *smallBuf) UnreadByte() error {
    if s.p == 0 {
    return errors.New("Could not unread")
    }
    s.p--
    return nil
    }
    func (s *smallBuf) Len() int {
    return len(s.b) - s.p
    }
    func (s *smallBuf) Bytes() []byte {
    if len(s.b) > s.p {
    return s.b[s.p:]
    }
    return nil
    }
    type smallWBuf struct {
    b []byte
    sum uint
    n uint
    }
    func (s *smallWBuf) Write(b []byte) (int, error) {
    s.b = append(s.b, b...)
    return len(s.b), nil
    }
    func (s *smallWBuf) WriteByte(b byte) error {
    s.b = append(s.b, b)
    return nil
    }
    func (s *smallWBuf) WriteString(ss string) (int, error) {
    s.b = append(s.b, ss...)
    return len(ss), nil
    }
    func (s smallWBuf) Len() int {
    return len(s.b)
    }
    func (s smallWBuf) Cap() int {
    return cap(s.b)
    }
    func (s *smallWBuf) Trunc(n int) {
    s.b = s.b[:n]
    }
    func (s *smallWBuf) Reset() {
    s.sum = uint(uint64(s.sum)*15/16) + uint(len(s.b))
    if s.n < 16 {
    s.n++
    }
    if cap(s.b) > 1024 && s.sum/s.n < uint(cap(s.b))/4 {
    s.b = make([]byte, 0, s.sum/s.n)
    } else {
    s.b = s.b[:0]
    }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

code healthImprove code readability, simplify maintenance and so onteamEv2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions