mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 11:36:56 +08:00
Merge pull request #28 from httprunner/dev
feat: use unique machine ID for reporting GA
This commit is contained in:
@@ -3,6 +3,7 @@ module github.com/httprunner/hrp
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1
|
||||||
github.com/getsentry/sentry-go v0.11.0
|
github.com/getsentry/sentry-go v0.11.0
|
||||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
|
||||||
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -23,11 +21,10 @@ type GAClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGAClient creates a new GAClient object with the trackingID and clientID.
|
// NewGAClient creates a new GAClient object with the trackingID and clientID.
|
||||||
func NewGAClient(trackingID string) *GAClient {
|
func NewGAClient(trackingID, clientID string) *GAClient {
|
||||||
nodeUUID, _ := uuid.NewUUID()
|
|
||||||
return &GAClient{
|
return &GAClient{
|
||||||
TrackingID: trackingID,
|
TrackingID: trackingID,
|
||||||
ClientID: nodeUUID.String(),
|
ClientID: clientID,
|
||||||
Version: "1", // constant v1
|
Version: "1", // constant v1
|
||||||
httpClient: &http.Client{
|
httpClient: &http.Client{
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
|
|||||||
+11
-1
@@ -1,5 +1,10 @@
|
|||||||
package ga
|
package ga
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/denisbrodbeck/machineid"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
trackingID = "UA-114587036-1" // Tracking ID for Google Analytics
|
trackingID = "UA-114587036-1" // Tracking ID for Google Analytics
|
||||||
)
|
)
|
||||||
@@ -7,7 +12,12 @@ const (
|
|||||||
var gaClient *GAClient
|
var gaClient *GAClient
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
gaClient = NewGAClient(trackingID)
|
clientID, err := machineid.ProtectedID("hrp")
|
||||||
|
if err != nil {
|
||||||
|
nodeUUID, _ := uuid.NewUUID()
|
||||||
|
clientID = nodeUUID.String()
|
||||||
|
}
|
||||||
|
gaClient = NewGAClient(trackingID, clientID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendEvent(e IEvent) error {
|
func SendEvent(e IEvent) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user