안쓰는 코드 정리 및 bson을 json으로 통일. 추후 gob으로 변경 예정

This commit is contained in:
2023-09-08 15:26:30 +09:00
parent 3603c0386b
commit 46ce5f0989
5 changed files with 12 additions and 289 deletions

View File

@ -2,6 +2,7 @@ package gocommon
import (
"context"
"encoding/gob"
"encoding/json"
"errors"
"fmt"
@ -26,7 +27,6 @@ import (
"repositories.action2quare.com/ayo/gocommon/logger"
"github.com/pires/go-proxyproto"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
@ -430,12 +430,17 @@ func ReadStringFormValue(r url.Values, key string) (string, bool) {
return strval, len(strval) > 0
}
func ReadBsonDocumentFromBody[T any](r io.Reader, out *T) error {
func DecodeGob[T any](r io.Reader, out *T) error {
dec := gob.NewDecoder(r)
return dec.Decode(out)
}
func ReadJsonDocumentFromBody[T any](r io.Reader, out *T) error {
bt, err := io.ReadAll(r)
if err != nil {
return err
}
return bson.Unmarshal(bt, out)
return json.Unmarshal(bt, out)
}
func DotStringToTimestamp(tv string) primitive.Timestamp {