Skip to content

Commit

Permalink
map[string]interface{} to map[string]any
Browse files Browse the repository at this point in the history
  • Loading branch information
sbpann committed Jun 25, 2023
1 parent 224d16f commit 5683eba
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 26 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.18
go-version: ^1.20

- name: Test
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
go test ./... -coverprofile=c.out
./cc-test-reporter after-build --prefix github.com/argonlab-io/bucharest
go test ./...
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
./test.sh
./scripts/test.sh
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var ErrNoRedis = errors.New("*redis.Client is not present in this context")
var ErrNoSQL = errors.New("*sql.DB is not present in this context")
var ErrNoSQLX = errors.New("*sqlx.DB is not present in this context")

func AddValuesToContext(ctx Context, values MapAny) Context {
func AddValuesToContext(ctx Context, values map[string]any) Context {
for key, value := range values {
ctx.SetValue(key, value)
}
Expand Down
6 changes: 3 additions & 3 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func TestAddValuesToContext(t *testing.T) {
t.Errorf("NewContext().String() = %q want %q", got, want)
}

key1 := 1
key1 := "key1"
value1 := "one"
key2 := "two"
key2 := "key2"
value2 := 2

ctx = AddValuesToContext(NewContextWithOptions(&ContextOptions{Parent: ctx}), MapAny{
ctx = AddValuesToContext(NewContextWithOptions(&ContextOptions{Parent: ctx}), map[string]any{
key1: value1,
key2: value2,
})
Expand Down
4 changes: 2 additions & 2 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type ENV interface {
All() Map
All() map[string]any
Bool(key string) bool
Int(key string) int
String(key string) string
Expand All @@ -15,7 +15,7 @@ type ENV interface {

type env struct{ preventDefaultPointer uuid.UUID }

func (e *env) All() Map {
func (e *env) All() map[string]any {
return viper.AllSettings()
}

Expand Down
7 changes: 3 additions & 4 deletions gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewGinHandlerFunc(ctx Context, handlerFunc HandlerFunc) gin.HandlerFunc {
}
}

func NewGinHandlerFuncWithData(ctx Context, handlerFunc HandlerFuncWithData, data Map) gin.HandlerFunc {
func NewGinHandlerFuncWithData(ctx Context, handlerFunc HandlerFuncWithData, data map[string]any) gin.HandlerFunc {
return func(g *gin.Context) {
httpError := handlerFunc(defaultHttpContextWithGin(ctx, g), data)
if httpError != nil {
Expand Down Expand Up @@ -384,7 +384,6 @@ func (rh *ginResponseHeader) SetAccepted(formats ...string) {
rh.gin.SetAccepted(formats...)
}

//
type ginResponseBody struct {
gin *gin.Context
}
Expand Down Expand Up @@ -513,7 +512,7 @@ func (h *httpContextWithGin) Gin() *gin.Context {
return ctx
}

func GinLoggerWithConfig(ctx HTTPContext, data Map) HTTPError {
func GinLoggerWithConfig(ctx HTTPContext, data map[string]any) HTTPError {
conf, logLevelFromGinParam := getLogConfigAndLogLevel(data)

formatter := conf.Formatter
Expand Down Expand Up @@ -574,7 +573,7 @@ func GinLoggerWithConfig(ctx HTTPContext, data Map) HTTPError {

type LogLevelFromGinParam func(*gin.LogFormatterParams) logrus.Level

func getLogConfigAndLogLevel(data Map) (*gin.LoggerConfig, LogLevelFromGinParam) {
func getLogConfigAndLogLevel(data map[string]any) (*gin.LoggerConfig, LogLevelFromGinParam) {
conf, ok := data["conf"].(*gin.LoggerConfig)
if !ok {
conf = &gin.LoggerConfig{}
Expand Down
4 changes: 2 additions & 2 deletions gin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func TestNewGinHandlerFuncWithData(t *testing.T) {
ctx := NewContextWithOptions(nil)
assert.NotNil(t, ctx)

handler := func(ctx HTTPContext, data Map) HTTPError {
handler := func(ctx HTTPContext, data map[string]any) HTTPError {
return NewBadRequestError(errors.New(data["message"].(string)))
}
ginHandlerFunc := NewGinHandlerFuncWithData(ctx, handler, Map{"message": "foobar"})
ginHandlerFunc := NewGinHandlerFuncWithData(ctx, handler, map[string]any{"message": "foobar"})
assert.NotNil(t, ginHandlerFunc)

var err error
Expand Down
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ type HTTPError interface {
}

type HandlerFunc func(HTTPContext) HTTPError
type HandlerFuncWithData func(HTTPContext, Map) HTTPError
type HandlerFuncWithData func(HTTPContext, map[string]any) HTTPError
type HandlersChain []HandlerFunc
File renamed without changes.
4 changes: 0 additions & 4 deletions types.go

This file was deleted.

0 comments on commit 5683eba

Please sign in to comment.