bson.go
This file
Path
render/bson.go
34 lines · 790 bytes · Go
Last changed by
chore(binding): upgrade bson dependency to mongo-driver v2 (#4549)Bob Dubefore adoptionba093d1
History of this fileTake it
feat(render): add bson protocol (#4145)Laurent Caumontbefore adoptiond7776de
lines 1–9why, one step back1// 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 render67import (8 "net/http"9chore(binding): upgrade bson dependency to mongo-driver v2 (#4549)Bob Dubefore adoptionba093d1
line 10why, one step back10 "go.mongodb.org/mongo-driver/v2/bson"feat(render): add bson protocol (#4145)Laurent Caumontbefore adoptiond7776de
lines 11–34why, one step back11)1213// BSON contains the given interface object.14type BSON struct {15 Data any16}1718var bsonContentType = []string{"application/bson"}1920// Render (BSON) marshals the given interface object and writes data with custom ContentType.21func (r BSON) Render(w http.ResponseWriter) error {22 r.WriteContentType(w)2324 bytes, err := bson.Marshal(&r.Data)25 if err == nil {26 _, err = w.Write(bytes)27 }28 return err29}3031// WriteContentType (BSONBuf) writes BSONBuf ContentType.32func (r BSON) WriteContentType(w http.ResponseWriter) {33 writeContentType(w, bsonContentType)34}