From 3bf9f02a9f4b0bc208ddffa7ad16d5e5a91cfe81 Mon Sep 17 00:00:00 2001 From: Vikram Rangnekar Date: Sun, 10 May 2020 11:26:48 -0400 Subject: [PATCH] fix: bug with reading config file by name --- Makefile | 2 +- core/config.go | 11 ++++++++--- core/internal/qcode/bench.9 | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 core/internal/qcode/bench.9 diff --git a/Makefile b/Makefile index 0bc5759..f989f46 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ BUILD_FLAGS ?= -ldflags '-s -w -X ${lastCommitSHA}=${BUILD} -X "${lastCommitTime .PHONY: all build gen clean test run lint changlog release version help $(PLATFORMS) test: - @go test -v ./... + @go test -v -short -race ./... BIN_DIR := $(GOPATH)/bin GORICE := $(BIN_DIR)/rice diff --git a/core/config.go b/core/config.go index 9c7f7ae..7a533cc 100644 --- a/core/config.go +++ b/core/config.go @@ -3,6 +3,7 @@ package core import ( "fmt" "path" + "path/filepath" "strings" "github.com/spf13/viper" @@ -195,9 +196,13 @@ func newViper(configPath, configFile string) *viper.Viper { vi.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) vi.AutomaticEnv() - vi.SetConfigName(configFile) - vi.AddConfigPath(configPath) - vi.AddConfigPath("./config") + if len(filepath.Ext(configFile)) != 0 { + vi.SetConfigFile(configFile) + } else { + vi.SetConfigName(configFile) + vi.AddConfigPath(configPath) + vi.AddConfigPath("./config") + } return vi } diff --git a/core/internal/qcode/bench.9 b/core/internal/qcode/bench.9 new file mode 100644 index 0000000..9172f77 --- /dev/null +++ b/core/internal/qcode/bench.9 @@ -0,0 +1,17 @@ +goos: darwin +goarch: amd64 +pkg: github.com/dosco/super-graph/core/internal/qcode +BenchmarkQCompile +BenchmarkQCompile-16 129614 8649 ns/op 3756 B/op 28 allocs/op +BenchmarkQCompileP +BenchmarkQCompileP-16 487488 2525 ns/op 3792 B/op 28 allocs/op +BenchmarkParse +BenchmarkParse-16 127582 8731 ns/op 3902 B/op 18 allocs/op +BenchmarkParseP +BenchmarkParseP-16 561373 2223 ns/op 3903 B/op 18 allocs/op +BenchmarkSchemaParse +BenchmarkSchemaParse-16 209142 5523 ns/op 3968 B/op 57 allocs/op +BenchmarkSchemaParseP +BenchmarkSchemaParseP-16 716437 1734 ns/op 3968 B/op 57 allocs/op +PASS +ok github.com/dosco/super-graph/core/internal/qcode 8.483s