Documentation ¶
Overview ¶
Example ¶
ReplaceGlobals(Init(os.Getenv("BEARER_SECRETKEY"))) // perform request resp, err := http.Get("...") if err != nil { panic(err) } fmt.Println("resp", resp)
Output:
Example (Advanced) ¶
logger, _ := zap.NewDevelopment() ctx, cancel := context.WithCancel(context.Background()) defer cancel() agent := &Agent{ SecretKey: os.Getenv("BEARER_SECRETKEY"), Logger: logger, Transport: http.DefaultTransport, Context: ctx, } defer agent.Flush() client := &http.Client{Transport: agent} // perform request resp, err := client.Get("...") if err != nil { panic(err) } fmt.Println("resp", resp)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrBlockedDomain is raised when your program tries to make requests to a blacklisted domain. ErrBlockedDomain = errors.New("bearer: blocked domain") )
Functions ¶
func ReplaceGlobals ¶
func ReplaceGlobals(n http.RoundTripper) func()
ReplaceGlobals replaces the global http.DefaultTransport, and returns a function to restore the original value.
Types ¶
type Agent ¶
type Agent struct { // Agent implements the http.RoundTripper interface http.RoundTripper // SecretKey is your Bearer Secret Key; available on https://app.bearer.sh/keys // Required SecretKey string // If set, the RoundTripper interface actually used to make requests // If nil, an equivalent of http.DefaultTransport is used Transport http.RoundTripper // If set, will be used for internal logging. Logger *zap.Logger // If set, this context will be used by the agent for managing its internal goroutines // and performing operational requests. Context context.Context // Duration between two config refreshes. // If empty, will use 5s as default. RefreshConfigEvery time.Duration // contains filtered or unexported fields }
Agent is the main object of this library. You need to initialize an agent first, and then you need to configure your HTTP clients to use it as a RoundTripper.
func (Agent) Config ¶
Config fetches and returns a fresh Bearer configuration for your current token
type Config ¶
type Config struct {
BlockedDomains []string `json:"blockedDomains"`
}
Config is retrieved from Bearer's API.
type ReportLog ¶
type ReportLog struct { Protocol string `json:"protocol"` Path string `json:"path"` Hostname string `json:"hostname"` Method string `json:"method"` StartedAt int `json:"startedAt"` EndedAt int `json:"endedAt"` Type string `json:"type"` StatusCode int `json:"statusCode"` URL string `json:"url"` RequestHeaders map[string]string `json:"requestHeaders"` RequestBody string `json:"requestBody"` ResponseHeaders map[string]string `json:"responseHeaders"` ResponseBody string `json:"responseBody"` }
ReportLog is the log object sent to Bearer's API.
func (ReportLog) RequestContentType ¶
RequestContentType returns the value of the requesting "Content-Type" HTTP header.
func (ReportLog) ResponseContentType ¶
ResponseContentType returns the value of the replying "Content-Type" HTTP header.
Click to show internal directories.
Click to hide internal directories.