Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/anhnmt/go-fingerprint

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/anhnmt/go-fingerprint

  • v1.0.2
  • Source
  • Go
  • Socket score

Version published
Created
Source

go-fingerprint

Server-side fingerprint library for Golang net/http

Features

  • Generate fingerprint for each browser or device

Installation

go get -u github.com/anhnmt/go-fingerprint

Usage

package main

import (
    "fmt"
    "log/slog"
    "net/http"

    "github.com/anhnmt/go-fingerprint"
)

func main() {
    mux := http.NewServeMux()

    mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fg := fingerprint.NewFingerprint(r)

        marshal, err := fg.Bytes()
        if err != nil {
            return
        }

        slog.Info("Fingerprint",
            slog.String("data", string(marshal)),
            slog.Any("headers", r.Header),
            slog.Any("remote-addr", r.RemoteAddr),
        )

        w.Header().Set("Content-Type", "application/json")
        w.Write(marshal)
    })

    addr := ":8080"
    slog.Info(fmt.Sprintf("Listening on http://localhost%s", addr))

    err := http.ListenAndServe(addr, mux)
    if err != nil {
        slog.Error(fmt.Sprintf("Error: %s", err.Error()))
    }
}

Fingerprint example:

{
    "id": "25c4164bea78a14ffedc40fe120ebecb",
    "ip_address": {
        "value": "xxx.xxx.xxx.xxx"
    },
    "user_agent": {
        "browser": {
            "name": "Chrome",
            "version": "xxx"
        },
        "os": {
            "name": "Windows",
            "version": "10.0"
        },
        "device": {
            "type": "Desktop"
        }
    }
}

License

MIT © anhnmt

FAQs

Package last updated on 24 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc