go-client-hints

module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2022 License: MIT

README

go-client-hints

Install

go get -u github.com/cateiru/go-client-hints

Example

func AnnounceHandler(w http.ResponseWriter, r *http.Request) {
	announceHeaders := []string{
		headers.SecChUa,
		headers.SecChUaArch,
		headers.SecChUaPlatform,
		headers.SecChUaBitness,
		headers.SecChUaMobile,
	}

	ch.Announce(w, announceHeaders)
}

func Handler(w http.ResponseWriter, r *http.Request) {
	chUa := r.Header.Get(headers.SecChUa)
	userData := ch.ParseSecChUa(chUa)

	for brandName, version := range userData {
		fmt.Printf("BrandName: %s, version: %s", brandName, version)
	}

	isMobile := ch.ParseChUaMobile(r.Header.Get(headers.SecChUaMobile))

	switch isMobile {
	case ch.Mobile:
		fmt.Println("Mobile!")
	case ch.NoMobile:
		fmt.Println("No Mobile!")
	case ch.Unknown:
		fmt.Println("Unknown!")
	}
}

LICENSE

MIT

Directories

Path Synopsis
ch

Jump to

Keyboard shortcuts

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