Skip to content

Instantly share code, notes, and snippets.

View akshaybharambe14's full-sized avatar
🎯
Focusing

Akshay Bharambe akshaybharambe14

🎯
Focusing
View GitHub Profile
@wijayaerick
wijayaerick / slog_console_handler.go
Last active November 25, 2023 06:40
Example ConsoleHandler for golang.org/x/exp/slog Logger
// 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"}}
func count(reader *bufio.Reader) (int, error) {
count := 0
for {
line, _, err := reader.ReadLine()
if err != nil {
switch err {
default:
return 0, errors.Wrapf(err, "unable to read")
case io.EOF:
return count, nil
@carlolars
carlolars / gitkraken-wsl-bash.bat
Last active February 10, 2023 21:08
Use bash from WSL as sh.exe for GitKraken (5.0.4) for Windows
@echo off
REM Make sure that the path to the script is correct!
@bash -l -c "~/bin/gitkraken-wsl-bash.sh %*"
package main
import (
"fmt"
"os"
"os/signal"
"sync"
"time"
)
@fracasula
fracasula / context_cancel.go
Last active May 19, 2022 20:49
GoLang exiting from multiple go routines with context and wait group
package main
// Here's a simple example to show how to properly terminate multiple go routines by using a context.
// Thanks to the WaitGroup we'll be able to end all go routines gracefully before the main function ends.
import (
"context"
"fmt"
"math/rand"
"os"
@creack
creack / main.go
Created January 7, 2018 17:30 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"strconv"
@enricofoltran
enricofoltran / main.go
Last active April 1, 2024 00:17
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@asukakenji
asukakenji / go-stdlib-interface-selected.md
Last active April 19, 2024 11:13
Go (Golang) Standard Library Interfaces (Selected)

Go (Golang) Standard Library Interfaces (Selected)

This is not an exhaustive list of all interfaces in Go's standard library. I only list those I think are important. Interfaces defined in frequently used packages (like io, fmt) are included. Interfaces that have significant importance are also included.

All of the following information is based on go version go1.8.3 darwin/amd64.

@alexchowle
alexchowle / pingpong.go
Created February 7, 2016 16:57
Simple golang pingpong
package main
import (
"fmt"
)
func main() {
pingChan := make(chan string)
pongChan := make(chan string)
@parmentf
parmentf / GitCommitEmoji.md
Last active April 26, 2024 09:53
Git Commit message Emoji