https://github.com/cateiru/go-client-hints
Go package for Client-Hint parser
https://github.com/cateiru/go-client-hints
client-hints go
Last synced: 10 months ago
JSON representation
Go package for Client-Hint parser
- Host: GitHub
- URL: https://github.com/cateiru/go-client-hints
- Owner: cateiru
- License: mit
- Created: 2022-03-09T08:08:41.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T09:08:46.000Z (almost 3 years ago)
- Last Synced: 2025-02-17T08:26:18.823Z (about 1 year ago)
- Topics: client-hints, go
- Language: Go
- Homepage: https://pkg.go.dev/github.com/cateiru/go-client-hints/v2
- Size: 32.2 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/cateiru/go-client-hints/v2)
[](https://github.com/cateiru/go-client-hints/actions/workflows/go.yml)
# Go Client Hints
## Install
```bash
go get -u github.com/cateiru/go-client-hints/v2
```
## Parse Client Hints
```go
import (
"fmt"
"net/http"
goclienthints "github.com/cateiru/go-client-hints/v2"
)
func Handler(w http.ResponseWriter, r *http.Request) {
clientHints, err := goclienthints.Parse(&r.Header)
if err != nil {
return
}
// Sec-CH-UA field
fmt.Println("Brand: ", clientHints.Brand.Brand)
fmt.Println("Brand Version: ", clientHints.BrandVersion)
fmt.Println("Brands: ", clientHints.Brands)
// Sec-Ch-Ua-Platform filed
fmt.Println("Platform: ", clientHints.Platform)
// Sec-CH-UA-Platform-Version filed
fmt.Println("Platform Version: ", clientHints.PlatformVersion)
// Sec-Ch-Ua-Mobile filed
fmt.Println("IsMobile: ", clientHints.IsMobile)
// Sec-CH-UA-Arch filed
fmt.Println("Arch: ", clientHints.Architecture)
// Sec-CH-UA-Bitness filed
fmt.Println("Bitness: ", clientHints.Bitness)
// Sec-CH-UA-Model filed
fmt.Println("Model: ", clientHints.Model)
// Sec-Ch-Ua-Full-Version filed
fmt.Println("Full Version: ", clientHints.FullVersion)
}
```
## Check Support Client Hints
```go
import (
"net/http"
clienthint "github.com/cateiru/go-client-hints/v2"
)
func Handler2(w http.ResponseWriter, r *http.Request) {
isSupport := clienthint.IsSupportClientHints(&r.Header)
if isSupport {
// ...do something
}
}
```
## LICENSE
[MIT](./LICENSE)