services

package
v0.0.0-...-7a56003 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package services implements utility functions.

Index

Constants

View Source
const Local = Rlm("local")
View Source
const Prod = Rlm("prod")

Variables

View Source
var UserDataBase = "https://www.googleapis.com"

Base URL to get user data from.

View Source
var UserDataPath = "/oauth2/v3/userinfo"

Path that allows you to get user data.

Functions

func Duration

func Duration(d time.Duration) string

Duration returns a friendly duration (with the insignificant bits rounded off).

func FriendlyDate

func FriendlyDate(t time.Time) string

FriendlyDate returns a friendlier version of the date.

func FriendlyLocation

func FriendlyLocation(loc *time.Location) string

Turns "America/New_York" into "New York"

func IsRegistered

func IsRegistered(name string) bool

func Opaque

func Opaque(s string, secretKey nacl.Key) string

Opaque encrypts s with secretKey and returns the encrypted string encoded with base64, or an error.

func OpaqueByte

func OpaqueByte(b []byte, secretKey nacl.Key) string

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

func TruncateSid(sid string) string

TruncateSid truncates the Sid to the first 6 characters of the ID (16 million possibilities).

func Unopaque

func Unopaque(compressed string, secretKey nacl.Key) (string, error)

Unopaque decodes compressed using base64, then decrypts the decoded byte array using the secretKey.

func UnopaqueByte

func UnopaqueByte(compressed string, key nacl.Key) ([]byte, error)

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

func GetGoogleUserData(ctx context.Context, client *http.Client) (*GoogleUser, error)

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 Rlm

type Rlm string

func Realm

func Realm() Rlm

Realm returns the given Rlm. If the realm cannot be determined, Local is returned.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL