diff options
Diffstat (limited to 'vendor/github.com/gin-gonic/gin/render')
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/data.go | 25 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/html.go | 92 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/json.go | 190 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/msgpack.go | 43 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/protobuf.go | 36 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/reader.go | 48 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/redirect.go | 29 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/render.go | 41 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/text.go | 41 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/toml.go | 36 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/xml.go | 28 | ||||
-rw-r--r-- | vendor/github.com/gin-gonic/gin/render/yaml.go | 36 |
12 files changed, 0 insertions, 645 deletions
diff --git a/vendor/github.com/gin-gonic/gin/render/data.go b/vendor/github.com/gin-gonic/gin/render/data.go deleted file mode 100644 index a653ea309..000000000 --- a/vendor/github.com/gin-gonic/gin/render/data.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. 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" - -// Data contains ContentType and bytes data. -type Data struct { - ContentType string - Data []byte -} - -// Render (Data) writes data with custom ContentType. -func (r Data) Render(w http.ResponseWriter) (err error) { - r.WriteContentType(w) - _, err = w.Write(r.Data) - return -} - -// WriteContentType (Data) writes custom ContentType. -func (r Data) WriteContentType(w http.ResponseWriter) { - writeContentType(w, []string{r.ContentType}) -} diff --git a/vendor/github.com/gin-gonic/gin/render/html.go b/vendor/github.com/gin-gonic/gin/render/html.go deleted file mode 100644 index c308408d2..000000000 --- a/vendor/github.com/gin-gonic/gin/render/html.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. 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 ( - "html/template" - "net/http" -) - -// Delims represents a set of Left and Right delimiters for HTML template rendering. -type Delims struct { - // Left delimiter, defaults to {{. - Left string - // Right delimiter, defaults to }}. - Right string -} - -// HTMLRender interface is to be implemented by HTMLProduction and HTMLDebug. -type HTMLRender interface { - // Instance returns an HTML instance. - Instance(string, any) Render -} - -// HTMLProduction contains template reference and its delims. -type HTMLProduction struct { - Template *template.Template - Delims Delims -} - -// HTMLDebug contains template delims and pattern and function with file list. -type HTMLDebug struct { - Files []string - Glob string - Delims Delims - FuncMap template.FuncMap -} - -// HTML contains template reference and its name with given interface object. -type HTML struct { - Template *template.Template - Name string - Data any -} - -var htmlContentType = []string{"text/html; charset=utf-8"} - -// Instance (HTMLProduction) returns an HTML instance which it realizes Render interface. -func (r HTMLProduction) Instance(name string, data any) Render { - return HTML{ - Template: r.Template, - Name: name, - Data: data, - } -} - -// Instance (HTMLDebug) returns an HTML instance which it realizes Render interface. -func (r HTMLDebug) Instance(name string, data any) Render { - return HTML{ - Template: r.loadTemplate(), - Name: name, - Data: data, - } -} -func (r HTMLDebug) loadTemplate() *template.Template { - if r.FuncMap == nil { - r.FuncMap = template.FuncMap{} - } - if len(r.Files) > 0 { - return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFiles(r.Files...)) - } - if r.Glob != "" { - return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseGlob(r.Glob)) - } - panic("the HTML debug render was created without files or glob pattern") -} - -// Render (HTML) executes template and writes its result with custom ContentType for response. -func (r HTML) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - - if r.Name == "" { - return r.Template.Execute(w, r.Data) - } - return r.Template.ExecuteTemplate(w, r.Name, r.Data) -} - -// WriteContentType (HTML) writes HTML ContentType. -func (r HTML) WriteContentType(w http.ResponseWriter) { - writeContentType(w, htmlContentType) -} diff --git a/vendor/github.com/gin-gonic/gin/render/json.go b/vendor/github.com/gin-gonic/gin/render/json.go deleted file mode 100644 index fc8dea453..000000000 --- a/vendor/github.com/gin-gonic/gin/render/json.go +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. 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 ( - "bytes" - "fmt" - "html/template" - "net/http" - - "github.com/gin-gonic/gin/internal/bytesconv" - "github.com/gin-gonic/gin/internal/json" -) - -// JSON contains the given interface object. -type JSON struct { - Data any -} - -// IndentedJSON contains the given interface object. -type IndentedJSON struct { - Data any -} - -// SecureJSON contains the given interface object and its prefix. -type SecureJSON struct { - Prefix string - Data any -} - -// JsonpJSON contains the given interface object its callback. -type JsonpJSON struct { - Callback string - Data any -} - -// AsciiJSON contains the given interface object. -type AsciiJSON struct { - Data any -} - -// PureJSON contains the given interface object. -type PureJSON struct { - Data any -} - -var ( - jsonContentType = []string{"application/json; charset=utf-8"} - jsonpContentType = []string{"application/javascript; charset=utf-8"} - jsonASCIIContentType = []string{"application/json"} -) - -// Render (JSON) writes data with custom ContentType. -func (r JSON) Render(w http.ResponseWriter) error { - return WriteJSON(w, r.Data) -} - -// WriteContentType (JSON) writes JSON ContentType. -func (r JSON) WriteContentType(w http.ResponseWriter) { - writeContentType(w, jsonContentType) -} - -// WriteJSON marshals the given interface object and writes it with custom ContentType. -func WriteJSON(w http.ResponseWriter, obj any) error { - writeContentType(w, jsonContentType) - jsonBytes, err := json.Marshal(obj) - if err != nil { - return err - } - _, err = w.Write(jsonBytes) - return err -} - -// Render (IndentedJSON) marshals the given interface object and writes it with custom ContentType. -func (r IndentedJSON) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - jsonBytes, err := json.MarshalIndent(r.Data, "", " ") - if err != nil { - return err - } - _, err = w.Write(jsonBytes) - return err -} - -// WriteContentType (IndentedJSON) writes JSON ContentType. -func (r IndentedJSON) WriteContentType(w http.ResponseWriter) { - writeContentType(w, jsonContentType) -} - -// Render (SecureJSON) marshals the given interface object and writes it with custom ContentType. -func (r SecureJSON) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - jsonBytes, err := json.Marshal(r.Data) - if err != nil { - return err - } - // if the jsonBytes is array values - if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes, - bytesconv.StringToBytes("]")) { - if _, err = w.Write(bytesconv.StringToBytes(r.Prefix)); err != nil { - return err - } - } - _, err = w.Write(jsonBytes) - return err -} - -// WriteContentType (SecureJSON) writes JSON ContentType. -func (r SecureJSON) WriteContentType(w http.ResponseWriter) { - writeContentType(w, jsonContentType) -} - -// Render (JsonpJSON) marshals the given interface object and writes it and its callback with custom ContentType. -func (r JsonpJSON) Render(w http.ResponseWriter) (err error) { - r.WriteContentType(w) - ret, err := json.Marshal(r.Data) - if err != nil { - return err - } - - if r.Callback == "" { - _, err = w.Write(ret) - return err - } - - callback := template.JSEscapeString(r.Callback) - if _, err = w.Write(bytesconv.StringToBytes(callback)); err != nil { - return err - } - - if _, err = w.Write(bytesconv.StringToBytes("(")); err != nil { - return err - } - - if _, err = w.Write(ret); err != nil { - return err - } - - if _, err = w.Write(bytesconv.StringToBytes(");")); err != nil { - return err - } - - return nil -} - -// WriteContentType (JsonpJSON) writes Javascript ContentType. -func (r JsonpJSON) WriteContentType(w http.ResponseWriter) { - writeContentType(w, jsonpContentType) -} - -// Render (AsciiJSON) marshals the given interface object and writes it with custom ContentType. -func (r AsciiJSON) Render(w http.ResponseWriter) (err error) { - r.WriteContentType(w) - ret, err := json.Marshal(r.Data) - if err != nil { - return err - } - - var buffer bytes.Buffer - for _, r := range bytesconv.BytesToString(ret) { - cvt := string(r) - if r >= 128 { - cvt = fmt.Sprintf("\\u%04x", int64(r)) - } - buffer.WriteString(cvt) - } - - _, err = w.Write(buffer.Bytes()) - return err -} - -// WriteContentType (AsciiJSON) writes JSON ContentType. -func (r AsciiJSON) WriteContentType(w http.ResponseWriter) { - writeContentType(w, jsonASCIIContentType) -} - -// Render (PureJSON) writes custom ContentType and encodes the given interface object. -func (r PureJSON) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - encoder := json.NewEncoder(w) - encoder.SetEscapeHTML(false) - return encoder.Encode(r.Data) -} - -// WriteContentType (PureJSON) writes custom ContentType. -func (r PureJSON) WriteContentType(w http.ResponseWriter) { - writeContentType(w, jsonContentType) -} diff --git a/vendor/github.com/gin-gonic/gin/render/msgpack.go b/vendor/github.com/gin-gonic/gin/render/msgpack.go deleted file mode 100644 index d1d8e84b0..000000000 --- a/vendor/github.com/gin-gonic/gin/render/msgpack.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 Manu Martinez-Almeida. All rights reserved. -// Use of this source code is governed by a MIT style -// license that can be found in the LICENSE file. - -//go:build !nomsgpack - -package render - -import ( - "net/http" - - "github.com/ugorji/go/codec" -) - -// Check interface implemented here to support go build tag nomsgpack. -// See: https://github.com/gin-gonic/gin/pull/1852/ -var ( - _ Render = MsgPack{} -) - -// MsgPack contains the given interface object. -type MsgPack struct { - Data any -} - -var msgpackContentType = []string{"application/msgpack; charset=utf-8"} - -// WriteContentType (MsgPack) writes MsgPack ContentType. -func (r MsgPack) WriteContentType(w http.ResponseWriter) { - writeContentType(w, msgpackContentType) -} - -// Render (MsgPack) encodes the given interface object and writes data with custom ContentType. -func (r MsgPack) Render(w http.ResponseWriter) error { - return WriteMsgPack(w, r.Data) -} - -// WriteMsgPack writes MsgPack ContentType and encodes the given interface object. -func WriteMsgPack(w http.ResponseWriter, obj any) error { - writeContentType(w, msgpackContentType) - var mh codec.MsgpackHandle - return codec.NewEncoder(w, &mh).Encode(obj) -} diff --git a/vendor/github.com/gin-gonic/gin/render/protobuf.go b/vendor/github.com/gin-gonic/gin/render/protobuf.go deleted file mode 100644 index 9331c4058..000000000 --- a/vendor/github.com/gin-gonic/gin/render/protobuf.go +++ /dev/null @@ -1,36 +0,0 @@ -// 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 ( - "net/http" - - "google.golang.org/protobuf/proto" -) - -// ProtoBuf contains the given interface object. -type ProtoBuf struct { - Data any -} - -var protobufContentType = []string{"application/x-protobuf"} - -// Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType. -func (r ProtoBuf) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - - bytes, err := proto.Marshal(r.Data.(proto.Message)) - if err != nil { - return err - } - - _, err = w.Write(bytes) - return err -} - -// WriteContentType (ProtoBuf) writes ProtoBuf ContentType. -func (r ProtoBuf) WriteContentType(w http.ResponseWriter) { - writeContentType(w, protobufContentType) -} diff --git a/vendor/github.com/gin-gonic/gin/render/reader.go b/vendor/github.com/gin-gonic/gin/render/reader.go deleted file mode 100644 index 5752d8d85..000000000 --- a/vendor/github.com/gin-gonic/gin/render/reader.go +++ /dev/null @@ -1,48 +0,0 @@ -// 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, r.Headers) - _, 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 custom Header. -func (r Reader) writeHeaders(w http.ResponseWriter, headers map[string]string) { - header := w.Header() - for k, v := range headers { - if header.Get(k) == "" { - header.Set(k, v) - } - } -} diff --git a/vendor/github.com/gin-gonic/gin/render/redirect.go b/vendor/github.com/gin-gonic/gin/render/redirect.go deleted file mode 100644 index 70e3a47e8..000000000 --- a/vendor/github.com/gin-gonic/gin/render/redirect.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. 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 ( - "fmt" - "net/http" -) - -// Redirect contains the http request reference and redirects status code and location. -type Redirect struct { - Code int - Request *http.Request - Location string -} - -// Render (Redirect) redirects the http request to new location and writes redirect response. -func (r Redirect) Render(w http.ResponseWriter) error { - if (r.Code < http.StatusMultipleChoices || r.Code > http.StatusPermanentRedirect) && r.Code != http.StatusCreated { - panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code)) - } - http.Redirect(w, r.Request, r.Location, r.Code) - return nil -} - -// WriteContentType (Redirect) don't write any ContentType. -func (r Redirect) WriteContentType(http.ResponseWriter) {} diff --git a/vendor/github.com/gin-gonic/gin/render/render.go b/vendor/github.com/gin-gonic/gin/render/render.go deleted file mode 100644 index 4bdcfa232..000000000 --- a/vendor/github.com/gin-gonic/gin/render/render.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. 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" - -// Render interface is to be implemented by JSON, XML, HTML, YAML and so on. -type Render interface { - // Render writes data with custom ContentType. - Render(http.ResponseWriter) error - // WriteContentType writes custom ContentType. - WriteContentType(w http.ResponseWriter) -} - -var ( - _ Render = (*JSON)(nil) - _ Render = (*IndentedJSON)(nil) - _ Render = (*SecureJSON)(nil) - _ Render = (*JsonpJSON)(nil) - _ Render = (*XML)(nil) - _ Render = (*String)(nil) - _ Render = (*Redirect)(nil) - _ Render = (*Data)(nil) - _ Render = (*HTML)(nil) - _ HTMLRender = (*HTMLDebug)(nil) - _ HTMLRender = (*HTMLProduction)(nil) - _ Render = (*YAML)(nil) - _ Render = (*Reader)(nil) - _ Render = (*AsciiJSON)(nil) - _ Render = (*ProtoBuf)(nil) - _ Render = (*TOML)(nil) -) - -func writeContentType(w http.ResponseWriter, value []string) { - header := w.Header() - if val := header["Content-Type"]; len(val) == 0 { - header["Content-Type"] = value - } -} diff --git a/vendor/github.com/gin-gonic/gin/render/text.go b/vendor/github.com/gin-gonic/gin/render/text.go deleted file mode 100644 index 77eafdfd8..000000000 --- a/vendor/github.com/gin-gonic/gin/render/text.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. 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 ( - "fmt" - "net/http" - - "github.com/gin-gonic/gin/internal/bytesconv" -) - -// String contains the given interface object slice and its format. -type String struct { - Format string - Data []any -} - -var plainContentType = []string{"text/plain; charset=utf-8"} - -// Render (String) writes data with custom ContentType. -func (r String) Render(w http.ResponseWriter) error { - return WriteString(w, r.Format, r.Data) -} - -// WriteContentType (String) writes Plain ContentType. -func (r String) WriteContentType(w http.ResponseWriter) { - writeContentType(w, plainContentType) -} - -// WriteString writes data according to its format and write custom ContentType. -func WriteString(w http.ResponseWriter, format string, data []any) (err error) { - writeContentType(w, plainContentType) - if len(data) > 0 { - _, err = fmt.Fprintf(w, format, data...) - return - } - _, err = w.Write(bytesconv.StringToBytes(format)) - return -} diff --git a/vendor/github.com/gin-gonic/gin/render/toml.go b/vendor/github.com/gin-gonic/gin/render/toml.go deleted file mode 100644 index 40f044c88..000000000 --- a/vendor/github.com/gin-gonic/gin/render/toml.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2022 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" - - "github.com/pelletier/go-toml/v2" -) - -// TOML contains the given interface object. -type TOML struct { - Data any -} - -var TOMLContentType = []string{"application/toml; charset=utf-8"} - -// Render (TOML) marshals the given interface object and writes data with custom ContentType. -func (r TOML) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - - bytes, err := toml.Marshal(r.Data) - if err != nil { - return err - } - - _, err = w.Write(bytes) - return err -} - -// WriteContentType (TOML) writes TOML ContentType for response. -func (r TOML) WriteContentType(w http.ResponseWriter) { - writeContentType(w, TOMLContentType) -} diff --git a/vendor/github.com/gin-gonic/gin/render/xml.go b/vendor/github.com/gin-gonic/gin/render/xml.go deleted file mode 100644 index 6af890179..000000000 --- a/vendor/github.com/gin-gonic/gin/render/xml.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. 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 ( - "encoding/xml" - "net/http" -) - -// XML contains the given interface object. -type XML struct { - Data any -} - -var xmlContentType = []string{"application/xml; charset=utf-8"} - -// Render (XML) encodes the given interface object and writes data with custom ContentType. -func (r XML) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - return xml.NewEncoder(w).Encode(r.Data) -} - -// WriteContentType (XML) writes XML ContentType for response. -func (r XML) WriteContentType(w http.ResponseWriter) { - writeContentType(w, xmlContentType) -} diff --git a/vendor/github.com/gin-gonic/gin/render/yaml.go b/vendor/github.com/gin-gonic/gin/render/yaml.go deleted file mode 100644 index 042bb821d..000000000 --- a/vendor/github.com/gin-gonic/gin/render/yaml.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. 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" - - "gopkg.in/yaml.v3" -) - -// YAML contains the given interface object. -type YAML struct { - Data any -} - -var yamlContentType = []string{"application/yaml; charset=utf-8"} - -// Render (YAML) marshals the given interface object and writes data with custom ContentType. -func (r YAML) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - - bytes, err := yaml.Marshal(r.Data) - if err != nil { - return err - } - - _, err = w.Write(bytes) - return err -} - -// WriteContentType (YAML) writes YAML ContentType for response. -func (r YAML) WriteContentType(w http.ResponseWriter) { - writeContentType(w, yamlContentType) -} |