utils

package
v0.0.0-...-4c735e4 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LongDateFormat  = "2006-01-02 15:04:05"
	ShortDateFormat = "2006-01-02"
)

Variables

View Source
var Agentid = ""
View Source
var Corpid = ""
View Source
var CurrentMode = "DEV"
View Source
var MONGODB = "mongodb://root:root@192.168.2.173:27017/"
View Source
var PORT = 7999
View Source
var Secret = ""
View Source
var TokenManager *manage.Manager

Functions

func DownloadFile

func DownloadFile(fileName string, url string) (err error)

网络文件下载

func GenerateToken

func GenerateToken(clientID string, clientSecret string) (ti oauth2.TokenInfo, err error)

func Get

func Get(apiURL string, params url.Values) (rs []byte, err error)

get 网络请求

func GetLongDateString

func GetLongDateString(date string, Hours int64) (dateString string, err error)

获取日期格式

func GetMinuteDiffer

func GetMinuteDiffer(start_time, end_time string) int64

获取相差时间

func GetRandomString

func GetRandomString(l int) string

随机生成大写字母

func HttpGet

func HttpGet(apiURL string, params url.Values) (rs []byte, err error)

网络请求GET

func HttpPostBody

func HttpPostBody(apiURL string, params url.Values, body string) (rs []byte, err error)

网络请求POST body

func HttpPostFile

func HttpPostFile(filename string, apiURL string, params url.Values) (rs []byte, err error)

网络请求POST multipart(二进制上传)

func PathExists

func PathExists(path string) (bool, error)

func RemoveRepeatedElement

func RemoveRepeatedElement(arr []string) (newArr []string)

移除重复数据

func Round

func Round(f float64, n int) float64

func RunMode

func RunMode(CurrentMode string)

func SubString

func SubString(source string, start int, end int) string

获取source的子串,如果start小于0或者end大于source长度则返回"" start:开始index,从0开始,包括0 end:结束index,以end结束,但不包括end

func Substr

func Substr(str string, start int, length int) string

func ToFloat64

func ToFloat64(ori []byte) (re float64)

func XlsxFileReader

func XlsxFileReader(mimeFile multipart.File) (*xlsx.File, error)

Types

type Session

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

—————————————————————————— 会话

type SessionMgr

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

Session会话管理

var GlobalsessionMgr *SessionMgr = nil //session管理器

func NewSessionMgr

func NewSessionMgr(cookieName string, maxLifeTime int64) *SessionMgr

创建会话管理器(cookieName:在浏览器中cookie的名字;maxLifeTime:最长生命周期)

func (*SessionMgr) CheckCookieValid

func (mgr *SessionMgr) CheckCookieValid(w http.ResponseWriter, r *http.Request) string

判断Cookie的合法性(每进入一个页面都需要判断合法性)

func (*SessionMgr) EndSession

func (mgr *SessionMgr) EndSession(w http.ResponseWriter, r *http.Request)

结束Session

func (*SessionMgr) EndSessionBy

func (mgr *SessionMgr) EndSessionBy(sessionID string)

结束session

func (*SessionMgr) GC

func (mgr *SessionMgr) GC()

GC回收

func (*SessionMgr) GetLastAccessTime

func (mgr *SessionMgr) GetLastAccessTime(sessionID string) time.Time

更新最后访问时间

func (*SessionMgr) GetSessionIDList

func (mgr *SessionMgr) GetSessionIDList() []string

得到sessionID列表

func (*SessionMgr) GetSessionVal

func (mgr *SessionMgr) GetSessionVal(sessionID string, key interface{}) (interface{}, bool)

得到session里面的值

func (*SessionMgr) NewSessionID

func (mgr *SessionMgr) NewSessionID() string

创建唯一ID

func (*SessionMgr) SetSessionVal

func (mgr *SessionMgr) SetSessionVal(sessionID string, key interface{}, value interface{}, w http.ResponseWriter)

设置session里面的值

func (*SessionMgr) StartSession

func (mgr *SessionMgr) StartSession(w http.ResponseWriter, r *http.Request) string

在开始页面登陆页面,开始Session

type Size

type Size interface {
	Size() int64
}

获取文件大小的接口

type TokenUser

type TokenUser struct {
	Id         bson.ObjectId `bson:"_id"`
	EmployeeNo string        `bson:"ID"`
}

func GetUserTokenSecret

func GetUserTokenSecret(clientID string, clientSecret string) (theOne *TokenUser, err error)

Jump to

Keyboard shortcuts

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