Skip to content

Instantly share code, notes, and snippets.

View sebasrock's full-sized avatar
🎯
Focusing

Juan Sebastian sanchez sebasrock

🎯
Focusing
View GitHub Profile
package main
import (
"context"
"fmt"
"time"
"unsafe"
)
func main() {
package statuscode
import (
"fmt"
"strconv"
"strings"
)
// Code are the status codes that define the stage of the transaction
type Code uint
@sebasrock
sebasrock / enum.go
Created October 13, 2021 16:09 — forked from lummie/enum.go
Golang Enum pattern that can be serialized to json
package enum_example
import (
"bytes"
"encoding/json"
)
// TaskState represents the state of task, moving through Created, Running then Finished or Errorred
type TaskState int
@sebasrock
sebasrock / GolangCPUProfiles.sh
Created April 27, 2022 03:01 — forked from bgadrian/GolangCPUProfiles.sh
Golang Flame graph profiles
#install FlameGraph library
cd /opt/
sudo git clone https://github.com/brendangregg/FlameGraph.git
#make it accesible from any folder
vim ~/.bashrc
##add these lines anywhere and exit vim (if you can)
export FLAMEPATH=/opt/FlameGraph
PATH=$PATH:$FLAMEPATH

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@sebasrock
sebasrock / gist:490254c08c4a433bf223cac6e22647e3
Created July 25, 2022 19:22 — forked from gambol99/gist:d55afd69217b8e2dd727be99f0a20e7d
golang - create ca and build csr for signing
//
// createCertificateAuthority generates a certificate authority request ready to be signed
//
func (r *secretStore) createCertificateAuthority(names pkix.Name, expiration time.Duration, size int) (*caCertificate, error) {
// step: generate a keypair
keys, err := rsa.GenerateKey(rand.Reader, size)
if err != nil {
return nil, fmt.Errorf("unable to genarate private keys, error: %s", err)
}
@sebasrock
sebasrock / Certificates.go
Created August 25, 2022 21:14 — forked from Mattemagikern/Certificates.go
Create x509 certificate chain using Golang. Root CA, Designated CA, server CA
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
@sebasrock
sebasrock / revprox.go
Created February 10, 2023 16:23 — forked from thurt/revprox.go
Simple reverse proxy in Go (forked from original to use a struct instead of a closure)
package main
import(
"log"
"net/url"
"net/http"
"net/http/httputil"
)
func main() {
@sebasrock
sebasrock / revprox.go
Created February 10, 2023 16:23
Simple reverse proxy in Go (forked from original to use a struct instead of a closure with ssl)
package main
import (
"crypto/tls"
"log"
"net/http"
"net/http/httputil"
"net/url"
)
@sebasrock
sebasrock / pprof.md
Created March 3, 2023 17:58 — forked from slok/pprof.md
Go pprof cheat sheet

Enable profiling

Default http server

import (
    _ "net/http/pprof"
    "net/http"
)