Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use DBBackend global variable for default config #211

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OUTPUT?=build/ostracon
BUILD_TAGS?=ostracon
VERSION := $(shell git describe --always)
LD_FLAGS = -X github.com/line/ostracon/version.TMCoreSemVer=$(VERSION)
BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
BUILD_FLAGS = -mod=readonly
HTTPS_GIT := https://github.com/line/ostracon.git
DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuild/buf
CGO_ENABLED ?= 0
Expand All @@ -23,25 +23,29 @@ endif

ifeq (,$(filter $(OSTRACON_BUILD_OPTIONS), cleveldb rocksdb boltdb badgerdb))
BUILD_TAGS += goleveldb
LD_FLAGS += -X github.com/line/ostracon/types.DBBackend=goleveldb
else
ifeq (cleveldb,$(findstring cleveldb,$(OSTRACON_BUILD_OPTIONS)))
CGO_ENABLED=1
BUILD_TAGS += cleveldb
LD_FLAGS += -X github.com/line/ostracon/types.DBBackend=cleveldb
endif
ifeq (badgerdb,$(findstring badgerdb,$(OSTRACON_BUILD_OPTIONS)))
BUILD_TAGS += badgerdb
LD_FLAGS += -X github.com/line/ostracon/types.DBBackend=badgerdb
endif
ifeq (rocksdb,$(findstring rocksdb,$(OSTRACON_BUILD_OPTIONS)))
CGO_ENABLED=1
BUILD_TAGS += rocksdb
LD_FLAGS += -X github.com/line/ostracon/types.DBBackend=rocksdb
endif
ifeq (boltdb,$(findstring boltdb,$(OSTRACON_BUILD_OPTIONS)))
BUILD_TAGS += boltdb
LD_FLAGS += -X github.com/line/ostracon/types.DBBackend=boltdb
endif
endif

# allow users to pass additional flags via the conventional LDFLAGS variable
LD_FLAGS += $(LDFLAGS)
BUILD_FLAGS += -ldflags "$(LD_FLAGS)"

all: check build test install
.PHONY: all
Expand Down
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"path/filepath"
"time"

"github.com/line/ostracon/types"
)

const (
Expand Down Expand Up @@ -232,7 +234,7 @@ func DefaultBaseConfig() BaseConfig {
LogFormat: LogFormatPlain,
FastSyncMode: true,
FilterPeers: false,
DBBackend: "goleveldb",
DBBackend: types.DBBackend,
DBPath: "data",
}
}
Expand Down
15 changes: 14 additions & 1 deletion types/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
package types

import "reflect"
import (
"reflect"
)

var (
// DBBackend is set at compile time. Could be cleveldb, defaults is goleveldb.
DBBackend = ""
)

func init() {
if len(DBBackend) == 0 {
DBBackend = "goleveldb"
}
}

// Go lacks a simple and safe way to see if something is a typed nil.
// See:
Expand Down