Skip to content

Instantly share code, notes, and snippets.

View avary's full-sized avatar

Abdulhafiz KAŞGARLI avary

View GitHub Profile
@avary
avary / GoMgoSample-1.go
Created August 16, 2023 14:05 — forked from 345161974/GoMgoSample-1.go
Sample Go and MGO example
type (
// BuoyCondition contains information for an individual station.
BuoyCondition struct {
WindSpeed float64 `bson:"wind_speed_milehour"`
WindDirection int `bson:"wind_direction_degnorth"`
WindGust float64 `bson:"gust_wind_speed_milehour"`
}
// BuoyLocation contains the buoy's location.
BuoyLocation struct {
@avary
avary / pocketbase.go
Created August 16, 2023 11:02 — forked from cnjax/pocketbase.go
fix for auth admin with password
package pocketbase
import (
"errors"
"fmt"
"github.com/duke-git/lancet/v2/convertor"
"github.com/go-resty/resty/v2"
"golang.org/x/sync/singleflight"
"time"
)
@avary
avary / echo_server.go
Created August 4, 2023 21:26 — forked from benjisg/echo_server.go
Simple GO HTTP server to pretty print the request body sent to it
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
@avary
avary / server.go
Created August 4, 2023 21:25 — forked from mindscratch/server.go
TLS enabled HTTP Server in Go
package main
import (
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
)
@avary
avary / server.go
Created August 4, 2023 21:23 — forked from josue/server.go
Simple Golang HTTP server with signal capturing (ie: SIGINT/SIGTERM) & pprof debugger
/*
go build for linux:
env GOOS=linux go build -o /tmp/server server.go
run with docker:
docker run -it --rm --name test -v /tmp/server:/server -p 3000:80 -p 3001:6060 alpine /server
run pprof debugger:
go get github.com/google/pprof
pprof --seconds 30 -http=:4444 /tmp/server http://localhost:3001/debug/pprof/profile
@avary
avary / redirectExample.go
Created August 4, 2023 21:22 — forked from d-schmidt/redirectExample.go
How to redirect HTTP to HTTPS with a golang webserver.
package main
import (
"net/http"
"log"
)
func redirect(w http.ResponseWriter, req *http.Request) {
// remove/add not default ports from req.Host
target := "https://" + req.Host + req.URL.Path
if len(req.URL.RawQuery) > 0 {
@avary
avary / main.go
Created August 4, 2023 21:21 — forked from up1/main.go
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"
@avary
avary / mux.go
Created August 4, 2023 21:19 — forked from arouene/mux.go
Golang http muxer with middleware support
package mux
import (
"fmt"
"net/http"
)
type Middleware struct {
mux *http.ServeMux
middlewares [](func(http.Handler) http.Handler)
@avary
avary / http.go
Created August 4, 2023 21:18 — forked from AngerM/http.go
High Performance Golang HTTP Client
package utils
import (
"context"
"io"
"io/ioutil"
"net"
"net/http"
"strings"
"time"
@avary
avary / main.go
Created August 4, 2023 21:16 — forked from husobee/main.go
simple golang http middleware chaining example
package main
import (
"fmt"
"net/http"
"time"
"golang.org/x/net/context"
"github.com/husobee/backdrop"