Skip to content

Commit

Permalink
Merge pull request #5 from alexandear/rename-json-http
Browse files Browse the repository at this point in the history
Rename Json to JSON, Http to HTTP
  • Loading branch information
jamietanna committed Nov 14, 2023
2 parents 11ea4d6 + be99087 commit b5265cf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions deepobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func getFieldName(f reflect.StructField) string {

// Create a map of field names that we'll see in the deepObject to reflect
// field indices on the given type.
func fieldIndicesByJsonTag(i interface{}) (map[string]int, error) {
func fieldIndicesByJSONTag(i interface{}) (map[string]int, error) {
t := reflect.TypeOf(i)
if t.Kind() != reflect.Struct {
return nil, errors.New("expected a struct as input")
Expand Down Expand Up @@ -271,7 +271,7 @@ func assignPathValues(dst interface{}, pathValues fieldOrValue) error {
}
dst.Set(reflect.ValueOf(tm))
}
fieldMap, err := fieldIndicesByJsonTag(iv.Interface())
fieldMap, err := fieldIndicesByJSONTag(iv.Interface())
if err != nil {
return fmt.Errorf("failed enumerating fields: %w", err)
}
Expand Down
8 changes: 8 additions & 0 deletions jsonmerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import (

// JsonMerge merges two JSON representation into a single object. `data` is the
// existing representation and `patch` is the new data to be merged in
//
// Deprecated: Use JSONMerge instead.
func JsonMerge(data, patch json.RawMessage) (json.RawMessage, error) {
return JSONMerge(data, patch)
}

// JSONMerge merges two JSON representation into a single object. `data` is the
// existing representation and `patch` is the new data to be merged in
func JSONMerge(data, patch json.RawMessage) (json.RawMessage, error) {
merger := jsonmerge.Merger{
CopyNonexistent: true,
}
Expand Down
16 changes: 8 additions & 8 deletions jsonmerge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"github.com/stretchr/testify/assert"
)

func TestJsonMerge(t *testing.T) {
func TestJSONMerge(t *testing.T) {
t.Run("when object", func(t *testing.T) {
t.Run("Merges properties defined in both objects", func(t *testing.T) {
data := `{"foo": 1}`
patch := `{"foo": null}`
expected := `{"foo":null}`

actual, err := JsonMerge([]byte(data), []byte(patch))
actual, err := JSONMerge([]byte(data), []byte(patch))
assert.NoError(t, err)
assert.Equal(t, expected, string(actual))
})
Expand All @@ -23,7 +23,7 @@ func TestJsonMerge(t *testing.T) {
patch := `{"source":"merge-me"}`
expected := `{"source":"merge-me"}`

actual, err := JsonMerge([]byte(data), []byte(patch))
actual, err := JSONMerge([]byte(data), []byte(patch))
assert.NoError(t, err)
assert.Equal(t, expected, string(actual))
})
Expand All @@ -33,7 +33,7 @@ func TestJsonMerge(t *testing.T) {
patch := `{"channel":{"id":1}}`
expected := `{"channel":{"id":1,"status":"valid"}}`

actual, err := JsonMerge([]byte(data), []byte(patch))
actual, err := JSONMerge([]byte(data), []byte(patch))
assert.NoError(t, err)
assert.Equal(t, expected, string(actual))
})
Expand All @@ -43,7 +43,7 @@ func TestJsonMerge(t *testing.T) {
patch := `{}`
expected := `{}`

actual, err := JsonMerge([]byte(data), []byte(patch))
actual, err := JSONMerge([]byte(data), []byte(patch))
assert.NoError(t, err)
assert.Equal(t, expected, string(actual))
})
Expand All @@ -52,7 +52,7 @@ func TestJsonMerge(t *testing.T) {
patch := `{"foo":"bar"}`
expected := `{"foo":"bar"}`

actual, err := JsonMerge(nil, []byte(patch))
actual, err := JSONMerge(nil, []byte(patch))
assert.NoError(t, err)
assert.Equal(t, expected, string(actual))
})
Expand All @@ -61,7 +61,7 @@ func TestJsonMerge(t *testing.T) {
data := `{"foo":"bar"}`
expected := `{"foo":"bar"}`

actual, err := JsonMerge([]byte(data), nil)
actual, err := JSONMerge([]byte(data), nil)
assert.NoError(t, err)
assert.Equal(t, expected, string(actual))
})
Expand All @@ -72,7 +72,7 @@ func TestJsonMerge(t *testing.T) {
patch := `[{"foo": null}]`
expected := `[{"foo":1}]`

actual, err := JsonMerge([]byte(data), []byte(patch))
actual, err := JSONMerge([]byte(data), []byte(patch))
assert.NoError(t, err)
assert.Equal(t, expected, string(actual))
})
Expand Down
6 changes: 6 additions & 0 deletions strictmiddleware/nethttp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
"net/http"
)

type StrictHTTPHandlerFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (response interface{}, err error)

type StrictHTTPMiddlewareFunc func(f StrictHTTPHandlerFunc, operationID string) StrictHTTPHandlerFunc

// Deprecated: Use StrictHTTPHandlerFunc instead.
type StrictHttpHandlerFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (response interface{}, err error)

// Deprecated: Use StrictHTTPMiddlewareFunc instead.
type StrictHttpMiddlewareFunc func(f StrictHttpHandlerFunc, operationID string) StrictHttpHandlerFunc

0 comments on commit b5265cf

Please sign in to comment.