mirror of
https://github.com/gin-gonic/gin.git
synced 2026-04-11 14:11:46 +08:00
* render: add PDF renderer and tests * render: update PDF renderer copyright header * test: add PDF rendering tests including 204 No Content in context_test.go
27 lines
651 B
Go
27 lines
651 B
Go
// Copyright 2026 Gin Core Team. All rights reserved.
|
|
// Use of this source code is governed by a MIT style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package render
|
|
|
|
import "net/http"
|
|
|
|
// PDF contains the given PDF binary data.
|
|
type PDF struct {
|
|
Data []byte
|
|
}
|
|
|
|
var pdfContentType = []string{"application/pdf"}
|
|
|
|
// Render (PDF) writes PDF data with custom ContentType.
|
|
func (r PDF) Render(w http.ResponseWriter) error {
|
|
r.WriteContentType(w)
|
|
_, err := w.Write(r.Data)
|
|
return err
|
|
}
|
|
|
|
// WriteContentType (PDF) writes PDF ContentType for response.
|
|
func (r PDF) WriteContentType(w http.ResponseWriter) {
|
|
writeContentType(w, pdfContentType)
|
|
}
|