utils

package
v1.0.1-0...-540a35a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2021 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

来自blueeye

来自blueeye

Index

Constants

View Source
const (
	KEY                    string = "JWT-ARY-STARK"
	DEFAULT_EXPIRE_SECONDS int    = 3000 //600 // default 10 minutes
	//SecretKey = "welcome to wangshubo's blog"
	SecretKey = "I have login"
)
View Source
const (
	KC_RAND_KIND_NUM   = 0 // 纯数字
	KC_RAND_KIND_LOWER = 1 // 小写字母
	KC_RAND_KIND_UPPER = 2 // 大写字母
	KC_RAND_KIND_ALL   = 3 // 数字、大小写字母
)

Variables

View Source
var (
	OK                    = &CodeWrapper{Code: "OK", HttpStatus: http.StatusOK, Description: "ok"}
	BAD_REQUEST           = &CodeWrapper{Code: "BAD_REQUEST", HttpStatus: http.StatusBadRequest, Description: "bad request"}
	NEED_SHARE_CODE       = &CodeWrapper{Code: "NEED_SHARE_CODE", HttpStatus: http.StatusUnauthorized, Description: "share code required"}
	SHARE_CODE_ERROR      = &CodeWrapper{Code: "SHARE_CODE_ERROR", HttpStatus: http.StatusUnauthorized, Description: "share code error"}
	LOGIN                 = &CodeWrapper{Code: "LOGIN", HttpStatus: http.StatusUnauthorized, Description: "not login"}
	USER_DISABLED         = &CodeWrapper{Code: "USER_DISABLED", HttpStatus: http.StatusForbidden, Description: "user disabled"}
	UNAUTHORIZED          = &CodeWrapper{Code: "UNAUTHORIZED", HttpStatus: http.StatusUnauthorized, Description: "unauthorized"}
	NOT_FOUND             = &CodeWrapper{Code: "NOT_FOUND", HttpStatus: http.StatusNotFound, Description: "404 not found"}
	RANGE_NOT_SATISFIABLE = &CodeWrapper{Code: "RANGE_NOT_SATISFIABLE", HttpStatus: http.StatusRequestedRangeNotSatisfiable, Description: "range not satisfiable"}
	NOT_INSTALLED         = &CodeWrapper{Code: "NOT_INSTALLED", HttpStatus: http.StatusInternalServerError, Description: "application not installed"}
	SERVER                = &CodeWrapper{Code: "SERVER", HttpStatus: http.StatusInternalServerError, Description: "server error"}
	UNKNOWN               = &CodeWrapper{Code: "UNKNOWN", HttpStatus: http.StatusInternalServerError, Description: "server unknow error"}
)
View Source
var (
	DB_ERROR_DUPLICATE_KEY  = "Error 1062: Duplicate entry"
	DB_ERROR_NOT_FOUND      = "record not found"
	DB_TOO_MANY_CONNECTIONS = "Error 1040: Too many connections"
	DB_BAD_CONNECTION       = "driver: bad connection"
)

db error.

View Source
var AesKey []byte
View Source
var FileLogs *logs.BeeLogger

var ConsoleLogs *logs.BeeLogger

View Source
var (
	SIGN_NAME_SCERET = "aweQurt178BNI"
)
View Source
var Tail = &Command{
	UsageLine: `tail -f main.go -l 10 -n 5 -o tmp.txt`,
	Run:       tail,
	Short:     "从文件结尾或指定位置读取内容",
	Long: `从文件结尾或指定位置读取内容,可以按行读取,也可以按大小读取,-i 和 -l同时使用的话-i生效,-s 与 -n 
同时使用的话-s生效`,
}

Functions

func AddMember

func AddMember(account, password string) error

func AllowCORS

func AllowCORS(writer http.ResponseWriter)

allow cors.

func Asset

func Asset(p string, cdn string) string

func AutoSummary

func AutoSummary(body string, l int) string

自动提取文章摘要

func CheckAuth

func CheckAuth(authString string) bool

func CheckToken

func CheckToken(tokenString string) (userName string, err error)

校验token是否有效 返回参数

