123456 |
- {
- "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>Raven-Go can be installed like any other Go library through <code class=\"docutils literal\"><span class=\"pre\">go</span> <span class=\"pre\">get</span></code>:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ go get github.com/getsentry/raven-go\n</pre></div>\n</div>\n</div>\n\n\n<div class=\"section\" id=\"configuring-the-client\">\n<h2>Configuring the Client</h2>\n<p>To use <code class=\"docutils literal\"><span class=\"pre\">raven-go</span></code>, you’ll need to import the <code class=\"docutils literal\"><span class=\"pre\">raven</span></code> package, then initilize your\nDSN globally. If you specify the <code class=\"docutils literal\"><span class=\"pre\">SENTRY_DSN</span></code> environment variable, this will be\ndone automatically for you.</p>\n<div class=\"highlight-go\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">package</span> <span style=\"color: #111111\">main</span>\n\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #e8535a\">"github.com/getsentry/raven-go"</span>\n\n<span style=\"color: #2eb0f7\">func</span> <span style=\"color: #111111\">init()</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">raven.SetDSN(</span><span style=\"color: #e8535a\">"___DSN___"</span><span style=\"color: #111111\">)</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n</div>\n\n\n<div class=\"section\" id=\"reporting-errors\">\n<h2>Reporting Errors</h2>\n<p>In Go, there are both errors and panics, and Raven can handle both. To learn more\nabout the differences, please read <a class=\"reference external\" href=\"https://blog.golang.org/error-handling-and-go\">Error handling and Go</a>.</p>\n<p>To handle normal <code class=\"docutils literal\"><span class=\"pre\">error</span></code> responses, we have two options: <code class=\"docutils literal\"><span class=\"pre\">CaptureErrorAndWait</span></code> and <code class=\"docutils literal\"><span class=\"pre\">CaptureError</span></code>. The former is a blocking call, for a case where you’d like to exit the application after reporting, and the latter is non-blocking.</p>\n<div class=\"highlight-go\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">f,</span> <span style=\"color: #111111\">err</span> <span style=\"color: #4b4f5c\">:=</span> <span style=\"color: #111111\">os.Open(</span><span style=\"color: #e8535a\">"filename.ext"</span><span style=\"color: #111111\">)</span>\n<span style=\"color: #2eb0f7\">if</span> <span style=\"color: #111111\">err</span> <span style=\"color: #4b4f5c\">!=</span> <span style=\"color: #2eb0f7\">nil</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">raven.CaptureErrorAndWait(err,</span> <span style=\"color: #2eb0f7\">nil</span><span style=\"color: #111111\">)</span>\n <span style=\"color: #111111\">log.Panic(err)</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n</div>\n\n\n<div class=\"section\" id=\"reporting-panics\">\n<h2>Reporting Panics</h2>\n<p>Capturing a panic is pretty simple as well. We just need to wrap our code in <code class=\"docutils literal\"><span class=\"pre\">CapturePanic</span></code>. <code class=\"docutils literal\"><span class=\"pre\">CapturePanic</span></code> will execute the <code class=\"docutils literal\"><span class=\"pre\">func</span></code> and if a panic happened, we will record it, and gracefully continue.</p>\n<div class=\"highlight-go\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">raven.CapturePanic(</span><span style=\"color: #2eb0f7\">func</span><span style=\"color: #111111\">()</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// do all of the scary things here</span>\n<span style=\"color: #111111\">},</span> <span style=\"color: #2eb0f7\">nil</span><span style=\"color: #111111\">)</span>\n</pre></div>\n</div>\n</div>\n",
- "link": "https://docs.getsentry.com/clients/go/",
- "id": "go",
- "name": "Go"
- }
|