common

package
v0.0.0-...-9742f5a Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EscrowIDSize = 16
	ObjectIDSize = 16
	ChunkIDSize  = 16
)

Variables

View Source
var (
	ErrMethodNotAllowed = &webError{status: http.StatusMethodNotAllowed}
)

Functions

func DecryptTicketL2

func DecryptTicketL2(ctx context.Context, secret, ciphertext []byte) (*ccmsg.TicketL2, error)

func EncryptTicketL2

func EncryptTicketL2(p *colocationpuzzle.Puzzle, t *ccmsg.TicketL2) ([]byte, error)

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, err error)

func GRPCDial

func GRPCDial(target string, insecure bool, opts ...grpc.DialOption) (*grpc.ClientConn, error)

GRPCDial creates a client connection to the given target.

func IsErrConnRefused

func IsErrConnRefused(err error) bool

IsErrConnRefused returns true iff the error is a network error corresponding to ECONNREFUSED being returned from a syscall like listen(2).

func IsNetErrClosing

func IsNetErrClosing(err error) bool

IsNetErrClosing returns true iff err is net.errClosing: "use of closed network connection". This helper exists because that error is not exported.

func IsWebSocketClose

func IsWebSocketClose(err error, statusCodes ...int) bool

IsWebSocketClose returns true iff err is indicates that a WebSocket connection has been closed with one of the indicated status codes.

func JSONResponse

func JSONResponse(w http.ResponseWriter, respObj interface{})

func JSONResponseC

func JSONResponseC(w http.ResponseWriter, respObj interface{}) error

func Main

func Main(mainC func() error)

Main provides a convenient thunk to allow writing a CLI with more idiomatic go - returning error rather than calling os.Exit. A small thunk is still needed. If mainC returns non-nil the error reported to stderr and a non-zero exit code is reported to the OS.

```

func main() {
    common.Main(mainC)
}

```

func NewDBGRPCServer

func NewDBGRPCServer(db *sql.DB, opt ...grpc.ServerOption) *grpc.Server

New GRPCServer makes a DB enabled GRPC server preconfigured with tracing and monitoring middleware.

func NewGRPCServer

func NewGRPCServer(opt ...grpc.ServerOption) *grpc.Server

NewGRPCServer makes a stateless GRPC server preconfigured with tracing and monitoring middleware.

func RunStarterShutdowner

func RunStarterShutdowner(l *logrus.Logger, o StarterShutdowner) error

Types

type ChunkID

type ChunkID [ChunkIDSize]byte

func BytesToChunkID

func BytesToChunkID(x []byte) (ChunkID, error)

func (*ChunkID) Randomize

func (id *ChunkID) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool)

TODO: I don't think that we need to support `fieldType` here, but do we need to support `shouldBeNull`? Their purpose is explained in the Randomizer docs.

func (*ChunkID) Scan

func (id *ChunkID) Scan(src interface{}) error

func (ChunkID) String

func (id ChunkID) String() string

func (ChunkID) Value

func (id ChunkID) Value() (driver.Value, error)

type ConfigParser

type ConfigParser struct {
	// contains filtered or unexported fields
}

func NewConfigParser

func NewConfigParser(l *logrus.Logger, prefix string) (*ConfigParser, error)

func (*ConfigParser) GetBool

func (p *ConfigParser) GetBool(key string, fallback bool) bool

func (*ConfigParser) GetInsecure

func (p *ConfigParser) GetInsecure() bool

GetInsecure returns the well known insecure setting, logging it for diagnostics. Insecure disables TLS checking on bootstrap/publisher/observability endpoints.

func (*ConfigParser) GetInt64

func (p *ConfigParser) GetInt64(key string, fallback int64) int64

func (*ConfigParser) GetSeconds

func (p *ConfigParser) GetSeconds(key string, fallback int64) time.Duration

func (*ConfigParser) GetString

func (p *ConfigParser) GetString(key string, fallback string) string

func (*ConfigParser) ReadFile

func (p *ConfigParser) ReadFile(path string) error

type EscrowID

type EscrowID [EscrowIDSize]byte

func BytesToEscrowID

func BytesToEscrowID(x []byte) (EscrowID, error)

func (EscrowID) MarshalText

func (id EscrowID) MarshalText() ([]byte, error)

These are here to support marshaling as JSON map keys.

func (*EscrowID) Randomize

func (id *EscrowID) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool)

TODO: I don't think that we need to support `fieldType` here, but do we need to support `shouldBeNull`? Their purpose is explained in the Randomizer docs.

func (*EscrowID) Scan

func (id *EscrowID) Scan(src interface{}) error

func (EscrowID) String

func (id EscrowID) String() string

func (EscrowID) UnmarshalText

func (id EscrowID) UnmarshalText(x []byte) error

func (EscrowID) Value

func (id EscrowID) Value() (driver.Value, error)

type Flushable

type Flushable struct {
	// contains filtered or unexported fields
}

Flushable is a wrapper for jaeger.Exporter to permit clean code in callers while permitting tracing to be disabled.

func SetupTracing

func SetupTracing(traceAPI string, serviceName string, l *logrus.Logger) *Flushable

SetupTracing configures OpenCensus to export to Jaeger.

func (*Flushable) Flush

func (f *Flushable) Flush()

Flush blocks until all recent spans are flushed or a hard error occurs flushing (which is then swallowed).

type MetricsPusher

type MetricsPusher struct {
	// contains filtered or unexported fields
}

MetricsPusher sends metrics to the CacheCash central metrics store

func NewMetricsPusher

func NewMetricsPusher(l *logrus.Logger, endpoint string, insecure bool, kp *keypair.KeyPair) *MetricsPusher

NewMetricsPusher creates a new MetricsPusher

func (*MetricsPusher) Shutdown

func (mp *MetricsPusher) Shutdown(ctx context.Context) error

Shutdown sending of metrics

func (*MetricsPusher) Start

func (mp *MetricsPusher) Start() error

Start sending metrics

type MyHandlerFunc

type MyHandlerFunc func(w http.ResponseWriter, req *http.Request) (respObj interface{}, err WebError)

type ObjectID

type ObjectID [ObjectIDSize]byte

func BytesToObjectID

func BytesToObjectID(x []byte) (ObjectID, error)

func (*ObjectID) Randomize

func (id *ObjectID) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool)

TODO: I don't think that we need to support `fieldType` here, but do we need to support `shouldBeNull`? Their purpose is explained in the Randomizer docs.

func (*ObjectID) Scan

func (id *ObjectID) Scan(src interface{}) error

func (ObjectID) String

func (id ObjectID) String() string

func (ObjectID) Value

func (id ObjectID) Value() (driver.Value, error)

type StarterShutdowner

type StarterShutdowner interface {
	// Start kicks off any internal goroutines that are necessary and returns synchronously.  It may temporarily block
	// until whatever needs to be started has been started.
	Start() error
	// Shutdown blocks until a graceful shutdown takes place.  If the provided context expires, the shutdown is forced.
	Shutdown(context.Context) error
}

type WebError

type WebError interface {
	error

	StatusCode() int
}

Jump to

Keyboard shortcuts

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