You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
828 B
36 lines
828 B
package seniverse
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.codecodify.com/golang/tool/helper"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
var secret = "" // 私钥
|
|
var publicKey = "" // 公钥
|
|
|
|
func init() {
|
|
// 从环境变量中获取私钥和公钥
|
|
secret = helper.Ternary(os.Getenv("SENIVERSE_SECRET") != "", os.Getenv("SENIVERSE_SECRET"), secret).(string)
|
|
publicKey = helper.Ternary(os.Getenv("SENIVERSE_PUBLIC_KEY") != "", os.Getenv("SENIVERSE_PUBLIC_KEY"), publicKey).(string)
|
|
}
|
|
|
|
// SetSecretAndPublicKey 设置私钥和公钥
|
|
func SetSecretAndPublicKey(s, p string) {
|
|
secret = s
|
|
publicKey = p
|
|
}
|
|
|
|
// 获取请求参数
|
|
func getParams(locations string) map[string]string {
|
|
ts := fmt.Sprintf("%d", time.Now().Unix())
|
|
ttl := "600"
|
|
return map[string]string{
|
|
"ts": ts,
|
|
"ttl": ttl,
|
|
"public_key": publicKey,
|
|
"locations": locations,
|
|
}
|
|
}
|