Skip to content

Library provides set of middlewares for setting `Content-Type` header.

License

Notifications You must be signed in to change notification settings

furdarius/contenttype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Furdarius\Contenttype

Build Status Coverage Status Go Report Card

Library provides set of middlewares for setting Content-Type header.

Installation

With a properly configured Go toolchain:

go get -u github.com/furdarius/contenttype

Usage

package main

import (
	"fmt"
	"net/http"

	"github.com/furdarius/contenttype"
)

func main() {
	// Preferred router initialization
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(w, "Welcome to the home page!")
	})

	handler := contenttype.Middleware(mux, "application/json")
	// Also you can use predefined contenttype middlewares.
	// Available middlewares: JSON, HTML, XML, PDF, Text, OctetStream
	//
	// You can change middleware above with:
	// handler := contenttype.JSON(mux)

	http.ListenAndServe(":3000", handler)
}

Available middlewares with predefined type:

JSON

JSON middleware set header Content-Type: application/json

h := contenttype.JSON(mux)

HTML

HTML middleware set header Content-Type: text/html

h := contenttype.HTML(mux)

XML

XML middleware set header Content-Type: application/xml

h := contenttype.XML(mux)

PDF

PDF middleware set header Content-Type: application/pdf

h := contenttype.PDF(mux)

Text

Text middleware set header Content-Type: text/plain

h := contenttype.Text(mux)

OctetStream

OctetStream middleware set header Content-Type: application/octet-stream

h := contenttype.OctetStream(mux)

About

Library provides set of middlewares for setting `Content-Type` header.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages