Categorygithub.com/replicate/go
module
0.0.0-20241108122401-0eb90874fe81
Repository: https://github.com/replicate/go.git
Documentation: pkg.go.dev

# README

replicate/go

This repository contains shared packages used by Go applications at Replicate. If we find ourselves writing the same code repeatedly across different applications, we might want to put it here.

In due course, it may become a monorepo for our services and tools built using Go.

For now, the repository is public, to simplify its use as a Go module in other applications.

Packages

cache

A redis-backed typed object cache implementation supporting serve-from-stale and asynchronous cache fills.

errors

Configures conventions for recording errors: a wrapper around the Sentry SDK.

flags

Feature flagging functions: a thin wrapper around the LaunchDarkly client.

httpclient

Conventions for creating HTTP clients with appropriate pooling and timeout configuration. Heavily inspired by https://github.com/hashicorp/go-cleanhttp.

lock

A redis-backed distributed lock for coordination within multi-instance services.

logging

Configures logging conventions for github.com/sirupsen/logrus.

ratelimit

A redis-backed token-bucket rate limiter implementation.

telemetry

Standard OpenTelemetry configuration and tracer creation.

version

A convention for retrieving service version from the environment.

Tools

The repository also contains a uuid command that can be used to generate a list of uuids using the uuid package.

% go run ./cmd/uuid/main.go
> 018d3855-24f0-7531-84b4-4e88f13bab70
% go run ./cmd/uuid/main.go -timestamps
> 018d3855-24f0-7531-84b4-4e88f13bab70 2024-01-23T21:58:40.624Z
% go run ./cmd/uuid/main.go -count 5 -timestamps
> 018d3855-24f0-7531-84b4-4e88f13bab70 2024-01-23T21:58:40.624Z
> 018d3855-24f1-7b1e-be24-4ce73f77d3bf 2024-01-23T21:58:40.625Z
> 018d3855-24f1-7b33-8b7b-50e5e535b510 2024-01-23T21:58:40.625Z
> 018d3855-24f1-75d7-abb1-0db1ac9ac285 2024-01-23T21:58:40.625Z
> 018d3855-24f1-78fc-a1ce-a81e26b3fbe8 2024-01-23T21:58:40.625Z

Development

You can run the build, check the tests, lint the code, and run a formatter using the scripts provided in script/

script/build
script/test
script/format
script/lint

# Packages

Package cache implements a typed cache which can serve stale data while fetching fresh data, and which takes a distributed lock before attempting a refresh in order to greatly reduce possible cache stampede effects.
No description provided by the author
package debug provides a collection of tools for debugging Go programs at runtime.
No description provided by the author
No description provided by the author
Package httpclient collects conventions for the configuration of HTTP clients used across our various codebases.
Package lock implements a basic distributed lock that is held in N redis instances.
No description provided by the author
Package must helps you do things that must not fail.
Package queue provides a queue implementation based on Redis streams which uses [shuffle-sharding] to provide a degree of isolation between queue tenants.
Package ratelimit implements a distributed rate limiter backed by a Redis server.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author