@ -1,3 +1,27 @@ | |||||
module goUtils | module goUtils | ||||
go 1.12 | go 1.12 | ||||
require ( | |||||
github.com/BurntSushi/toml v0.3.1 // indirect | |||||
github.com/Joker/jade v1.0.0 // indirect | |||||
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398 // indirect | |||||
github.com/aymerick/raymond v2.0.2+incompatible // indirect | |||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 // indirect | |||||
github.com/fatih/structs v1.1.0 // indirect | |||||
github.com/flosch/pongo2 v0.0.0-20200518135938-dfb43dbdc22a // indirect | |||||
github.com/gorilla/schema v1.1.0 // indirect | |||||
github.com/iris-contrib/blackfriday v2.0.0+incompatible // indirect | |||||
github.com/iris-contrib/formBinder v5.0.0+incompatible // indirect | |||||
github.com/iris-contrib/go.uuid v2.0.0+incompatible // indirect | |||||
github.com/json-iterator/go v1.1.9 // indirect | |||||
github.com/kataras/golog v0.0.15 // indirect | |||||
github.com/kataras/iris v11.1.1+incompatible // indirect | |||||
github.com/klauspost/compress v1.10.6 // indirect | |||||
github.com/microcosm-cc/bluemonday v1.0.2 // indirect | |||||
github.com/ryanuber/columnize v2.1.0+incompatible // indirect | |||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect | |||||
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a // indirect | |||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect | |||||
gopkg.in/yaml.v2 v2.3.0 // indirect | |||||
) |
@ -0,0 +1,35 @@ | |||||
package eventWay | |||||
type Event struct { | |||||
Name string | |||||
CfgId int | |||||
} | |||||
type HandlerErr struct { | |||||
Event Event | |||||
Handler Handler | |||||
ErrInfo error | |||||
} | |||||
type Handler func(msg interface{}) error | |||||
var eventMgr = map[Event][]Handler{} | |||||
func Register(event Event, handler Handler) { | |||||
if handlers, ok := eventMgr[event]; ok { | |||||
eventMgr[event] = append(handlers, handler) | |||||
} else { | |||||
eventMgr[event] = []Handler{handler} | |||||
} | |||||
} | |||||
func Publish(event Event, msg interface{}) (errs []HandlerErr) { | |||||
if handlers, ok := eventMgr[event]; ok { | |||||
for _, handler := range handlers { | |||||
if err := handler(msg); err != nil { | |||||
errs = append(errs, HandlerErr{Event: event, Handler: handler, ErrInfo: err}) | |||||
} | |||||
} | |||||
} | |||||
return errs | |||||
} |
@ -0,0 +1,31 @@ | |||||
package main | |||||
import ( | |||||
"fmt" | |||||
eventWay2 "goUtils/learn/eventWay/eventWay" | |||||
) | |||||
func hand1(msg interface{}) error { | |||||
println("IMY************ 111", msg) | |||||
return nil | |||||
} | |||||
func hand2(msg interface{}) error { | |||||
println("IMY************ 222", msg) | |||||
return nil | |||||
} | |||||
func hand3(msg interface{}) error { | |||||
fmt.Printf("IMY************ 333 %v\n", msg) | |||||
return nil | |||||
} | |||||
func main() { | |||||
eventWay2.Register(eventWay2.Event{Name: "str1"}, hand1) | |||||
eventWay2.Register(eventWay2.Event{Name: "str1"}, hand2) | |||||
eventWay2.Register(eventWay2.Event{Name: "str3"}, hand3) | |||||
eventWay2.Publish(eventWay2.Event{Name: "str1"}, "teste1") | |||||
eventWay2.Publish(eventWay2.Event{Name: "str3"}, "testt3") | |||||
eventWay2.Publish(eventWay2.Event{Name: "str2"}, "fdfdfdfdf") | |||||
} |
@ -0,0 +1,35 @@ | |||||
package main | |||||
import ( | |||||
"github.com/kataras/iris" | |||||
) | |||||
func main() { | |||||
app := iris.New() | |||||
app.Get("/", before, mainHandler, after) | |||||
app.Run(iris.Addr(":8081")) | |||||
} | |||||
func before(ctx iris.Context) { | |||||
shareInfo := "this is a shareInfo between handlers" | |||||
requestPath := ctx.Path() | |||||
println("Before the mainHandler: " + requestPath) | |||||
ctx.Values().Set("info", shareInfo) | |||||
ctx.Next() //继续下一个handler | |||||
} | |||||
func after(ctx iris.Context) { | |||||
println("after the mainHandler") | |||||
} | |||||
func mainHandler(ctx iris.Context) { | |||||
println("Inside mainHandler") | |||||
info := ctx.Values().GetString("info") | |||||
ctx.HTML("<h1>Response</h1>") | |||||
ctx.HTML("<br/> Info: " + info) | |||||
ctx.Next() | |||||
} |
@ -0,0 +1,34 @@ | |||||
package main | |||||
import ( | |||||
"github.com/kataras/iris" | |||||
"github.com/kataras/iris/mvc" | |||||
"strconv" | |||||
) | |||||
func main() { | |||||
app := iris.New() | |||||
mvc.Configure(app.Party("/root"), myMVC) | |||||
app.Run(iris.Addr(":8082")) | |||||
} | |||||
func myMVC(app *mvc.Application) { | |||||
app.Handle(new(MyController)) | |||||
} | |||||
type MyController struct{} | |||||
func (m *MyController) BeforeActivation(b mvc.BeforeActivation) { | |||||
b.Handle("GET", "/something/{id:long}", "MyCustomHandler") | |||||
} | |||||
// GET: http://localhost:8080/root | |||||
func (m *MyController) Get() string { return "Hey" } | |||||
// GET: http://localhost:8080/root/something/{id:long} | |||||
func (m *MyController) MyCustomHandler(id int64) string { | |||||
return "MyCustomHandler says Hey " + strconv.FormatInt(id, 10) | |||||
} |
@ -0,0 +1,44 @@ | |||||
package main | |||||
import ( | |||||
"github.com/kataras/iris" | |||||
"github.com/kataras/iris/middleware/logger" | |||||
"github.com/kataras/iris/middleware/recover" | |||||
"github.com/kataras/iris/mvc" | |||||
) | |||||
func main() { | |||||
app := iris.New() | |||||
app.Use(recover.New()) | |||||
app.Use(logger.New()) | |||||
mvc.New(app).Handle(new(ExampleController)) | |||||
// http://localhost:8080 | |||||
// http://localhost:8080/ping | |||||
// http://localhost:8080/hello | |||||
app.Run(iris.Addr(":8080")) | |||||
} | |||||
type ExampleController struct{} | |||||
func (c *ExampleController) Get() mvc.Result { | |||||
return mvc.Response{ | |||||
ContentType: "text/html", | |||||
Text: "<h1>Welcome</h1>", | |||||
} | |||||
} | |||||
func (c *ExampleController) GetPing() string { | |||||
return "Pong" | |||||
} | |||||
func (c *ExampleController) GetHello() interface{} { | |||||
return map[string]string{"massage": "hello Iris!"} | |||||
} | |||||
func (c *ExampleController) GetHellos() interface{} { | |||||
return map[string]string{"massage": "hellos Iris!"} | |||||
} |
@ -0,0 +1,23 @@ | |||||
package main | |||||
import ( | |||||
"context" | |||||
"github.com/kataras/iris" | |||||
"time" | |||||
) | |||||
func main() { | |||||
app := iris.New() | |||||
iris.RegisterOnInterrupt(func() { | |||||
timeout := 5 * time.Second | |||||
ctx, cancel := context.WithTimeout(context.Background(), timeout) | |||||
defer cancel() | |||||
// 关闭所有主机 | |||||
println("IMY*********** todo stop") | |||||
app.Shutdown(ctx) | |||||
}) | |||||
app.Get("/", func(ctx iris.Context) { | |||||
ctx.HTML("<h1>hi I just exist in order to see if the server is closed</h1>") | |||||
}) | |||||
app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler) | |||||
} |
@ -0,0 +1,19 @@ | |||||
package main | |||||
func test() { | |||||
var a int | |||||
defer func() { | |||||
if p := recover(); p != nil { | |||||
a = 1111 | |||||
} | |||||
}() | |||||
panic(2222) | |||||
print(a) | |||||
} | |||||
func main() { | |||||
test() | |||||
} |
@ -0,0 +1,48 @@ | |||||
package main | |||||
import ( | |||||
"github.com/kataras/iris" | |||||
"github.com/kataras/iris/middleware/logger" | |||||
"github.com/kataras/iris/middleware/recover" | |||||
"github.com/valyala/tcplisten" | |||||
) | |||||
func main() { | |||||
app := iris.New() | |||||
app.Use(recover.New()) | |||||
app.Use(logger.New()) | |||||
// 输出html | |||||
// 请求方式:GET | |||||
// 访问地址:http://localhost:8080/welcome | |||||
app.Handle("GET", "/welcome", func(ctx iris.Context) { | |||||
ctx.HTML("<h1>Welcome</h1>") | |||||
}) | |||||
// 输出字符串 | |||||
// 类似于app.Handle("GET", "/ping", [...]) | |||||
// 请求方式GET | |||||
// 请求地址:http://localhost:8080/ping | |||||
app.Get("/ping", func(ctx iris.Context) { | |||||
ctx.WriteString("Pong") | |||||
}) | |||||
// 输出JSON | |||||
// 请求方式:GET | |||||
// 请求地址: http://localhost:8080/hello | |||||
app.Get("/hello", func(ctx iris.Context) { | |||||
ctx.JSON(iris.Map{"message": "hello Iris!"}) | |||||
}) | |||||
listenerCfg := tcplisten.Config{ | |||||
ReusePort: true, | |||||
DeferAccept: true, | |||||
FastOpen: true, | |||||
} | |||||
l, err := listenerCfg.NewListener("tcp4", ":8080") | |||||
if err != nil { | |||||
app.Logger().Fatal(err) | |||||
} | |||||
app.Run(iris.Listener(l)) //8080 监听端口 | |||||
} |
@ -0,0 +1,9 @@ | |||||
SELECT DATE(FROM_UNIXTIME(created_at)) as group_date,COUNT(*) AS day1,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 1, 1, 0)) AS day2,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 2, 1, 0)) AS day3,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 3, 1, 0)) AS day4,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 4, 1, 0)) AS day5,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 5, 1, 0)) AS day6,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 6, 1, 0)) AS day7,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 14, 1, 0)) AS day14,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 30, 1, 0)) AS day30,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 60, 1, 0)) AS day60,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 90, 1, 0)) AS day90,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 120, 1, 0)) AS day120 FROM `roles` WHERE (created_at >= 1590451200 AND created_at <= 1590537599) AND (is_internal = false) AND (login_at != 0) GROUP BY DATE(FROM_UNIXTIME(created_at)) | |||||
SELECT DATE(FROM_UNIXTIME(created_at)) as group_date,COUNT(*) AS day1,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 1, 1, 0)) AS day2,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 2, 1, 0)) AS day3,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 3, 1, 0)) AS day4,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 4, 1, 0)) AS day5,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 5, 1, 0)) AS day6,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 6, 1, 0)) AS day7,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 14, 1, 0)) AS day14,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 30, 1, 0)) AS day30,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 60, 1, 0)) AS day60,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 90, 1, 0)) AS day90,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 120, 1, 0)) AS day120 FROM `roles` WHERE (created_at >= 1590451200 AND created_at <= 1590537599) AND (is_internal = false) AND (login_at != 0) GROUP BY DATE(FROM_UNIXTIME(created_at)) | |||||
SELECT DATE(FROM_UNIXTIME(created_at)) as group_date,COUNT(*) AS day1,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 1, 1, 0)) AS day2,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 2, 1, 0)) AS day3,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 3, 1, 0)) AS day4,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 4, 1, 0)) AS day5,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 5, 1, 0)) AS day6,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 6, 1, 0)) AS day7,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 14, 1, 0)) AS day14,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 30, 1, 0)) AS day30,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 60, 1, 0)) AS day60,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 90, 1, 0)) AS day90,SUM(if(DATEDIFF(FROM_UNIXTIME(login_at), FROM_UNIXTIME(created_at)) >= 120, 1, 0)) AS day120 FROM `roles` WHERE (created_at >= 1590451200 AND created_at <= 1590537599) AND (is_internal = false) AND (login_at != 0) GROUP BY DATE(FROM_UNIXTIME(created_at)) |
@ -0,0 +1,19 @@ | |||||
package main | |||||
import ( | |||||
"os" | |||||
"strconv" | |||||
"time" | |||||
) | |||||
func test() {} | |||||
func main() { | |||||
start := time.Now() | |||||
cnt, _ := strconv.Atoi(os.Args[1]) | |||||
for i := 0; i < cnt; i++ { | |||||
test() | |||||
} | |||||
println("IMY*****main*", time.Since(start).Microseconds(), "us") | |||||
} |