Skip to content

Commit

Permalink
Merge pull request #32 from rabee-inc/feature/go122
Browse files Browse the repository at this point in the history
Go122にアップデート
  • Loading branch information
aikizoku authored Mar 12, 2024
2 parents 873e388 + 80bf3bd commit 3b14cc0
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 201 deletions.
4 changes: 2 additions & 2 deletions cloudfirestore/batch_getter_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (bg *batchGetter) Delete(docRef *firestore.DocumentRef) {
delete(bg.docMap, docRef.Path)
}

func (bg *batchGetter) isAllCommitted(ctx context.Context) bool {
func (bg *batchGetter) isAllCommitted() bool {
for _, item := range bg.docMap {
if !item.committed {
return false
Expand Down Expand Up @@ -105,7 +105,7 @@ func (bg *batchGetter) commit(ctx context.Context) error {
}

func (bg *batchGetter) Commit(ctx context.Context) error {
for !bg.isAllCommitted(ctx) {
for !bg.isAllCommitted() {
if err := bg.commit(ctx); err != nil {
return err
}
Expand Down
54 changes: 27 additions & 27 deletions cloudfirestore/convertible_batch_getter_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func (cbg *convertibleBatchGetterItem[D]) RemoveOnEmpty() ConvertibleBatchGetter
}

type convertibleBatchGetter[S, D any] struct {
bg BatchGetter
items sliceutil.Slice[*convertibleBatchGetterItem[*D]]
dstMap map[string]*D
getDoc FuncGetDoc
getID FuncGetID[D]
convert FuncConvert[S, D]
BG BatchGetter
Items sliceutil.Slice[*convertibleBatchGetterItem[*D]]
DstMap map[string]*D
GetDoc FuncGetDoc
GetID FuncGetID[D]
Convert FuncConvert[S, D]
}

func NewConvertibleBatchGetter[S, D any](
Expand All @@ -64,12 +64,12 @@ func NewConvertibleBatchGetter[S, D any](
convert FuncConvert[S, D],
) ConvertibleBatchGetter[S, D] {
cbg := &convertibleBatchGetter[S, D]{
bg: bg,
dstMap: map[string]*D{},
items: []*convertibleBatchGetterItem[*D]{},
getDoc: getDoc,
getID: getID,
convert: convert,
BG: bg,
DstMap: map[string]*D{},
Items: []*convertibleBatchGetterItem[*D]{},
GetDoc: getDoc,
GetID: getID,
Convert: convert,
}

bg.OnCommit(func() {
Expand All @@ -84,18 +84,18 @@ func NewConvertibleBatchGetter[S, D any](
}

func (cbg *convertibleBatchGetter[S, D]) convertAll() {
items := cbg.items.Filter(func(item *convertibleBatchGetterItem[*D]) bool {
return !item.Converted && cbg.bg.IsCommittedItem(item.Path)
items := cbg.Items.Filter(func(item *convertibleBatchGetterItem[*D]) bool {
return !item.Converted && cbg.BG.IsCommittedItem(item.Path)
})

srcs := make([]any, len(items))

// 変換処理
for i, item := range items {
src := cbg.bg.Get(item.Path)
src := cbg.BG.Get(item.Path)
srcs[i] = src
if src != nil {
converted := cbg.convert(src.(*S))
converted := cbg.Convert(src.(*S))
if converted != nil {
*(item.Dst) = *converted
} else {
Expand All @@ -114,7 +114,7 @@ func (cbg *convertibleBatchGetter[S, D]) convertAll() {
}
item.RemoveAfter()
item.RemoveOnEmpty()
cbg.dstMap[item.Path] = item.Dst
cbg.DstMap[item.Path] = item.Dst
item.Converted = true
}
}
Expand All @@ -126,42 +126,42 @@ func (cbg *convertibleBatchGetter[S, D]) Add(ids ...string) ConvertibleBatchGett
func (cbg *convertibleBatchGetter[S, D]) Set(d *D, ids ...string) ConvertibleBatchGetterItem[*D] {
id := ""
if d != nil {
id = cbg.getID(d)
id = cbg.GetID(d)
}
return cbg.SetWithID(d, append(ids, id)...)
}

func (cbg *convertibleBatchGetter[S, D]) SetWithID(d *D, ids ...string) ConvertibleBatchGetterItem[*D] {
docRef := cbg.getDoc(ids...)
docRef := cbg.GetDoc(ids...)
data := new(S)
cbg.bg.Add(docRef, data)
cbg.BG.Add(docRef, data)

item := &convertibleBatchGetterItem[*D]{
ID: docRef.ID,
Path: docRef.Path,
Dst: d,
}
cbg.items = append(cbg.items, item)
cbg.Items = append(cbg.Items, item)
return item
}

func (cbg *convertibleBatchGetter[S, D]) Delete(ids ...string) {
docRef := cbg.getDoc(ids...)
cbg.bg.Delete(docRef)
docRef := cbg.GetDoc(ids...)
cbg.BG.Delete(docRef)
}

func (cbg *convertibleBatchGetter[S, D]) GetMap() map[string]*D {
return maps.Clone(cbg.dstMap)
return maps.Clone(cbg.DstMap)
}

func (cbg *convertibleBatchGetter[S, D]) Get(ids ...string) *D {
docRef := cbg.getDoc(ids...)
if dst, ok := cbg.dstMap[docRef.Path]; ok {
docRef := cbg.GetDoc(ids...)
if dst, ok := cbg.DstMap[docRef.Path]; ok {
return dst
}
return nil
}

func (cbg *convertibleBatchGetter[S, D]) Commit(ctx context.Context) error {
return cbg.bg.Commit(ctx)
return cbg.BG.Commit(ctx)
}
12 changes: 6 additions & 6 deletions cloudfirestore/typed_batch_getter_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ func NewTypedBatchGetter[T any](
convert = func(t *T) *T { return t }
}
cbg := &convertibleBatchGetter[T, T]{
bg: bg,
dstMap: map[string]*T{},
items: []*convertibleBatchGetterItem[*T]{},
getDoc: getDoc,
getID: getID,
convert: convert,
BG: bg,
DstMap: map[string]*T{},
Items: []*convertibleBatchGetterItem[*T]{},
GetDoc: getDoc,
GetID: getID,
Convert: convert,
}

bg.OnCommit(func() {
Expand Down
100 changes: 50 additions & 50 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
module github.com/rabee-inc/go-pkg

go 1.19
go 1.22

require (
cloud.google.com/go/bigquery v1.55.0
cloud.google.com/go/cloudtasks v1.12.1
cloud.google.com/go/firestore v1.13.0
cloud.google.com/go/pubsub v1.33.0
cloud.google.com/go/storage v1.33.0
cloud.google.com/go/bigquery v1.59.1
cloud.google.com/go/cloudtasks v1.12.6
cloud.google.com/go/firestore v1.15.0
cloud.google.com/go/pubsub v1.37.0
cloud.google.com/go/storage v1.39.1
firebase.google.com/go v3.13.0+incompatible
github.com/davecgh/go-spew v1.1.1
github.com/go-chi/chi v1.5.5
github.com/jszwec/csvutil v1.8.0
github.com/jszwec/csvutil v1.10.0
github.com/otiai10/opengraph v1.1.3
github.com/rs/xid v1.5.0
github.com/unrolled/render v1.6.0
github.com/unrolled/render v1.6.1
github.com/vincent-petithory/dataurl v1.0.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/sync v0.3.0
golang.org/x/text v0.13.0
google.golang.org/api v0.141.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
golang.org/x/sync v0.6.0
golang.org/x/text v0.14.0
google.golang.org/api v0.169.0
gopkg.in/go-playground/assert.v1 v1.2.1
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go v0.110.6 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute v1.25.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/longrunning v0.5.1 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/apache/arrow/go/v12 v12.0.0 // indirect
github.com/apache/thrift v0.16.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/longrunning v0.5.5 // indirect
github.com/apache/arrow/go/v14 v14.0.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v2.0.8+incompatible // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/flatbuffers v24.3.7+incompatible // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/klauspost/asmfmt v1.3.2 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.19.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading

0 comments on commit 3b14cc0

Please sign in to comment.