Skip to content

Instantly share code, notes, and snippets.

View athiwatp's full-sized avatar
💭
I may be slow to respond.

athiwatp athiwatp

💭
I may be slow to respond.
View GitHub Profile
@athiwatp
athiwatp / aes256-gcm.go
Created July 23, 2021 08:12 — forked from kkirsche/aes256-gcm.go
AES-256 GCM Encryption Example in Golang
package example_test
import (
"crypto/aes"
"crypto/cipher"
"hex"
"io"
)
// AES-GCM should be used because the operation is an authenticated encryption
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
@athiwatp
athiwatp / main.go
Created May 31, 2021 05:22 — forked from dopey/main.go
How to generate secure random strings in golang with crypto/rand.
package main
import (
"crypto/rand"
"encoding/base64"
"fmt"
"io"
)
// Adapted from https://elithrar.github.io/article/generating-secure-random-numbers-crypto-rand/
@athiwatp
athiwatp / send-sms.go
Created January 21, 2021 08:09 — forked from BizarroDavid/send-sms.go
Sending an SMS Text Message using AWS SNS service in GoLang
//assumes you have the following environment variables setup for AWS session creation
// AWS_SDK_LOAD_CONFIG=1
// AWS_ACCESS_KEY_ID=XXXXXXXXXX
// AWS_SECRET_ACCESS_KEY=XXXXXXXX
// AWS_REGION=us-west-2( or AWS_DEFAULT_REGION=us-east-1 if you are having trouble)
package main
import (
"fmt"
@athiwatp
athiwatp / golang-nuts.go
Created October 3, 2020 17:46 — forked from ryanfitz/golang-nuts.go
two ways to call a function every 2 seconds
package main
import (
"fmt"
"time"
)
// Suggestions from golang-nuts
// http://play.golang.org/p/Ctg3_AQisl
@athiwatp
athiwatp / sort_time.go
Created September 22, 2020 07:22 — forked from xigang/sort_time.go
Sorting by time.Time in Golang
package main
import (
"fmt"
"sort"
"time"
)
type reviews_data struct {
review_id string
@athiwatp
athiwatp / main.go
Created August 27, 2020 05:27 — forked from nmerouze/main.go
JSON-API with Go and MongoDB: Final Part
package main
import (
"encoding/json"
"log"
"net/http"
"reflect"
"time"
"github.com/gorilla/context"
@athiwatp
athiwatp / .Title
Created August 27, 2020 04:25 — forked from congjf/.Title
Using MongoDB in golang with mgo
Using MongoDB in golang with mgo
@athiwatp
athiwatp / jwt-expiration.md
Created June 16, 2020 11:05 — forked from soulmachine/jwt-expiration.md
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC: