Skip to content
This repository has been archived by the owner on Jan 17, 2020. It is now read-only.

seerx/got

Repository files navigation

概述

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")

About

Golang 常用功能工具库(自用)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages