Skip to content

Instantly share code, notes, and snippets.

View dakait's full-sized avatar
🏠
Working from home

dakait

🏠
Working from home
View GitHub Profile
@dakait
dakait / validators.go
Last active May 29, 2023 01:59
Golang Custom Validator examples
package main
import (
"fmt"
"github.com/satori/go.uuid" //for uuid
"gopkg.in/validator.v2"
"reflect"
"regexp"
"time"
)
@dakait
dakait / cipher.go
Last active December 18, 2023 20:29
AES-256 GCM Encryption/Decryption Example in Golang
package secure
import (
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
"crypto/sha512"
)
@dakait
dakait / code.go
Created August 29, 2018 11:44
Generate random code golang
import "crypto/rand"
func generateRandomSecret(size int) string {
alphanum := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefbgijklmnopqrstuvwxyz0123456789"
var bytes = make([]byte, size)
rand.Read(bytes)
for i, b := range bytes {
bytes[i] = alphanum[b%byte(len(alphanum))]
}
return string(bytes)
@dakait
dakait / decorators.go
Created August 29, 2018 12:02
Chaining handler functions with gin
//Golang doesn't have python-Django like decorators but here is
//a small example of what you can do
package main
import "github.com/gin-gonic/gin"
func Handler(h gin.HandlerFunc, decors ...func(gin.HandlerFunc)gin.HandlerFunc) gin.HandlerFunc {
for i := range decors {
@dakait
dakait / help.txt
Last active March 29, 2019 10:56
Mysql install/remove
Removing mysql completely
sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
sudo apt-get autoremove -y
sudo apt-get autoclean
rm -rf /etc/mysql
sudo find / -iname 'mysql*' -exec rm -rf {} \;
Installing mysql:
sudo apt install mysql-server mysql-client