Skip to content
Myr

bson.go

This file

Path

binding/bson.go

30 lines · 580 bytes · Go

Last changed by

chore(binding): upgrade bson dependency to mongo-driver v2 (#4549)Bob Dubefore adoptionba093d1

History of this file

Take it

1// Copyright 2025 Gin Core Team. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package binding67import (8	"io"9	"net/http"1011	"go.mongodb.org/mongo-driver/v2/bson"12)1314type bsonBinding struct{}1516func (bsonBinding) Name() string {17	return "bson"18}1920func (b bsonBinding) Bind(req *http.Request, obj any) error {21	buf, err := io.ReadAll(req.Body)22	if err == nil {23		err = b.BindBody(buf, obj)24	}25	return err26}2728func (bsonBinding) BindBody(body []byte, obj any) error {29	return bson.Unmarshal(body, obj)30}