func ConvertDateTimeStringToTime

func ConvertDateTimeStringToTime(timeString string) time.Time

convert time string(yyyy-MM-dd HH:mm:ss) to Time object

func ConvertTimeToDateString

func ConvertTimeToDateString(time time.Time) string

convert Time object to string(yyyy-MM-dd)

func ConvertTimeToDateTimeString

func ConvertTimeToDateTimeString(time time.Time) string

convert Time object to string(yyyy-MM-dd HH:mm:ss)

func ConvertTimeToTimeString

func ConvertTimeToTimeString(time time.Time) string

convert Time object to string(HH:mm:ss)

func CreateToken

func CreateToken(userName string) (tokenString string, err error)

使用这个生成token

func Decode

func Decode(value string, r interface{}) error

解码

func DisableCache

func DisableCache(writer http.ResponseWriter)

disable cache.

func Encode

func Encode(value interface{}) (string, error)

编码

func EncodingAESKey2AESKey

func EncodingAESKey2AESKey(encodingKey string) []byte

func FetchHttpStatus

func FetchHttpStatus(code string) int

func FirstMinuteOfDay

func FirstMinuteOfDay(day time.Time) time.Time

func FirstSecondOfDay

func FirstSecondOfDay(day time.Time) time.Time

func GenerateToken

func GenerateToken(expiredSeconds int) (tokenString string)

func GetAccessToken

func GetAccessToken(app_version string) (accesstoken string, errcode float64, errmsg string, err error)

验证token时效性

func GetFileType

func GetFileType(fSrc []byte) string

用文件前面几个字节来判断 fSrc: 文件字节流(就用前面几个字节)

func GetHostFromRequest

func GetHostFromRequest(request *http.Request) string

get host from request

func GetIpAddress

func GetIpAddress(r *http.Request) string

get ip from request

func GetMysqlUrl

func GetMysqlUrl(
	mysqlPort int,
	mysqlHost string,
	mysqlSchema string,
	mysqlUsername string,
	mysqlPassword string) string

get mysql url.

func GetSessionUuidFromRequest

func GetSessionUuidFromRequest(request *http.Request, cookieAuthKey string) string

get cookieAuthKey from request.

func HumanFileSize

func HumanFileSize(bytes int64) string

human readable file size

func ImgSecCheck

func ImgSecCheck(bts []byte, accessToken string) (errcode float64, errmsg string, err error)

func JoinURI

func JoinURI(elem ...string) string

func JsonResponse

func JsonResponse(response interface{}, w http.ResponseWriter)

func Krand

func Krand(size int, kind int) []byte

随机字符串

func LastSecondOfDay

func LastSecondOfDay(day time.Time) time.Time

func LoginHandler

func LoginHandler(w http.ResponseWriter, r *http.Request)

服务端生成token,并放入到response的header * JWT由三部份组成: * Header:头部 (对应:Header) * Claims:声明 (对应:Payload) * Signature:签名 (对应:Signature)

func LubanCheckToken

func LubanCheckToken(tokenString string) (userId, userName, userNickname string, err error)

校验token是否有效 返回参数

func ModifyPassword

func ModifyPassword(account, old_password, new_password string) error

func MsgSecCheck

func MsgSecCheck(scene, version int, access_token, openid, content string) (errcode float64, errmsg string, err error)

文本敏感字符检测

func ParseAuthToken

func ParseAuthToken()

func ParseToken

func ParseToken(authString string) (t *jwt.Token, err error)

ParseToken parse JWT token in http header.

func PasswordHash

func PasswordHash(pass string) (string, error)

加密密码

func PasswordVerify

func PasswordVerify(hashing string, pass string) (bool, error)

校验密码是否有效

func RandomNumber4

func RandomNumber4() string

get random number 4.

func RandomString4

func RandomString4() string

get random 4 string

func RefreshToken

func RefreshToken(tokenString string) (string, error)

update expireAt and return a new token

func SafetyProcessor

func SafetyProcessor(html string) string

安全处理HTML文档,过滤危险标签和属性.

func SendMessage

func SendMessage(access_token, openid, template_id string) (errcode float64, errmsg string, err error)

