Documentation ¶
Overview ¶
Package services implements utility functions.
Index ¶
- Constants
- Variables
- func Duration(d time.Duration) string
- func FriendlyDate(t time.Time) string
- func FriendlyLocation(loc *time.Location) string
- func IsRegistered(name string) bool
- func Opaque(s string, secretKey nacl.Key) string
- func OpaqueByte(b []byte, secretKey nacl.Key) string
- func RegisterReporter(name string, r ErrorReporter)
- func TruncateSid(sid string) string
- func Unopaque(compressed string, secretKey nacl.Key) (string, error)
- func UnopaqueByte(compressed string, key nacl.Key) ([]byte, error)
- type ErrorReporter
- type GoogleUser
- type LocationFinder
- type NoopErrorReporter
- type Rlm
- type SentryErrorReporter
Constants ¶
const Local = Rlm("local")
const Prod = Rlm("prod")
Variables ¶
var UserDataBase = "https://www.googleapis.com"
Base URL to get user data from.
var UserDataPath = "/oauth2/v3/userinfo"
Path that allows you to get user data.
Functions ¶
func FriendlyDate ¶
FriendlyDate returns a friendlier version of the date.
func FriendlyLocation ¶
Turns "America/New_York" into "New York"
func IsRegistered ¶
func Opaque ¶
Opaque encrypts s with secretKey and returns the encrypted string encoded with base64, or an error.
func RegisterReporter ¶
func RegisterReporter(name string, r ErrorReporter)
RegisterReporter allows the ErrorReporter with the given name to be used. Use this to register a custom ErrorReporter for your project.
Call RegisterReporter(name, nil) to delete a Reporter.
func TruncateSid ¶
TruncateSid truncates the Sid to the first 6 characters of the ID (16 million possibilities).
Types ¶
type ErrorReporter ¶
type ErrorReporter interface { Configure(token string) // ReportError reports an error. If ReportError captures a stacktrace, be // sure to call it in the same goroutine as the context you are hoping // to capture. Set block to true to wait for the remote service call to // complete before returning. ReportError(err error, block bool) // ReportPanic returns a http.Handler that monitors the inner handler for // panics, and reports them to the remote service. ReportPanics(http.Handler) http.Handler }
An ErrorReporter reports errors to a third party service. ErrorReporter instances should be thread safe.
func GetReporter ¶
func GetReporter(name, token string) ErrorReporter
GetReporter gets the reporter for the given name and token. If the name is unknown, a NoopErrorReporter is returned.
type GoogleUser ¶
type GoogleUser struct { Sub string `json:"sub"` Name string `json:"name"` GivenName string `json:"given_name"` FamilyName string `json:"family_name"` Profile string `json:"profile"` Picture string `json:"picture"` Email string `json:"email"` EmailVerified bool `json:"email_verified"` Gender string `json:"gender"` Locale string `json:"locale"` HD string `json:"hd"` }
The data about users that we get back from Google.
func GetGoogleUserData ¶
type LocationFinder ¶
type LocationFinder interface { AddLocation(loc string) bool GetLocation(string) *time.Location // GetLocation gets a location preference from the user cookie, or the // default location if no location was found. GetLocationReq(*http.Request) *time.Location // SetLocation sets the location (string) as a cookie, and returns true if // it was successfully set. SetLocation(http.ResponseWriter, string, bool) bool // Locations returns all known locations Locations() []*time.Location }
func NewLocationFinder ¶
func NewLocationFinder(defaultLocation string) (LocationFinder, error)
NewLocationFinder returns a new LocationFinder, where the defaultLocation is used for any request where we can't find the default location. If defaultLocation is the empty string, time.UTC will be used as the default. Returns an error if defaultLocation cannot be parsed by time.LoadLocation.
type NoopErrorReporter ¶
type NoopErrorReporter struct{}
A NoopErrorReporter silently swallows all errors.
func (*NoopErrorReporter) Configure ¶
func (n *NoopErrorReporter) Configure(_ string)
func (*NoopErrorReporter) ReportError ¶
func (n *NoopErrorReporter) ReportError(_ error, _ bool)
func (*NoopErrorReporter) ReportPanics ¶
func (n *NoopErrorReporter) ReportPanics(h http.Handler) http.Handler
type SentryErrorReporter ¶
type SentryErrorReporter struct{}
func (*SentryErrorReporter) Configure ¶
func (s *SentryErrorReporter) Configure(token string)
func (*SentryErrorReporter) ReportError ¶
func (s *SentryErrorReporter) ReportError(err error, block bool)
func (*SentryErrorReporter) ReportPanics ¶
func (s *SentryErrorReporter) ReportPanics(h http.Handler) http.Handler