Skip to content

Instantly share code, notes, and snippets.

View wtask's full-sized avatar
🏠
Working from home

Mike Mikhailov wtask

🏠
Working from home
  • Tver, Russia
View GitHub Profile
@wtask
wtask / min-max.go
Created March 29, 2022 00:03
Table driven tests for generics
package number
import "golang.org/x/exp/constraints"
func Min[T constraints.Ordered](x, y T) T {
if x <= y {
return x
}
return y
@wtask
wtask / go-outdated
Last active September 3, 2021 20:49
Windows/WSL Golang dependency checker (go-mod-outdated wrapper)
#!/bin/sh
echo Checking Golang outdated dependencies...
echo
if [ -f "./go.mod" ]; then
echo $(head -n 1 ./go.mod)
go.exe list -u -m -json all | go-mod-outdated.exe -update -direct
else
echo " go.mod is missing"
fi;
@wtask
wtask / Makefile
Last active May 9, 2021 18:45
Orchestrate the orchestrator with Makefile
description := "Generic development dependency runner"
comma := ,
ENV ?= dev
# You may set credentials for all services with this single session var
# Example:
# CREDENTIALS=micro-service make postgres
# OR under Windows:
# wsl CREDENTIALS=micro-service make postgres
CREDENTIALS ?= service
@wtask
wtask / reference.go
Last active February 14, 2021 00:35
MongoDB bson.ValueMarshaler/bson.ValueUnmarshaler Golang example
package model
import (
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/bson/primitive"
)
@wtask
wtask / 1_fault.go
Last active January 21, 2020 08:53
Helper to handle errors in Go 1.13.x on idiomatic way
package errcode
import (
"fmt"
)
// Fault type is implementation of standard error interface with minimal details like error scope and error code
// and the error scope is a "namespace" of error code used.
// Also the Fault type contain Cause field to save original (underlying) error and to support error-wrapping chains.
//
@wtask
wtask / main.go
Last active July 2, 2019 21:56
Abstraction for help to manage concurrency as scopes of dependencies
package main
import (
"context"
"fmt"
"sync"
"time"
)
// Background - abstraction for concurrency scope
@wtask
wtask / .gitignore
Created June 25, 2019 09:59
Git-ignore template for Golang projects
.idea/
.vscode/
.history/
# Debug binaries
debug
# Binaries for programs and plugins
*.exe
*.exe~
@wtask
wtask / main.go
Last active April 29, 2019 15:15
Golang: simplest way to execute several deferred funcs and return appropriate exit code from main
package main
import (
"some/logging"
"also/database"
"finally/application"
"fmt"
"os"
)
func main() {
@wtask
wtask / service_test.go
Last active April 26, 2019 15:28
Go: organize your tests with "suits" to get setup/teardown for group of tests and make initialization without using init() function and any testing frameworks!
package service
import (
"fmt"
"testing"
"github.com/jinzhu/gorm"
".../service/model"
)
type test func(t *testing.T)
@wtask
wtask / functional-options.go
Last active June 17, 2022 22:48
Golang functional options pattern by Dave Cheney with little improvments due to practice.
// optionsptrn - inspired by https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
package optionsptrn
import (
"errors"
"time"
// ...
)
// service - to implement SomeInterface.