Skip to content

Instantly share code, notes, and snippets.

// FileSystem custom file system handler
type FileSystem struct {
fs http.FileSystem
}
// Open opens file
func (fs FileSystem) Open(path string) (http.File, error) {
f, err := fs.fs.Open(path)
if err != nil {
return nil, err
@hauxe
hauxe / pool_of_workers.go
Last active July 5, 2023 15:03
Pool of Workers
package main
import (
"sync"
"time"
)
// Job define job interface
type Job interface {
Execute()
@hauxe
hauxe / generic_env_test.go
Created October 24, 2022 08:44
Generic get environment unit test
package utils
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestGetEnvT(t *testing.T) {
@hauxe
hauxe / generic_env.go
Created October 24, 2022 08:43
Generic get environment
package utils
import (
"os"
"strconv"
)
type Env[T any] struct {
DefaultVal T
FromString func(string) (T, error)
package main
import (
"flag"
"log"
"net/http"
"strings"
)
func main() {
package main
import (
"flag"
"log"
"net/http"
"strings"
)
// FileSystem custom file system handler
// AND function combines all signal from channels into a single channel with And condition
func AND(channels ...<-chan interface{}) <-chan interface{} {
switch len(channels) {
case 0:
return nil
case 1:
return channels[0]
}
andDone := make(chan interface{})
collector := make(chan interface{}, len(channels))
package main
import (
"bytes"
"fmt"
"io"
"log"
"os"
"sync"
)
// OR function combines all signal from channels into a single channel with Or condition
func OR(channels ...<-chan interface{}) <-chan interface{} {
switch len(channels) {
case 0:
return nil
case 1:
return channels[0]
}
orDone := make(chan interface{})
go func() {
package main
import (
"log"
"sync"
)
func main() {
cond := sync.NewCond(&sync.Mutex{})
var wg1 sync.WaitGroup