Skip to content

Commit a5b8736

Browse files
Merge branch 'master' of github.com:dipdup-net/go-lib
2 parents 9cc5468 + 0f49706 commit a5b8736

File tree

7 files changed

+63
-25
lines changed

7 files changed

+63
-25
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Build release
1+
name: Release
22
on:
33
push:
44
tags:
55
- "v*.*.*"
66

77
jobs:
8-
build:
9-
name: Build
8+
release:
9+
name: Release
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@master

.github/workflows/test_master.yml renamed to .github/workflows/test.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
on:
2-
push:
3-
branches:
4-
- master
5-
name: build
1+
name: Tests
2+
on: push
3+
64
jobs:
75
golangci:
86
name: lint

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
# go-lib
2-
General instruments for DipDup in golang
1+
# DipDup Go SDK
2+
3+
[![Tests](https://github.com/dipdup-net/metadata/workflows/Tests/badge.svg?)](https://github.com/dipdup-net/metadata/actions?query=workflow%3ATests)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5+
6+
This library partially implements DipDup framework features and can be used for building Tezos indexers and dapps when performance and effective resource utilization are important.
37

48
## Packages
59

6-
* `cmdline` - parser for default dipdup keys
10+
#### `cmdline`
11+
12+
Command line argument parser, compatible with [DipDup CLI](https://docs.dipdup.net/command-line).
713

814
```go
915
import "github.com/dipdup-net/go-lib/cmdline"
@@ -14,7 +20,9 @@ if args.Help {
1420
}
1521
```
1622

17-
* `config`
23+
#### `config`
24+
25+
DipDup YAML [configuration](https://docs.dipdup.net/config-file-reference) parser.
1826

1927
```go
2028
import "github.com/dipdup-net/go-lib/config"
@@ -50,23 +58,27 @@ if err := config.Parse("config.yaml", &cfg); err != nil {
5058
}
5159
```
5260

53-
* `node` - package for accessing to tezos node
61+
#### `node`
62+
63+
Simple Tezos RPC API wrapper.
5464

5565
```go
5666
import "github.com/dipdup-net/go-lib/node"
5767

5868
rpc := node.NewNodeRPC(url, node.WithTimeout(timeout))
5969
```
6070

61-
* `state` - package with DipDup state model
71+
#### `state`
72+
73+
Managing DipDup index state.
6274

6375
```go
6476
import "github.com/dipdup-net/go-lib/state"
6577

6678
s := state.State{}
6779
```
6880

69-
`State` structure is
81+
where `State` structure is:
7082
```go
7183
// State -
7284
type State struct {
@@ -77,11 +89,10 @@ type State struct {
7789
}
7890
```
7991

80-
* `tzkt` - package with API and Events wrapper for TzKT.
81-
82-
You can find docs on Events wrapper [here](tzkt/events/README.md).
92+
#### `tzkt`
8393

84-
Example usage of events
94+
TzKT API and Events wrapper.
95+
Read more about events and SignalR in the [doc](https://github.com/dipdup-net/go-lib/blob/master/tzkt/events/README.md)
8596

8697
```go
8798
package main
@@ -110,7 +121,7 @@ func main() {
110121

111122
```
112123

113-
Example usage of API wrapper
124+
Example usage of the API wrapper:
114125

115126
```go
116127
package main

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
116116
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
117117
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
118118
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
119+
github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY=
119120
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
120121
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
121122
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=

hasura/hasura.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ const (
2323
func Create(hasura config.Hasura, cfg config.Database, views []string, models ...interface{}) error {
2424
api := New(hasura.URL, hasura.Secret)
2525

26-
log.Info("Waiting hasura is up...")
26+
log.Info("Waiting hasura is up and running")
2727
for err := api.Health(); err != nil; err = api.Health() {
28-
time.Sleep(time.Second * 10)
28+
log.Warn(err)
29+
time.Sleep(time.Second)
2930
}
3031

3132
metadata, err := Generate(hasura, cfg, models...)
@@ -60,7 +61,7 @@ func Create(hasura config.Hasura, cfg config.Database, views []string, models ..
6061
return err
6162
}
6263

63-
if hasura.Rest == nil || *hasura.Rest {
64+
if len(metadata.QueryCollections) > 0 && (hasura.Rest == nil || *hasura.Rest) {
6465
log.Info("Creating REST endpoints...")
6566
for _, query := range metadata.QueryCollections[0].Definition.Queries {
6667
if err := api.CreateRestEndpoint(query.Name, query.Name, query.Name, allowedQueries); err != nil {

state/db.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@ import (
88

99
"github.com/dipdup-net/go-lib/config"
1010
"github.com/pkg/errors"
11+
"github.com/sirupsen/logrus"
1112
"gorm.io/driver/mysql"
1213
"gorm.io/driver/postgres"
1314
"gorm.io/driver/sqlite"
1415
"gorm.io/gorm"
1516
"gorm.io/gorm/logger"
1617
)
1718

19+
// CheckConnection
20+
func CheckConnection(db *gorm.DB) error {
21+
sql, err := db.DB()
22+
if err != nil {
23+
return err
24+
}
25+
26+
if err = sql.Ping(); err != nil {
27+
return err
28+
}
29+
30+
return nil
31+
}
32+
1833
// OpenConnection -
1934
func OpenConnection(cfg config.Database) (*gorm.DB, error) {
2035
var dialector gorm.Dialector
@@ -43,7 +58,7 @@ func OpenConnection(cfg config.Database) (*gorm.DB, error) {
4358
return nil, errors.Errorf("Unsupported database kind %s", cfg.Kind)
4459
}
4560

46-
return gorm.Open(dialector, &gorm.Config{
61+
db, err := gorm.Open(dialector, &gorm.Config{
4762
SkipDefaultTransaction: true,
4863
PrepareStmt: true,
4964
Logger: logger.New(
@@ -54,4 +69,15 @@ func OpenConnection(cfg config.Database) (*gorm.DB, error) {
5469
},
5570
),
5671
})
72+
if err != nil {
73+
return nil, err
74+
}
75+
76+
logrus.Info("Waiting database is up and runnning")
77+
for err := CheckConnection(db); err != nil; err = CheckConnection(db) {
78+
logrus.Warn(err)
79+
time.Sleep(time.Second)
80+
}
81+
82+
return db, nil
5783
}

tzkt/api/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package api
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"net/http"
67
"net/url"
@@ -59,7 +60,7 @@ func (tzkt *API) json(endpoint string, args map[string]string, output interface{
5960
return json.NewDecoder(resp.Body).Decode(output)
6061
}
6162

62-
return errors.New(resp.Status)
63+
return errors.New(fmt.Sprintf("%s: %s %v", resp.Status, endpoint, args))
6364
}
6465

6566
func (tzkt *API) count(endpoint string) (uint64, error) {

0 commit comments

Comments
 (0)