Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / openapi_go_services.md
Created September 23, 2021 03:04
What are the best choices for minimizing the amount of boilerplate required to get a service online?

I'm looking at OpenAPI generation and I see three main forms:

Service + Design

I really like the look of go-restful when it comes to adding hundreds of api endpoints. You define your service (actual business logic) and you define your routes with request/response structs and you're done. Validation, decoding/encoding, swagger docs, etc... is all taken care of - but you can only use HTTP. https://github.com/emicklei/go-restful-openapi/blob/dec9f41f12/examples/user-resource.go

Service + Design + Boilerplate

Next you have go-kit which requires additional definitions for decoding, but also allows you to define different transports (HTTP, gRPC, cli, and even NATS!) still, for rest-only servers seems like overkill to have to write all that boilerplate code for each service method. https://github.com/go-kit/examples/blob/master/stringsvc4/main.go#L153-L205

@xeoncross
xeoncross / ERRORS_IN_GO.md
Last active October 2, 2021 19:03
Golang - Go http.Handler returning and error that can split user messages from log messages

Demo: https://play.golang.org/p/qk20EKdlRuL

One message (somewhere in the chain of errors) is for the user - the rest are for the logs. The idea is that you can still put plenty of debugging information in the full error logs ("SQL error") - but show a nice, safe message to the client ("user not found").

Based on the following articles (discussed above)

https://middlemost.com/failure-is-your-domain/ https://commandcenter.blogspot.com/2017/12/error-handling-in-upspin.html https://blog.questionable.services/article/http-handler-error-handling-revisited/ https://go.dev/blog/error-handling-and-go

@xeoncross
xeoncross / react-state-management.md
Last active September 13, 2022 08:01
Comparison of react state management + Dev story + Testing for Redux Toolkit, Zustand, Jotia, and Valtio

A demo "counter" + async application (codesandbox) is provided for each of the following four state libraries. The Zustand codesandbox includes three versions: vanila, immer, and redux-like

Redux Toolkit

OpenAPI

RTK Query has a (currently experimental) code-gen tool that will take an OpenAPI spec or GraphQL schema and give you a typed API client, as well as provide methods for enhancing the generated client after the fact.

@xeoncross
xeoncross / .env
Last active July 10, 2021 14:28
Flags, environment variables, and .env file config loading https://play.golang.org/p/pautLXl7yMW
MYSQL_HOST=127.0.0.1
MYSQL_USER=hello
MYSQL_PASS=world
MYSQL_NAME=myapp
MYSQL_PORT=3306
@xeoncross
xeoncross / durable_objects.md
Last active May 21, 2021 02:26
Cloudflare Durable Objects

Just saw that cloudflare created https://developers.cloudflare.com/workers/learning/using-durable-objects

Background: Regular lambda/worker/serverless functions are state-less - they have no persistent memory and are created and destroyed often; the are ephemeral.

For those of us that use these, we often default to having a stateful server somewhere (pubsub, websockets, chatroom organizer, rate-limiter, etc..). Often the database or filesystem (lock files) can be used as the manager of state or "source of truth".

Cloudflare basically created long-lived, single-instance lambda functions here. Now they can keep an hash of websocket connections or recent chat messages allowing multiple other short-lived (regular) serverless functions to use them like a regular webserver.

It's the new, old server pretending to be serverless. An expected, but still interesting development.

@xeoncross
xeoncross / README.md
Created May 19, 2021 19:37
https://linc.sh utilizes the neat idea of auto-deployed branches for every push

Cloudflare workers + auto deployments of staging branches

Using github actions to create the wrangler.toml domain name would let us use the default commit sha or branch name as the subdomain.

Inside the workers-deploy.yml you could build the domain name using the github action vars:

echo "[env.production]\nname=\"${GITHUB_REF}.example.com\"" > ~/.wrangler/config/domain.toml
@xeoncross
xeoncross / driver.go
Created May 19, 2021 01:50 — forked from kamichidu/driver.go
POC: golang database/sql, row to map[string]interface{} mapping
package main
import (
"database/sql"
"database/sql/driver"
"fmt"
"strings"
)
type Mapper interface {
@xeoncross
xeoncross / settings.json
Last active June 14, 2021 22:38
Changes to https://github.com/tonsky/vscode-theme-alabaster Alabaster theme to make more text black
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go",
"workbench.colorTheme": "Alabaster",
"settingsSync.ignoredExtensions": [
],
"workbench.colorCustomizations": {
// "editor.background": "#F1F1F1",
},
@xeoncross
xeoncross / osx_installer.sh
Created April 17, 2021 15:22
Download the full Mac OSX installer image
// https://eclecticlight.co/2019/10/18/beware-apple-security-certificates-after-24-october-they-may-have-expired/
// the macOS 10.15 version of the softwareupdate command tool contains a new option which allows you to download full installers for specific versions of macOS
// Get Mojave
softwareupdate --fetch-full-installer --full-installer-version 10.14.6
@xeoncross
xeoncross / spacy_on_big_sur.md
Created April 9, 2021 15:38
Install spaCy on OSX Big Sur

spaCy on Mac Big Sur

Mac OSX ships with python (2) and python3 with pip3.

They should be current enough versions. If not, you can update them.

pip3 install -U pip3 setuptools

First install spaCy