yatwiki/AuthorHash.go

16 lines
360 B
Go

package yatwiki3
import (
"crypto/md5"
"encoding/hex"
"net/http"
"strings"
)
func Author(r *http.Request) string {
userAgentHash := md5.Sum([]byte(r.UserAgent()))
ipAddr := strings.TrimRight(strings.TrimRight(r.RemoteAddr, `0123456789`), `:`) // trim trailing port; IPv4 and IPv6-safe
return ipAddr + "-" + hex.EncodeToString(userAgentHash[:])[:6]
}