Skip to content

Commit

Permalink
api: add initial implementation
Browse files Browse the repository at this point in the history
The package parses constants from:

- tarantool/src/box/errcode.h
- tarantool/src/box/iproto_constants.h
- tarantool/src/box/iproto_features.h

You could to generate the code with the command:

TT_TAG=master make

Closes tarantool/go-tarantool#267
  • Loading branch information
oleg-jukovec committed Apr 11, 2023
1 parent d382401 commit 1f4bce2
Show file tree
Hide file tree
Showing 23 changed files with 2,622 additions and 0 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: testing

on:
push:
pull_request:
workflow_dispatch:

jobs:
tests:
# We want to run on external PRs, but not on our own internal
# PRs as they'll be run by the push to the branch.
#
# The main trick is described here:
# https://github.com/Dart-Code/Dart-Code/pull/2375
#
# Also we want to run it always for manually triggered workflows.
if: (github.event_name == 'push') ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name != github.repository) ||
(github.event_name == 'workflow_dispatch')

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
golang:
- '1.13'
- '1.20'

steps:
- uses: actions/checkout@v3

- name: Setup golang ${{ matrix.golang }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.golang }}

- run: make test

master-build:
if: (github.event_name == 'push') ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name != github.repository) ||
(github.event_name == 'workflow_dispatch')

runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3

- run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

- run: make deps

- run: TT_TAG=master make

golangci-lint:
if: (github.event_name == 'push') ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name != github.repository) ||
(github.event_name == 'workflow_dispatch')

runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
continue-on-error: true
with:
# The first run is for GitHub Actions error format.
args: -E goimports

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# The second run is for human-readable error format with a file name
# and a line number.
args: --out-${NO_FUTURE}format colored-line-number -E goimports
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SHELL := /bin/bash

.PHONY: all
all: generate test

.PHONY: deps
deps:
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/tools/cmd/stringer@latest

.PHONY: format
format:
goimports -l -w .

.PHONY: generate
generate:
go generate ./...

.PHONY: test
test:
@echo "Running all packages tests"
go clean -testcache
go test -tags ./... -v -p 1
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[![Go Reference][godoc-badge]][godoc-url]
[![Actions Status][actions-badge]][actions-url]
[![Telegram][telegram-badge]][telegram-url]
[![Telegram Russian][telegram-badge]][telegramru-url]

# iproto

## Import

```go
import "github.com/tarantool/go-iproto"
```

## Overview

Package `iproto` contains IPROTO constants.

The code generated from Tarantool code. Code generation is only supported for
an actual commit/release. We do not have a goal to support all versions of
Tarantool with a code generator.

## Example

```go
package main

import (
"fmt"

"github.com/tarantool/go-iproto"
)

func main() {
fmt.Printf("%s=%d\n", iproto.ER_READONLY, iproto.ER_READONLY)
fmt.Printf("%s=%d\n", iproto.IPROTO_FEATURE_WATCHERS, iproto.IPROTO_FEATURE_WATCHERS)
fmt.Printf("%s=%d\n", iproto.IPROTO_FLAG_COMMIT, iproto.IPROTO_FLAG_COMMIT)
fmt.Printf("%s=%d\n", iproto.IPROTO_SYNC, iproto.IPROTO_SYNC)
fmt.Printf("%s=%d\n", iproto.IPROTO_SELECT, iproto.IPROTO_SELECT)
}
```

## Development

You need to install `git` and `go1.13+` first. After that, you need to install
additional dependencies into `$GOBIN`:

```bash
make deps
```

You can generate the code with commands:

```bash
TT_TAG=master make
TT_TAG=2.10.6 make
TT_TAG=master TT_REPO=https://github.com/my/tarantool.git make
```

You need to specify a target branch/tag with the environment variable `TT_TAG`
and you could to specify a repository with the `TT_REPO`.

Makefile has additional targets that can be useful:

```bash
make format
TT_TAG=master make generate
make test
```

A good starting point is [generate.go](./generate.go).

[actions-badge]: https://github.com/tarantool/go-iproto/actions/workflows/test.yml/badge.svg
[actions-url]: https://github.com/tarantool/go-iproto/actions/workflows/test.yml
[godoc-badge]: https://pkg.go.dev/badge/github.com/tarantool/go-iproto.svg
[godoc-url]: https://pkg.go.dev/github.com/tarantool/go-iproto
[telegram-badge]: https://img.shields.io/badge/Telegram-join%20chat-blue.svg
[telegram-url]: http://telegram.me/tarantool
[telegramru-url]: http://telegram.me/tarantoolru
10 changes: 10 additions & 0 deletions doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1f4bce2

Please sign in to comment.