Skip to content

Commit

Permalink
バージョン更新
Browse files Browse the repository at this point in the history
  • Loading branch information
aikizoku committed Feb 24, 2023
1 parent 687b7f8 commit 244e6b2
Show file tree
Hide file tree
Showing 33 changed files with 282 additions and 197 deletions.
33 changes: 15 additions & 18 deletions bigquery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,22 @@ type Client struct {
client *bigquery.Client
}

func NewClient(projectID string) *Client {
ctx := context.Background()
gOpt := option.WithGRPCDialOption(grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 1 * time.Second,
Timeout: 5 * time.Second,
PermitWithoutStream: true,
}))
client, err := bigquery.NewClient(ctx, projectID, gOpt)
if err != nil {
panic(err)
}
return &Client{client}
}

// クエリを実行し、データを取得する
func (c *Client) List(ctx context.Context, query string, limit int, cursor string, dsts interface{}) (string, error) {
func (c *Client) List(ctx context.Context, query string, limit int, cursor string, dsts any) (string, error) {
q := c.client.Query(query)
it, err := q.Read(ctx)
if err != nil {
Expand Down Expand Up @@ -56,20 +70,3 @@ func (c *Client) List(ctx context.Context, query string, limit int, cursor strin
}
return token, nil
}

// クライアントを作成する
func NewClient(projectID string) *Client {
ctx := context.Background()
gOpt := option.WithGRPCDialOption(grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 1 * time.Second,
Timeout: 5 * time.Second,
PermitWithoutStream: true,
}))
client, err := bigquery.NewClient(ctx, projectID, gOpt)
if err != nil {
panic(err)
}
return &Client{
client: client,
}
}
16 changes: 8 additions & 8 deletions cloudfirestore/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func CommitBulkWriter(ctx context.Context) (context.Context, error) {
}

