Skip to content

Instantly share code, notes, and snippets.

View avary's full-sized avatar

Abdulhafiz KAŞGARLI avary

View GitHub 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 / 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 / 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 / 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 / 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 / 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 / config.toml
Created August 17, 2023 07:59 — forked from ghiden/config.toml
Load TOML config and pick environment from a environmental variable in Go
[dev]
url = "http://dev.example.com"
username = "dev.account"
password = "devdev"
[test]
url = "http://test.example.com"
username = "test.account"
password = "testtest"
@avary
avary / convert_repo.sh
Created August 18, 2023 07:08 — forked from iserko/convert_repo.sh
Shell script for easily joining multiple GIT repositories into a single repository by rewriting the GIT history
#!/bin/bash
###########
# ./convert_repo.sh
# Author: Igor Serko <[email protected]>
# Description: Allows the user to join multiple git repositories under one single repository
# Procedure: Using git filter-branch we rewrite the history of every repo
# example of current tree
# -- REPOONE
# |-- repoone files
# -- REPOTWO
Source link: https://stackoverflow.com/questions/31374085/installing-adb-on-macos
# Option 1 - Using Homebrew
This is the easiest way and will provide automatic updates.
1. Install [homebrew](http://brew.sh/)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. Install adb
@avary
avary / gin-secure-https.go
Created December 13, 2023 09:30 — forked from kenng/gin-secure-https.go
redirect gin http to https using unrolled/secure
// gin will throw following for the first time due to secure initiate a http.Redirect but gin is unaware of it
// [GIN-debug] [WARNING] Headers were already written. Wanted to override status code 301 with 200
package main
import (
"github.com/gin-gonic/gin"
"github.com/unrolled/secure"
)