httpcontentwriter

package module
v0.0.0-...-b5da6f8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2024 License: AGPL-3.0 Imports: 2 Imported by: 1

README

HTTP Content Writer - Custom http.ResponseWriter for Dynamic Content-Type

The httpcontentwriter package provides a custom http.ResponseWriter implementation that allows you to set the content type on the first write. This can be useful in scenarios where you want to dynamically determine the content type based on the content being written.

Installation

You can install the package using the go get command:

go get -u github.com/NIR3X/httpcontentwriter

Usage

package main

import (
	"net/http"
	"github.com/NIR3X/httpcontentwriter"
)

func handler(w http.ResponseWriter, r *http.Request) {
	// Create a new HttpContentWriter instance
	contentWriter := httpcontentwriter.NewHttpContentWriter(w)

	// Your logic here, writing content to the response using contentWriter
	contentWriter.Write([]uint8("Hello, World!"))
}

func main() {
	http.HandleFunc("/", handler)
	http.ListenAndServe(":8080", nil)
}

License

GNU AGPLv3 Image

This program is Free Software: You can use, study share and improve it at your will. Specifically you can redistribute and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpContentWriter

type HttpContentWriter struct {
	// contains filtered or unexported fields
}

func NewHttpContentWriter

func NewHttpContentWriter(w http.ResponseWriter) *HttpContentWriter

func (*HttpContentWriter) Write

func (h *HttpContentWriter) Write(p []uint8) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL