站点更新:2018-07-31 17:06:12
This commit is contained in:
parent
d8c8935d0c
commit
3579e111a3
50
main.go
Normal file
50
main.go
Normal file
@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
jwtgo "github.com/dgrijalva/jwt-go"
|
||||
|
||||
"github.com/ehlxr/go-utils/utils/log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
type jwtAuthenticator struct {
|
||||
keyFunc jwtgo.Keyfunc
|
||||
}
|
||||
|
||||
var claims = &jwtgo.StandardClaims{}
|
||||
tokenStr := "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjZXJlcy5lbm5jbG91ZC5jbjphcHA6eTdnSU9hemlSIiwiY2VyZXMuZW5uY2xvdWQuY24vYXBwLmlkIjoieTdnSU9hemlSIiwiY2VyZXMuZW5uY2xvdWQuY24vbmFtZXNwYWNlIjoiZy1jZXJlcyJ9.JhSzDnUcCfenDFQkTudaAzLO2JJKaghTOPnHNT9bz4nysVFzSAD-wP4mIiQKTKGPYP4442QGbRtxocTZx-VTK7YkdEKh-QZDkpyyfNi7loTCdCDrcMUQHwK4w8zhZ8KzKOXQrmsYkMSO_kJ8FNKCpOpOeUS5zu-BN39MrgqwE5evFsE-9C-MhrsKzOxuLv5I_cF5AqNnfhHcdCdF7PhHEmXsWC8S_9ep21MxaPhXTspeZa56eZHylV5ddm-bj8WR4r_2OsBI0k1QRN_SZNh8j35eB-Ht3sReVBvYnAHyvGptB8kFTuN6fF-Lkxi-OhkxncAGpl0UpdA5gJ9U0zHaHEM18eE7yr2wQKZIPEWAvtP4xOVPK3GfCx6UAX5HU1Vp5OwSkIW-L6TIUfuGpTAfa36UyDpybXlQ6sU6kGbT5jTetffAjf3FLN4HbS61Mgj1QSjii2dUd2L3lT-jv1d2jSQJGtozL-sapRQ7o6F-IlIaRGmYV0AP7lhN7Pu-22SWseRBVYlkvdgcPXODm_WDmpxBVq77hAyJI2_ARAmbXRGfBDKmwD6kYD2YAvG8wAMiZApFazamwAIQKHmy0Y4tv8I2-r9YlOF5ri4vaZ36Uv65C9YaSL6ctbb25TwMHDVzwSaIYv-HhLMYxGxNBJxnOnIG-SHIE0f1rgYynJbL1sg"
|
||||
token, err := jwtgo.ParseWithClaims(tokenStr, claims, func(*jwtgo.Token) (interface{}, error) {
|
||||
|
||||
f, err := os.Open("api-token-public.pem")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
fd, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return jwtgo.ParseRSAPublicKeyFromPEM(fd)
|
||||
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
|
||||
if !token.Valid {
|
||||
return
|
||||
}
|
||||
|
||||
log.Debugf("jwt token received: %v", claims)
|
||||
|
||||
// appKey@namespace
|
||||
temp := strings.Split(claims.Subject, "@")
|
||||
fmt.Println(temp[0])
|
||||
}
|
61
utils/decimalconvert/main.go
Normal file
61
utils/decimalconvert/main.go
Normal file
@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var tenToAny map[int]string = map[int]string{0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "a", 11: "b", 12: "c", 13: "d", 14: "e", 15: "f", 16: "g", 17: "h", 18: "i", 19: "j", 20: "k", 21: "l", 22: "m", 23: "n", 24: "o", 25: "p", 26: "q", 27: "r", 28: "s", 29: "t", 30: "u", 31: "v", 32: "w", 33: "x", 34: "y", 35: "z", 36: ":", 37: ";", 38: "<", 39: "=", 40: ">", 41: "?", 42: "@", 43: "[", 44: "]", 45: "^", 46: "_", 47: "{", 48: "|", 49: "}", 50: "A", 51: "B", 52: "C", 53: "D", 54: "E", 55: "F", 56: "G", 57: "H", 58: "I", 59: "J", 60: "K", 61: "L", 62: "M", 63: "N", 64: "O", 65: "P", 66: "Q", 67: "R", 68: "S", 69: "T", 70: "U", 71: "V", 72: "W", 73: "X", 74: "Y", 75: "Z"}
|
||||
|
||||
func main() {
|
||||
fmt.Println(decimalToAny(1024126004316082177, 2))
|
||||
fmt.Println(anyToDecimal("111000110110011011010010110011000100100000000001000000000000", 2))
|
||||
}
|
||||
|
||||
// 10进制转任意进制
|
||||
func decimalToAny(num, n int) string {
|
||||
new_num_str := ""
|
||||
var remainder int
|
||||
var remainder_string string
|
||||
for num != 0 {
|
||||
remainder = num % n
|
||||
if 76 > remainder && remainder > 9 {
|
||||
remainder_string = tenToAny[remainder]
|
||||
} else {
|
||||
remainder_string = strconv.Itoa(remainder)
|
||||
}
|
||||
new_num_str = remainder_string + new_num_str
|
||||
num = num / n
|
||||
}
|
||||
return new_num_str
|
||||
}
|
||||
|
||||
// map根据value找key
|
||||
func findkey(in string) int {
|
||||
result := -1
|
||||
for k, v := range tenToAny {
|
||||
if in == v {
|
||||
result = k
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 任意进制转10进制
|
||||
func anyToDecimal(num string, n int) int {
|
||||
var new_num float64
|
||||
new_num = 0.0
|
||||
nNum := len(strings.Split(num, "")) - 1
|
||||
for _, value := range strings.Split(num, "") {
|
||||
tmp := float64(findkey(value))
|
||||
if tmp != -1 {
|
||||
new_num = new_num + tmp*math.Pow(float64(n), float64(nNum))
|
||||
nNum = nNum - 1
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return int(new_num)
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"foo": "bar",
|
||||
"exp": "2108-02-03",
|
||||
"info": "jjjkk",
|
||||
"other": "靠捡垃圾困了就睡打发士大夫斯柯达房间爱劳动法"
|
||||
"ceres.enncloud.cn/app.id": "loaclDemo",
|
||||
"ceres.enncloud.cn/namespace": "g-laikang-sh-dev",
|
||||
"sub": "ceres.enncloud.cn:app:loaclDemo"
|
||||
}
|
Loading…
Reference in New Issue
Block a user