Skip to content

add buffer #1

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

Merged
merged 1 commit into from
Jan 12, 2025
Merged
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ linters:
- errorlint
- bodyclose
- exportloopref
- gci
- gosec
- lll
fast: false
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2024, Mikhail Knyazhev <[email protected]>
Copyright (c) 2024-2025, Mikhail Knyazhev <[email protected]>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ build:
tests:
devtool test

.PHONY: pre-commite
pre-commite: setup lint build tests
.PHONY: pre-commit
pre-commit: setup license lint build tests

.PHONY: ci
ci: install setup lint build tests
Expand Down
2 changes: 1 addition & 1 deletion ascii.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

Expand Down
5 changes: 5 additions & 0 deletions cache/cache_simple.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

package cache

import (
Expand Down
5 changes: 5 additions & 0 deletions cache/cache_time.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

package cache

import (
Expand Down
5 changes: 5 additions & 0 deletions cache/cache_time_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

package cache

import (
Expand Down
5 changes: 5 additions & 0 deletions cache/common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

package cache

import "time"
Expand Down
6 changes: 3 additions & 3 deletions codec/encdec.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

Expand Down Expand Up @@ -31,7 +31,7 @@ type (
Codec struct {
Encode func(in interface{}) ([]byte, error)
Decode func(b []byte, out interface{}) error
Merge func(dst map[string]interface{}, src map[string]interface{}) error
Merge func(dst map[string]interface{}, src ...map[string]interface{})
}
encoders struct {
list map[string]Codec
Expand All @@ -54,7 +54,7 @@ func (v *encoders) Add(
ext string,
enc func(interface{}) ([]byte, error),
dec func([]byte, interface{}) error,
merge func(map[string]interface{}, map[string]interface{}) error,
merge func(map[string]interface{}, ...map[string]interface{}),
) *encoders {
v.mux.Lock(func() {
v.list[ext] = Codec{
Expand Down
6 changes: 2 additions & 4 deletions codec/encdec_blob.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

Expand Down Expand Up @@ -53,9 +53,7 @@ func (v *BlobEncoder) Encode(configs ...interface{}) error {
if err = codec.Decode(bb, &tmp); err != nil {
return err
}
if err = codec.Merge(out, tmp); err != nil {
return err
}
codec.Merge(out, tmp)
}
v.Blob, err0 = codec.Encode(out)
return err0
Expand Down
3 changes: 2 additions & 1 deletion codec/encdec_blob_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

Expand All @@ -9,6 +9,7 @@ import (
"testing"

"go.osspkg.com/casecheck"

"go.osspkg.com/ioutils/codec"
)

Expand Down
2 changes: 1 addition & 1 deletion codec/encdec_file.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

Expand Down
2 changes: 1 addition & 1 deletion codec/encdec_file_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

Expand Down
31 changes: 17 additions & 14 deletions codec/map_merge.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

package codec

func mapMerge(dst map[string]interface{}, src map[string]interface{}) error {
for k, v := range src {
vv, ok := dst[k]
if !ok {
func mapMerge(dst map[string]interface{}, src ...map[string]interface{}) {
for _, next := range src {
for k, v := range next {
vv, ok := dst[k]
if !ok {
dst[k] = v
continue
}

m1, ok1 := vv.(map[string]interface{})
m2, ok2 := v.(map[string]interface{})
if ok2 && ok1 {
mapMerge(m1, m2)
continue
}

dst[k] = v
continue
}
vMap, vOk := v.(map[string]interface{})
vvMap, vvOk := vv.(map[string]interface{})
if vOk && vvOk {
return mapMerge(vvMap, vMap)
}
dst[k] = v
}

return nil
}
14 changes: 12 additions & 2 deletions codec/map_merge_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

Expand All @@ -17,6 +17,8 @@ func TestUnit_mapMerge(t *testing.T) {
"aa": map[string]interface{}{
"bb": "cc",
},
"yy": 123,
"ww": 123,
}
mapB := map[string]interface{}{
"zz": "xx",
Expand All @@ -26,10 +28,15 @@ func TestUnit_mapMerge(t *testing.T) {
"rr": "tt",
},
},
"ww": map[string]interface{}{
"gg": "hh",
},
}

casecheck.NoError(t, mapMerge(mapA, mapB))
mapMerge(mapA, mapB)

casecheck.Equal(t, map[string]interface{}{
"yy": 123,
"zz": "xx",
"qq": "ww",
"aa": map[string]interface{}{
Expand All @@ -39,5 +46,8 @@ func TestUnit_mapMerge(t *testing.T) {
"rr": "tt",
},
},
"ww": map[string]interface{}{
"gg": "hh",
},
}, mapA)
}
Loading
Loading