// 単体取得する(tx対応)
func Get(ctx context.Context, docRef *firestore.DocumentRef, dst interface{}) (bool, error) {
func Get(ctx context.Context, docRef *firestore.DocumentRef, dst any) (bool, error) {
if docRef == nil || docRef.ID == "" || !ValidateDocumentID(docRef.ID) {
return false, nil
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func Get(ctx context.Context, docRef *firestore.DocumentRef, dst interface{}) (b
}

// 複数取得する(tx対応)
func GetMulti(ctx context.Context, cFirestore *firestore.Client, docRefs []*firestore.DocumentRef, dsts interface{}) error {
func GetMulti(ctx context.Context, cFirestore *firestore.Client, docRefs []*firestore.DocumentRef, dsts any) error {
docRefs = sliceutil.StreamOf(docRefs).
Filter(func(docRef *firestore.DocumentRef) bool {
return docRef != nil && docRef.ID != "" && ValidateDocumentID(docRef.ID)
Expand Down Expand Up @@ -157,7 +157,7 @@ func GetMulti(ctx context.Context, cFirestore *firestore.Client, docRefs []*fire
}

// クエリで単体取得する(tx対応)
func GetByQuery(ctx context.Context, query firestore.Query, dst interface{}) (bool, error) {
func GetByQuery(ctx context.Context, query firestore.Query, dst any) (bool, error) {
query = query.Limit(1)
var it *firestore.DocumentIterator
if tx := getContextTransaction(ctx); tx != nil {
Expand Down Expand Up @@ -185,7 +185,7 @@ func GetByQuery(ctx context.Context, query firestore.Query, dst interface{}) (bo
}

// クエリで複数取得する(tx対応)
func ListByQuery(ctx context.Context, query firestore.Query, dsts interface{}) error {
func ListByQuery(ctx context.Context, query firestore.Query, dsts any) error {
var it *firestore.DocumentIterator
if tx := getContextTransaction(ctx); tx != nil {
it = tx.Documents(query)
Expand Down Expand Up @@ -219,7 +219,7 @@ func ListByQuery(ctx context.Context, query firestore.Query, dsts interface{}) e
}

// クエリで複数取得する(ページング)
func ListByQueryCursor(ctx context.Context, query firestore.Query, limit int, cursor *firestore.DocumentSnapshot, dsts interface{}) (*firestore.DocumentSnapshot, error) {
func ListByQueryCursor(ctx context.Context, query firestore.Query, limit int, cursor *firestore.DocumentSnapshot, dsts any) (*firestore.DocumentSnapshot, error) {
if cursor != nil {
query = query.StartAfter(cursor)
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func ListByQueryCursor(ctx context.Context, query firestore.Query, limit int, cu
}

// 作成する(tx, bw対応)
func Create(ctx context.Context, colRef *firestore.CollectionRef, src interface{}) error {
func Create(ctx context.Context, colRef *firestore.CollectionRef, src any) error {
// 不正なIDがないかチェック
if !ValidateCollectionRef(colRef) {
return errors.New("Invalid Collection Path: " + colRef.Path)
Expand Down Expand Up @@ -298,7 +298,7 @@ func Create(ctx context.Context, colRef *firestore.CollectionRef, src interface{
}

// 更新する(tx, bw対応)
func Update(ctx context.Context, docRef *firestore.DocumentRef, kv map[string]interface{}) error {
func Update(ctx context.Context, docRef *firestore.DocumentRef, kv map[string]any) error {
srcs := []firestore.Update{}
for k, v := range kv {
src := firestore.Update{Path: k, Value: v}
Expand Down Expand Up @@ -327,7 +327,7 @@ func Update(ctx context.Context, docRef *firestore.DocumentRef, kv map[string]in
}

// 上書きする(tx, bw対応)
func Set(ctx context.Context, docRef *firestore.DocumentRef, src interface{}) error {
func Set(ctx context.Context, docRef *firestore.DocumentRef, src any) error {
// 不正なIDがないかチェック
if !ValidateDocumentRef(docRef) {
return errors.New("Invalid Document Path: " + docRef.Path)
Expand Down
4 changes: 2 additions & 2 deletions cloudfirestore/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"cloud.google.com/go/firestore"
)

func setDocByDst(dst interface{}, ref *firestore.DocumentRef) {
func setDocByDst(dst any, ref *firestore.DocumentRef) {
rv := reflect.Indirect(reflect.ValueOf(dst))
rt := rv.Type()
if rt.Kind() == reflect.Struct {
Expand Down Expand Up @@ -42,7 +42,7 @@ func setDocByDsts(rv reflect.Value, rt reflect.Type, ref *firestore.DocumentRef)
}
}

func setEmptyBySlice(dst interface{}) {
func setEmptyBySlice(dst any) {
rv := reflect.Indirect(reflect.ValueOf(dst))
rt := rv.Type()
if rt.Kind() == reflect.Struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudpubsub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewClient(projectID string) *Client {
func (c *Client) Publish(
ctx context.Context,
topicID string,
msg interface{},
msg any,
) error {
bMsg, err := json.Marshal(msg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cloudtasks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewClient(
}

// リクエストをEnqueueする
func (c *Client) AddTask(ctx context.Context, queue string, path string, params interface{}) error {
func (c *Client) AddTask(ctx context.Context, queue string, path string, params any) error {
headers := map[string]string{
"Content-Type": "application/json",
"Authorization": c.authToken,
Expand Down
8 changes: 4 additions & 4 deletions csv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// レスポンス形式に変換する
func ToResponse(ctx context.Context, srcs interface{}) ([][]string, error) {
func ToResponse(ctx context.Context, srcs any) ([][]string, error) {
bytes, err := csvutil.Marshal(srcs)
if err != nil {
log.Error(ctx, err)
Expand All @@ -32,7 +32,7 @@ func ToResponse(ctx context.Context, srcs interface{}) ([][]string, error) {
}

// URLからCSVデータを取得する
func GetByURL(ctx context.Context, url string, dsts interface{}) error {
func GetByURL(ctx context.Context, url string, dsts any) error {
status, body, err := httpclient.Get(ctx, url, nil)
if err != nil {
log.Error(ctx, err)
Expand All @@ -51,7 +51,7 @@ func GetByURL(ctx context.Context, url string, dsts interface{}) error {
}

// 文字列からCSVデータを取得する
func GetByStr(ctx context.Context, str string, dsts interface{}) error {
func GetByStr(ctx context.Context, str string, dsts any) error {
bytes := stringutil.ToBytes(str)
err := GetByBytes(ctx, bytes, dsts)
if err != nil {
Expand All @@ -62,7 +62,7 @@ func GetByStr(ctx context.Context, str string, dsts interface{}) error {
}

// バイト列からCSVデータを取得する
func GetByBytes(ctx context.Context, bytes []byte, dsts interface{}) error {
func GetByBytes(ctx context.Context, bytes []byte, dsts any) error {
err := csvutil.Unmarshal(bytes, dsts)
if err != nil {
log.Error(ctx, err)
Expand Down
6 changes: 3 additions & 3 deletions firebaseauth/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func GetUserID(ctx context.Context) string {
}

// FirebaseAuthのJWTClaimsの値を取得
func GetClaims(ctx context.Context) (map[string]interface{}, bool) {
func GetClaims(ctx context.Context) (map[string]any, bool) {
if dst := ctx.Value(claimsContextKey); dst != nil {
return dst.(map[string]interface{}), true
return dst.(map[string]any), true
}
return nil, false
}
Expand All @@ -42,6 +42,6 @@ func setUserID(ctx context.Context, userID string) context.Context {
return context.WithValue(ctx, userIDContextKey, userID)
}

func setClaims(ctx context.Context, claims map[string]interface{}) context.Context {
func setClaims(ctx context.Context, claims map[string]any) context.Context {
return context.WithValue(ctx, claimsContextKey, claims)
}
4 changes: 2 additions & 2 deletions firebaseauth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ type Service interface {
Authentication(
ctx context.Context,
ah string,
) (string, map[string]interface{}, error)
) (string, map[string]any, error)

SetCustomClaims(
ctx context.Context,
userID string,
claims map[string]interface{},
claims map[string]any,
) error
}
8 changes: 4 additions & 4 deletions firebaseauth/service_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

type serviceDebug struct {
sFirebaseAuth Service
dummyClaims map[string]interface{}
dummyClaims map[string]any
}

func NewServiceDebug(cFirebaseAuth *auth.Client, dummyClaims map[string]interface{}) Service {
func NewServiceDebug(cFirebaseAuth *auth.Client, dummyClaims map[string]any) Service {
sFirebaseAuth := NewService(cFirebaseAuth)
return &serviceDebug{
sFirebaseAuth,
Expand All @@ -20,7 +20,7 @@ func NewServiceDebug(cFirebaseAuth *auth.Client, dummyClaims map[string]interfac
}

// 認証を行う
func (s *serviceDebug) Authentication(ctx context.Context, ah string) (string, map[string]interface{}, error) {
func (s *serviceDebug) Authentication(ctx context.Context, ah string) (string, map[string]any, error) {
// AuthorizationHeaderからUserが取得できたらデバッグリクエストと判定する
if user := getUserByAuthHeader(ah); user != "" {
return user, s.dummyClaims, nil
Expand All @@ -29,7 +29,7 @@ func (s *serviceDebug) Authentication(ctx context.Context, ah string) (string, m
}

// カスタムClaimsを設定
func (s *serviceDebug) SetCustomClaims(ctx context.Context, userID string, claims map[string]interface{}) error {
func (s *serviceDebug) SetCustomClaims(ctx context.Context, userID string, claims map[string]any) error {
// AuthorizationHeaderからUserが取得できたらデバッグリクエストと判定する
ah := getAuthHeader(ctx)
if getUserByAuthHeader(ah) != "" {
Expand Down
4 changes: 2 additions & 2 deletions firebaseauth/service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewService(cFirebaseAuth *auth.Client) Service {
}

// 認証を行う
func (s *service) Authentication(ctx context.Context, ah string) (string, map[string]interface{}, error) {
func (s *service) Authentication(ctx context.Context, ah string) (string, map[string]any, error) {
token := getTokenByAuthHeader(ah)
if token == "" {
err := log.Warninge(ctx, "token empty error")
Expand All @@ -32,7 +32,7 @@ func (s *service) Authentication(ctx context.Context, ah string) (string, map[st
}

// カスタムClaimsを設定
func (s *service) SetCustomClaims(ctx context.Context, userID string, claims map[string]interface{}) error {
func (s *service) SetCustomClaims(ctx context.Context, userID string, claims map[string]any) error {
err := s.cFirebaseAuth.SetCustomUserClaims(ctx, userID, claims)
if err != nil {
log.Error(ctx, err)
Expand Down
4 changes: 2 additions & 2 deletions flexiblecsv/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CSVWriter interface {
}

type StreamMarshaler interface {
Marshal(row interface{}) error
Marshal(row any) error
Flush() error
}

Expand All @@ -33,7 +33,7 @@ func MarshalFileAsStream(file *os.File) StreamMarshaler {
return NewStreamMarshaler(csv.NewWriter(file))
}

func (s *streamMarshaler) Marshal(row interface{}) error {
func (s *streamMarshaler) Marshal(row any) error {
if s.isFirst {
// Headerを取得
header := []string{}
Expand Down
6 changes: 3 additions & 3 deletions flexiblecsv/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"reflect"
)

func MarshalString(srcs interface{}) (string, error) {
func MarshalString(srcs any) (string, error) {
records, err := marshal(srcs)
if err != nil {
return "", err
Expand All @@ -27,7 +27,7 @@ func MarshalString(srcs interface{}) (string, error) {
return buf.String(), nil
}

func MarshalFile(srcs interface{}, file *os.File) error {
func MarshalFile(srcs any, file *os.File) error {
records, err := marshal(srcs)
if err != nil {
return err
Expand All @@ -44,7 +44,7 @@ func MarshalFile(srcs interface{}, file *os.File) error {
return nil
}

func marshal(srcs interface{}) ([][]string, error) {
func marshal(srcs any) ([][]string, error) {
// Pointerの場合は参照先を取得
rvs := reflect.Indirect(reflect.ValueOf(srcs))

Expand Down
50 changes: 33 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/rabee-inc/go-pkg
go 1.19

require (
cloud.google.com/go/bigquery v1.44.0
cloud.google.com/go/cloudtasks v1.8.0
cloud.google.com/go/bigquery v1.47.0
cloud.google.com/go/cloudtasks v1.9.0
cloud.google.com/go/firestore v1.9.0
cloud.google.com/go/pubsub v1.27.1
cloud.google.com/go/storage v1.28.1
cloud.google.com/go/pubsub v1.28.0
cloud.google.com/go/storage v1.29.0
firebase.google.com/go v3.13.0+incompatible
github.com/davecgh/go-spew v1.1.1
github.com/go-chi/chi v1.5.4
Expand All @@ -17,37 +17,53 @@ require (
github.com/unrolled/render v1.5.0
github.com/vincent-petithory/dataurl v1.0.0
golang.org/x/sync v0.1.0
golang.org/x/text v0.6.0
google.golang.org/api v0.103.0
google.golang.org/grpc v1.51.0
golang.org/x/text v0.7.0
google.golang.org/api v0.110.0
google.golang.org/grpc v1.53.0
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go v0.108.0 // indirect
cloud.google.com/go/compute v1.15.1 // indirect
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.10.0 // indirect
cloud.google.com/go/longrunning v0.4.0 // indirect
cloud.google.com/go/iam v0.12.0 // indirect
cloud.google.com/go/longrunning v0.4.1 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/apache/arrow/go/v10 v10.0.1 // indirect
github.com/apache/thrift v0.18.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v23.1.21+incompatible // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/klauspost/asmfmt v1.3.2 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // 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.17 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.6.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-20221205194025-8222ab48f5fc // indirect
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
)
Loading

0 comments on commit 244e6b2

Please sign in to comment.