-
Notifications
You must be signed in to change notification settings - Fork 1
/
http.go
83 lines (70 loc) · 1.97 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package raygun
import (
"os"
"time"
)
type Ray struct {
OccuredOn string `json:"occurredOn"`
Details Details `json:"details"`
}
type Details struct {
MachineName string `json:"machineName"`
Version string `json:"version"`
Error Error `json:"error"`
Tags []string `json:"tags"`
UserCustomData interface{} `json:"userCustomData"`
Request Request `json:"request"`
User User `json:"user"`
Context Context `json:"context"`
Client Client `json:"client"`
}
type Error struct {
Message string `json:"message"`
StackTrace StackTrace `json:"stackTrace"`
}
type Request struct {
HostName string `json:"hostName"`
URL string `json:"url"`
HTTPMethod string `json:"httpMethod"`
IPAddress string `json:"ipAddress"`
QueryString map[string]string `json:"queryString"`
Form map[string]string `json:"form"`
Headers map[string]string `json:"headers"`
}
type Client struct {
Name string `json:"name"`
Version string `json:"version"`
ClientURL string `json:"clientUrl"`
}
type User struct {
Identifier string `json:"identifier"`
}
type Context struct {
Identifier string `json:"identifier"`
}
type StackTraceElement struct {
LineNumber int `json:"lineNumber"`
PackageName string `json:"className"`
FileName string `json:"fileName"`
MethodName string `json:"methodName"`
}
type StackTrace []StackTraceElement
func (s *StackTrace) AddEntry(lineNumber int, packageName, fileName, methodName string) {
*s = append(*s, StackTraceElement{lineNumber, packageName, fileName, methodName})
}
func NewRay(msg string) Ray {
hostname, err := os.Hostname()
if err != nil {
hostname = "not available"
}
return Ray{
OccuredOn: time.Now().UTC().Format("2006-01-02T15:04:05Z"),
Details: Details{
MachineName: hostname,
Error: Error{
Message: msg,
StackTrace: GetCurrentStack(),
},
},
}
}