Typesafe lazy instantiation to improve service start time

lazy

PkgGoDev GitHub issues license Release

Package lazy is a light wrapper around sync.Once providing support for return values. It removes the burden of capturing return values via closures from the caller.

// server.go
type server struct {
  DB func() *sql.DB
}

func (s *server) someHttpHandler(w http.ResponseWriter, r *http.Request) {
  db := s.DB()
  _ = db // use db throughout the handler
}

// db.go
func newDB() *sql.DB {
  // ommitted
}

// main.go
s := server {
  DB: lazy.Lazy(newDB),
}

s.ListenAndServe()
Owner
Jeremy Loy
☕️ +💻=📱
Jeremy Loy
Similar Resources

FlameScope is a visualization tool for exploring different time ranges as Flame Graphs.

FlameScope is a visualization tool for exploring different time ranges as Flame Graphs.

FlameScope FlameScope is a visualization tool for exploring different time ranges as Flame Graphs, allowing quick analysis of performance issues such

Dec 27, 2022

Advent of Code 2021 - Time to learn Go

aoc2021 Advent of Code 2021 - Time to learn Go Will contain my solutions for aoc2021, so avoid reading the files in .src/aoc2021/ unless you want spoi

Dec 22, 2021

Advent of Code 2021, this time in Go

Go Lang Notes Advent of Code Day 3 The distinction between chars and bytes is a bit annoying. I got tripped up by doing: int(str[pos]) which gives yo

Dec 10, 2022

You could leverage Alfred and Google Sheets to track your time with ease.

You could leverage Alfred and Google Sheets to track your time with ease.

You could leverage Alfred and Google Sheets to track your time with ease. The goal is to track your time in a way that is easy to understand how much time you spend on.

Dec 25, 2022

Solver for wordle hard mode - achieves 5 attempts or less 100% of the time

wordier Solver for wordle hard mode - achieves 5 attempts or less 100% of the time Example - Spoiler ➜ wordier git:(master) ✗ go run main.go scamp ➜

Jan 12, 2022

⛑ Gatus - Automated service health dashboard

⛑ Gatus - Automated service health dashboard

A service health dashboard in Go that is meant to be used as a docker image with a custom configuration file. I personally deploy it in my Kubernetes

Dec 31, 2022

HTTP service to generate PDF from Json requests

pdfgen HTTP service to generate PDF from Json requests Install and run The recommended method is to use the docker container by mounting your template

Dec 2, 2022

Kratos Service Layout

Kratos Layout Install Kratos

Jan 1, 2023

An HTTP service for customizing import path of your Go packages.

Go Packages A self-host HTTP service that allow customizing your Go package import paths. Features Reports. Badges. I18N. Preview I launch up a free H

Nov 27, 2022
Related tags
A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

Dec 31, 2021
Start of a project that would let people stay informed about safe running spaces in their area.

SafeRun Start of a project that would let people stay informed about safe running spaces in their area. Too many people I'm friends with feel unsafe w

Feb 11, 2022
Real-time Charging System for Telecom & ISP environments

Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments Features Real-time Online/Offline Charging System (OCS). Account Balance

Dec 31, 2022
A toolkit for replaying time series data.

Replay Toolkit The replay package provides some simple tools for replaying captured data at realtime. I use this in various tools that take logged dat

Aug 13, 2019
A simple Cron library for go that can execute closures or functions at varying intervals, from once a second to once a year on a specific date and time. Primarily for web applications and long running daemons.

Cron.go This is a simple library to handle scheduled tasks. Tasks can be run in a minimum delay of once a second--for which Cron isn't actually design

Dec 17, 2022
Weaviate is a cloud-native, modular, real-time vector search engine
Weaviate is a cloud-native, modular, real-time vector search engine

Weaviate is a cloud-native, real-time vector search engine (aka neural search engine or deep search engine). There are modules for specific use cases such as semantic search, plugins to integrate Weaviate in any application of your choice, and a console to visualize your data.

Jan 5, 2023
Visualize plant growth over time with Go, WebDAV and WASM; @pojntfx's entry for #growlab.

Growlapse Visualize plant growth over time with Go, WebDAV and WASM; @pojntfx's entry for #growlab. Installation Containerized You can get the Docker

Feb 21, 2022
An effective time-series data compression/decompression method based on Facebook's Gorilla.

Gorilla This package provides the effective time-series data compression method based on Facebook's Gorilla.. In a nutshell, it uses delta-of-delta ti

Sep 26, 2022
Code snippets by first time open source contributors

Introduction Golang code snippets by first time open source contributors Rules How to contribute Add a folder and create your desired code snippet fil

Oct 6, 2021
Solution to elevator test problem but this time recursive and in go

Synopsis A multi-floor building has a Lift in it. People are queued on different floors waiting for the Lift. Some people want to go up. Some people w

Nov 8, 2021