Exploring tools that allow converting a JSON response automagically into an OpenAPI / Swagger spec.
{
"accounts": {
"default": {
package main | |
import ( | |
"fmt" | |
"log" | |
"context" | |
"cloud.google.com/go/storage" |
graph Doskvol { | |
concentrate=true; | |
edge[color=forestgreen] | |
subgraph legend { | |
color = black; | |
label = "Legend"; | |
"Tier I"--"Tier II"--"Tier III"--"Tier IV"--"Tier V" | |
} | |
// It took me few hours how to get this to work | |
// Have a service account in GCP which wanted to use Admin SDK with Google Workspace | |
// The service account needs to have the following role: `roles/iam.serviceAccountTokenCreator` | |
// You need to create a domain wide delegation for the service account client id | |
import ( | |
"google.golang.org/api/impersonate" | |
"google.golang.org/api/option" | |
"context" | |
) |
### colored and fuzzy go doc | |
if which bat > /dev/null; then | |
function _godoc() { | |
if echo $1|grep -q -E "^([a-zA-Z0-9/]+)$"; then | |
go doc ${@} | bat -p -l md | |
elif echo $1|grep -q -E "^[a-zA-Z0-9/]+\.[a-zA-Z0-9.]+$"; then | |
go doc ${@} | bat -p -l go | |
elif echo $1|grep -q -E "^([a-zA-Z0-9/._-]+)/.*\.[a-zA-Z0-9.]+$"; then | |
go doc ${@} | bat -p -l go | |
else |
// ConsoleHandler formats slog.Logger output in console format, a bit similar with Uber's zap ConsoleEncoder | |
// The log format is designed to be human-readable. | |
// | |
// Performance can definitely be improved, however it's not in my priority as | |
// this should only be used in development environment. | |
// | |
// e.g. log output: | |
// 2022-11-24T11:40:20+08:00 DEBUG ./main.go:162 Debug message {"hello":"world","!BADKEY":"bad kv"} | |
// 2022-11-24T11:40:20+08:00 INFO ./main.go:167 Info message {"with_key_1":"with_value_1","group_1":{"with_key_2":"with_value_2","hello":"world"}} | |
// 2022-11-24T11:40:20+08:00 WARN ./main.go:168 Warn message {"with_key_1":"with_value_1","group_1":{"with_key_2":"with_value_2","hello":"world"}} |
package workload | |
import ( | |
"context" | |
"golang.org/x/sync/errgroup" | |
"time" | |
) | |
type Worker func() error |
package main | |
import ( | |
"context" | |
"encoding/json" | |
"errors" | |
"fmt" | |
"log" | |
"net/http" | |
"os" |
package do | |
type Void struct{} | |
type Result[T any] interface { | |
Unwrap() (T, error) | |
} | |
type defaultResult[T any] struct { | |
val T |
package main | |
import ( | |
"fmt" | |
) | |
var ( | |
ones = []string{ | |
"zero", "one", "two", "three", "four", | |
"five", "six", "seven", "eight", "nine", |