feature: verify tokens
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
@@ -16,6 +17,12 @@ func Warn(msg string, args ...any) {
|
||||
slog.Warn(fmt.Sprintf(msg, a...), b...)
|
||||
}
|
||||
|
||||
func Incident(ctx context.Context, name, msg string, args ...any) {
|
||||
a, b := getArgs(args)
|
||||
slog.Warn(fmt.Sprintf(msg, a...), b...)
|
||||
// TODO: save incident for alert purpose
|
||||
}
|
||||
|
||||
func Error(err error, args ...any) {
|
||||
a, b := getArgs(args)
|
||||
slog.Error(fmt.Sprintf(err.Error(), a...), b...)
|
||||
|
||||
29
util/uid/sqid.go
Normal file
29
util/uid/sqid.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package uid
|
||||
|
||||
import "github.com/sqids/sqids-go"
|
||||
|
||||
// use your own random version of alphabets
|
||||
// there is online util at the bottomt of this page: https://sqids.org/go
|
||||
var opts sqids.Options = sqids.Options{
|
||||
Alphabet: "fsvjrnGWiTk2Lt1l5MzEhFH73CIg60ByexQPYpX9Ro8ZKawAVUdNuDJbmqScO4",
|
||||
}
|
||||
|
||||
// Encode a slice of IDs into one unique ID
|
||||
func Encode(ids []uint64) (string, error) {
|
||||
s, err := sqids.New()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return s.Encode(ids) // "86Rf07"
|
||||
}
|
||||
|
||||
// Decode an ID back to slice of IDs
|
||||
func Decode(id string) ([]uint64, error) {
|
||||
s, err := sqids.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.Decode(id), nil
|
||||
}
|
||||
Reference in New Issue
Block a user