发送订阅消息

func StripTags

func StripTags(s string) string

func SubString

func SubString(str string, begin, length int) (substr string)

如果不够length,返回全部长度范围

func TestGetFileType

func TestGetFileType(t *testing.T)

func TestLog

func TestLog(t *testing.T)

func Tomorrow

func Tomorrow() time.Time

Tomorrow right now

func ValidLDAPLogin

func ValidLDAPLogin(password string) (result bool, err error)

func ValidateToken

func ValidateToken(tokenString string) error

func VerifyToken

func VerifyToken(tokenString string) bool

token验证

func Yesterday

func Yesterday() time.Time

Yesterday right now

Types

type CodeWrapper

type CodeWrapper struct {
	Code        string
	HttpStatus  int
	Description string
}

type Command

type Command struct {
	UsageLine string
	Run       func(*Command, []string) bool
	Short     string
	Long      string
}

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func InitConnection

func InitConnection(wsConn *websocket.Conn) (conn *Connection, err error)

func (*Connection) Close

func (conn *Connection) Close()

func (*Connection) ReadMessage

func (conn *Connection) ReadMessage() (data []byte, err error)

func (*Connection) WriteMessage

func (conn *Connection) WriteMessage(data []byte) (err error)

type Data

type Data struct {
	Keyword1 WxKeyword `json:"keyword1"`
	Keyword2 WxKeyword `json:"keyword2"`
	Keyword3 WxKeyword `json:"keyword3"`
}

type Message

type Message struct {
	Touser      string `json:"touser"`
	Template_id string `json:"template_id"`
	Page        string `json:"page"`
	Data        data   `json:"data"`
}

type MsgInput

type MsgInput struct {
	Openid  string `json:"openid"`
	Scene   int    `json:"scene"`
	Version int    `json:"version"`
	Content string `json:"content"`
}

type MyCustomClaims

type MyCustomClaims struct {
	User
	jwt.StandardClaims
}

JWT -- json web token HEADER PAYLOAD SIGNATURE This struct is the PAYLOAD

type Response

type Response struct {
	Data string `json:"data"`
}

type TailFile

type TailFile struct {
	// contains filtered or unexported fields
}

func NewTail

func NewTail(File *os.File) *TailFile

func (*TailFile) Close

func (f *TailFile) Close() error

func (*TailFile) Read

func (f *TailFile) Read(offset, size, lines int64, w io.Writer) error

func (*TailFile) ReadLine

func (f *TailFile) ReadLine() ([]byte, error)

暂时用不到

func (*TailFile) TailLine

func (f *TailFile) TailLine(line, lines int, w io.Writer) (err error)

type Token

type Token struct {
	Token string `json:"token"`
}

type User

type User struct {
	Id       string `json:"id"`
	Name     string `json:"json"`
	Password string `json:"password"`
}

type UserCredentials

type UserCredentials struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type WebResult

type WebResult struct {
	Code string      `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func BadRequest

func BadRequest(format string, v ...interface{}) *WebResult

func ConstWebResult

func ConstWebResult(codeWrapper *CodeWrapper) *WebResult

func CustomWebResult

func CustomWebResult(codeWrapper *CodeWrapper, description string) *WebResult

func NotFound

func NotFound(format string, v ...interface{}) *WebResult

func Server

func Server(format string, v ...interface{}) *WebResult

sever inner error

func Unauthorized

func Unauthorized(format string, v ...interface{}) *WebResult

func (*WebResult) Error

func (this *WebResult) Error() string

type WxKeyword

type WxKeyword struct {
	Value string `json:"value"`
}

type WxPushContent

type WxPushContent struct {
	Push_record_id   int    `json:"push_record_id"`
	Template_id      string `json:"template_id"`
	Page             string `json:"page"`
	Data             Data   `json:"data"`
	Emphasis_keyword string `json:"emphasis_keyword"`
}

Directories

Path Synopsis
Package wkhtmltopdf contains wrappers around the wkhtmltopdf commandline tool
Package wkhtmltopdf contains wrappers around the wkhtmltopdf commandline tool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL