Skip to content

Commit db1a549

Browse files
authored
Merge pull request #1 from osspkg/dev
add buffer
2 parents 93a5f11 + 5001bcc commit db1a549

26 files changed

+738
-132
lines changed

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ linters:
368368
- errorlint
369369
- bodyclose
370370
- exportloopref
371-
- gci
372371
- gosec
373372
- lll
374373
fast: false

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

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

55
Redistribution and use in source and binary forms, with or without
66
modification, are permitted provided that the following conditions are met:

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ build:
2323
tests:
2424
devtool test
2525

26-
.PHONY: pre-commite
27-
pre-commite: setup lint build tests
26+
.PHONY: pre-commit
27+
pre-commit: setup license lint build tests
2828

2929
.PHONY: ci
3030
ci: install setup lint build tests

ascii.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
33
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
44
*/
55

cache/cache_simple.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
3+
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
4+
*/
5+
16
package cache
27

38
import (

cache/cache_time.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
3+
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
4+
*/
5+
16
package cache
27

38
import (

cache/cache_time_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
3+
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
4+
*/
5+
16
package cache
27

38
import (

cache/common.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
3+
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
4+
*/
5+
16
package cache
27

38
import "time"

codec/encdec.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
33
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
44
*/
55

@@ -31,7 +31,7 @@ type (
3131
Codec struct {
3232
Encode func(in interface{}) ([]byte, error)
3333
Decode func(b []byte, out interface{}) error
34-
Merge func(dst map[string]interface{}, src map[string]interface{}) error
34+
Merge func(dst map[string]interface{}, src ...map[string]interface{})
3535
}
3636
encoders struct {
3737
list map[string]Codec
@@ -54,7 +54,7 @@ func (v *encoders) Add(
5454
ext string,
5555
enc func(interface{}) ([]byte, error),
5656
dec func([]byte, interface{}) error,
57-
merge func(map[string]interface{}, map[string]interface{}) error,
57+
merge func(map[string]interface{}, ...map[string]interface{}),
5858
) *encoders {
5959
v.mux.Lock(func() {
6060
v.list[ext] = Codec{

codec/encdec_blob.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
33
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
44
*/
55

@@ -53,9 +53,7 @@ func (v *BlobEncoder) Encode(configs ...interface{}) error {
5353
if err = codec.Decode(bb, &tmp); err != nil {
5454
return err
5555
}
56-
if err = codec.Merge(out, tmp); err != nil {
57-
return err
58-
}
56+
codec.Merge(out, tmp)
5957
}
6058
v.Blob, err0 = codec.Encode(out)
6159
return err0

codec/encdec_blob_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
33
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
44
*/
55

@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"go.osspkg.com/casecheck"
12+
1213
"go.osspkg.com/ioutils/codec"
1314
)
1415

codec/encdec_file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
33
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
44
*/
55

codec/encdec_file_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
33
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
44
*/
55

codec/map_merge.go

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
/*
2-
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
33
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
44
*/
55

66
package codec
77

8-
func mapMerge(dst map[string]interface{}, src map[string]interface{}) error {
9-
for k, v := range src {
10-
vv, ok := dst[k]
11-
if !ok {
8+
func mapMerge(dst map[string]interface{}, src ...map[string]interface{}) {
9+
for _, next := range src {
10+
for k, v := range next {
11+
vv, ok := dst[k]
12+
if !ok {
13+
dst[k] = v
14+
continue
15+
}
16+
17+
m1, ok1 := vv.(map[string]interface{})
18+
m2, ok2 := v.(map[string]interface{})
19+
if ok2 && ok1 {
20+
mapMerge(m1, m2)
21+
continue
22+
}
23+
1224
dst[k] = v
13-
continue
1425
}
15-
vMap, vOk := v.(map[string]interface{})
16-
vvMap, vvOk := vv.(map[string]interface{})
17-
if vOk && vvOk {
18-
return mapMerge(vvMap, vMap)
19-
}
20-
dst[k] = v
2126
}
22-
23-
return nil
2427
}

codec/map_merge_test.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
2+
* Copyright (c) 2024-2025 Mikhail Knyazhev <[email protected]>. All rights reserved.
33
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
44
*/
55

@@ -17,6 +17,8 @@ func TestUnit_mapMerge(t *testing.T) {
1717
"aa": map[string]interface{}{
1818
"bb": "cc",
1919
},
20+
"yy": 123,
21+
"ww": 123,
2022
}
2123
mapB := map[string]interface{}{
2224
"zz": "xx",
@@ -26,10 +28,15 @@ func TestUnit_mapMerge(t *testing.T) {
2628
"rr": "tt",
2729
},
2830
},
31+
"ww": map[string]interface{}{
32+
"gg": "hh",
33+
},
2934
}
3035

31-
casecheck.NoError(t, mapMerge(mapA, mapB))
36+
mapMerge(mapA, mapB)
37+
3238
casecheck.Equal(t, map[string]interface{}{
39+
"yy": 123,
3340
"zz": "xx",
3441
"qq": "ww",
3542
"aa": map[string]interface{}{
@@ -39,5 +46,8 @@ func TestUnit_mapMerge(t *testing.T) {
3946
"rr": "tt",
4047
},
4148
},
49+
"ww": map[string]interface{}{
50+
"gg": "hh",
51+
},
4252
}, mapA)
4353
}

0 commit comments

Comments
 (0)