got

package module
v0.0.0-...-fe11d09 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

README

概述

Golang 常用功能工具库

MD5、目录相关操作、格式化时间

Web Server 一些操作的封装,简化开发,增强功能

增加 session 功能

获取包

go get github.com/seerx/got

web server

简单实例 main.go

package main

import (
	"log"
	"net/http"

	"github.com/seerx/got"
	"github.com/seerx/got/gottp"
)

var svr *http.Server

func init() {
	svr = &http.Server{Addr: ":8099"}

	got.GET("/hello", hello)
}

func hello(ctx *gottp.Context) {
	ctx.ResponseText("Hello Golang!")
}

func main() {
	def := got.DefaultRouter()
	svr.Handler = def.GetHTTPRouter()
	log.Fatal(svr.ListenAndServe())
}

在终端运行

go run main.go

在浏览器中输入 http://localhost:8099/hello 可以看到运行结果

使用 session 功能

首先在 mann.go 的 init() 函数中添加

cache := cache.NewCacheManager(memcache.PROVIDER, 600)
gottp.InitSession("go-session", cache)

在 handlers 中即可以使用 ctx.GetSession() 来获取和使用 session 了

ss := ctx.GetSession()
ss.Set("test", "OK")
val := ss.Get("test")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheManager *cache.Manager

CacheManager 缓存管理

Functions

func AESDecrypt

func AESDecrypt(src, k, n string) (string, error)

AESDecrypt AES 解密

func AESEncrypt

func AESEncrypt(src, k, n string) (string, error)

AESEncrypt AES 加密

func CacheDestroy

func CacheDestroy(name string)

CacheDestroy 销毁缓存对象

func CacheGet

func CacheGet(name string) cache.Entity

CacheGet 获取缓存对象 调用前确保已经初始化 got.InitCacheManager(...)

func CacheNew

func CacheNew(name string) cache.Entity

CacheNew 创建缓存对象

func DEBUG

func DEBUG(fn func(string))

DEBUG 设置 debug 函数

func DELETE

func DELETE(path string, handler gottp.Handler)

DELETE 在默认的 defaultConetx 上注册 DELETE 请求

func DefaultRouter

func DefaultRouter() *gottp.Router

DefaultRouter 获取默认的 Router

func DirecotoryExists

func DirecotoryExists(path string) (bool, error)

DirecotoryExists 路径是否存在

func ERROR

func ERROR(fn func(error))

ERROR 设置 错误信息 函数

func GET

func GET(path string, handler gottp.Handler)

GET 在默认的 defaultConetx 上注册 GET 请求

func GetIP

func GetIP() string

GetIP 获取本机 IP 地址

func GetMyPath

func GetMyPath() string

GetMyPath 获取可执行程序所在路径

func HEAD(path string, handler gottp.Handler)

HEAD 在默认的 defaultConetx 上注册 HEAD 请求

func InitCacheManager

func InitCacheManager(provider string, expiredTime int64)

InitCacheManager 初始化缓存管理器 不用自己维护,使用全局的 CacheManager @param expiredTime 秒

func InitGoQL

func InitGoQL(g *goql.GQL, path string, cfg *handler.Config)

InitGoQL 初始化 goql

func InitGraphQL

func InitGraphQL(g *gql.GQL, path string, cfg *handler.Config)

InitGraphQL 初始化 GraphQL

func Ip2long

func Ip2long(ipstr string) uint32

Ip2long 字符串 IP 地址转 long

func JoinPath

func JoinPath(basePath string, relatePath string) string

JoinPath 计算真实路径,去掉 .. 之类的目录层次

func Long2ip

func Long2ip(ipLong uint32) string

Long2ip long 转字符串 IP

func MD5

func MD5(val string) string

MD5 MD5 加密

func MakeDirecotories

func MakeDirecotories(path string) bool

MakeDirecotories 连续创建路径

func POST

func POST(path string, handler gottp.Handler)

POST 在默认的 defaultConetx 上注册 POST 请求

func PUT

func PUT(path string, handler gottp.Handler)

PUT 在默认的 defaultConetx 上注册 PUT 请求

func ParseJSONFile

func ParseJSONFile(file string, v interface{}) error

ParseJSONFile 解析 json 文件

func UUID

func UUID() string

UUID 生成 uuid

func WriteJSONFile

func WriteJSONFile(file string, v interface{}) error

WriteJSONFile 写入 json 文件

Types

type TF

type TF struct {

	//年月日之间的分隔符
	Y string // 年
	M string // 月
	D string // 日
	// YMD string
	//日期和时间之间的分隔符
	DT string
	//时分秒之间的分隔符
	H  string
	Mn string
	S  string
	// contains filtered or unexported fields
}

TF 时间格式化

func NewChineseTimeFormatter

func NewChineseTimeFormatter() *TF

NewChineseTimeFormatter 创建中文格式化日期

func NewTimeFormatter

func NewTimeFormatter() *TF

NewTimeFormatter 创建时间格式化对象 默认使用 yyyy-mm-dd hh:mm:ss 形式

func (*TF) FormatDate

func (tf *TF) FormatDate(time time.Time) string

FormatDate 格式化日期

func (*TF) FormatDateTime

func (tf *TF) FormatDateTime(time time.Time) string

FormatDateTime 格式化时间

func (*TF) FormatDateTimeM

func (tf *TF) FormatDateTimeM(time time.Time) string

FormatDateTimeM 格式化时间,末尾带毫秒

func (*TF) FormatTime

func (tf *TF) FormatTime(time time.Time) string

FormatTime 格式化时间

func (*TF) FormatTimeM

func (tf *TF) FormatTimeM(time time.Time) string

FormatTimeM 格式化时间,末尾带毫秒

func (*TF) GetDateTemplate

func (tf *TF) GetDateTemplate() string

GetDateTemplate 获取日期格式模板

func (*TF) GetDatetimeMTemplate

func (tf *TF) GetDatetimeMTemplate() string

GetDatetimeMTemplate 获取日期及时间(含毫秒)格式模板

func (*TF) GetDatetimeTemplate

func (tf *TF) GetDatetimeTemplate() string

GetDatetimeTemplate 获取日期及时间格式模板

func (*TF) GetTimeTemplate

func (tf *TF) GetTimeTemplate() string

GetTimeTemplate 获取时间格式模板

func (*TF) ParseDate

func (tf *TF) ParseDate(date string) (time.Time, error)

ParseDate 解析日期

func (*TF) ParseDatetime

func (tf *TF) ParseDatetime(date string) (time.Time, error)

ParseDatetime 解析日期及时间

func (*TF) ParseDatetimeM

func (tf *TF) ParseDatetimeM(date string) (time.Time, error)

ParseDatetimeM 解析日期及时间(含毫秒)

func (*TF) ParseTime

func (tf *TF) ParseTime(date string) (time.Time, error)

ParseTime 解析时间

Directories

Path Synopsis
examples
pkg
clog
** 文本日志
** 文本日志

Jump to

Keyboard shortcuts

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