admin项目公共方法解析
前言:
项目中公用的一些方法,配置,常量等
正文:
文件:common/inc.go
package common const TimeTem = "2006-01-02 15:04:05" const AdminSecret = "jO4s4QcGs4B8brP2" //随机秘钥 // 定义一个统一的返回对象 type ReData struct { Status bool Msg string Data interface{} }
文件:common/functions.go
package common import ( "crypto/md5" "encoding/hex" "strconv" "strings" ) //生成加密的密码 func MyMd5(str string) string { str = AdminSecret+str has := md5.New() has.Write([]byte(str)) b := has.Sum(nil) return hex.EncodeToString(b) } //管理后台权限判断 func HasPower(pids string ,pid int) bool{ id := strconv.Itoa(pid) ids := ","+id+"," return strings.Contains(pids,ids) }
完结
但行好事,莫问前程!
本文来自博客园,作者:yangphp,转载请注明原文链接:https://www.cnblogs.com/ypeih/p/17334574.html