ReadBsonDocumentFromBody로 교체

This commit is contained in:
2023-09-05 15:02:06 +09:00
parent 7489fa657a
commit 3a3839a461

View File

@ -26,6 +26,7 @@ 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"
)
@ -429,10 +430,12 @@ func ReadStringFormValue(r url.Values, key string) (string, bool) {
return strval, len(strval) > 0
}
func ReadJsonDocumentFromBody(r io.Reader) (out map[string]any) {
dec := json.NewDecoder(r)
dec.Decode(&out)
return
func ReadBsonDocumentFromBody[T any](r io.Reader, out *T) error {
bt, err := io.ReadAll(r)
if err != nil {
return err
}
return bson.Unmarshal(bt, out)
}
func DotStringToTimestamp(tv string) primitive.Timestamp {