Home / File/ reader.go — gin Source File

reader.go — gin Source File

Architecture documentation for reader.go, a go file in the gin codebase. 1 imports, 0 dependents.

File go 1 imports

Entity Profile

Dependency Diagram

graph LR
  5b4e35f4_15cc_5c48_bcb2_ab9af8f70c83["reader.go"]
  0d816439_76ee_c7fb_5329_a059811a793a["io"]
  5b4e35f4_15cc_5c48_bcb2_ab9af8f70c83 --> 0d816439_76ee_c7fb_5329_a059811a793a
  style 5b4e35f4_15cc_5c48_bcb2_ab9af8f70c83 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// Copyright 2018 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 (
	"io"
	"net/http"
	"strconv"
)

// Reader contains the IO reader and its length, and custom ContentType and other headers.
type Reader struct {
	ContentType   string
	ContentLength int64
	Reader        io.Reader
	Headers       map[string]string
}

// Render (Reader) writes data with custom ContentType and headers.
func (r Reader) Render(w http.ResponseWriter) (err error) {
	r.WriteContentType(w)
	if r.ContentLength >= 0 {
		if r.Headers == nil {
			r.Headers = map[string]string{}
		}
		r.Headers["Content-Length"] = strconv.FormatInt(r.ContentLength, 10)
	}
	r.writeHeaders(w)
	_, err = io.Copy(w, r.Reader)
	return
}

// WriteContentType (Reader) writes custom ContentType.
func (r Reader) WriteContentType(w http.ResponseWriter) {
	writeContentType(w, []string{r.ContentType})
}

// writeHeaders writes headers from r.Headers into response.
func (r Reader) writeHeaders(w http.ResponseWriter) {
	header := w.Header()
	for k, v := range r.Headers {
		if header.Get(k) == "" {
			header.Set(k, v)
		}
	}
}

Types

Dependencies

  • io

Frequently Asked Questions

What does reader.go do?
reader.go is a source file in the gin codebase, written in go.
What does reader.go depend on?
reader.go imports 1 module(s): io.
Where is reader.go in the architecture?
reader.go is located at render/reader.go (directory: render).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free