//go:build ignore // +build ignore package main import ( "log" "os" "os/signal" "syscall" "time" "git.me9.top/git/tinymq" "git.me9.top/git/tinymq/config" "git.me9.top/git/tinymq/conn" ) // 代理架构 func main() { cf := config.NewConfig() localChannel := "/tinymq/proxy" var hub *tinymq.Hub hub = tinymq.NewHub( cf, localChannel, nil, func(host *conn.HostInfo, proto string, version uint8, channel string, remoteAuth []byte) (auth []byte) { log.Println("[AuthFunc]", host, proto, version, channel, string(remoteAuth)) return []byte("tinymq-proxy") }, func(host *conn.HostInfo, proto string, version uint8, channel string, auth []byte) bool { log.Println("[CheckAuthFunc]", host, proto, version, channel, string(auth)) return true }, func(conn *tinymq.Line) { log.Println("[Connect state change]", conn.Channel(), conn.State(), time.Since(conn.Started())) }, ) // tcp2协议 bindTpv2Info := &conn.HostInfo{ Proto: "tcp", Version: 2, Bind: "127.0.0.1", Port: 44222, Hash: "xor:1qaz2wsx3", } hub.BindForServer(bindTpv2Info) // ws2协议 bindws2Info := &conn.HostInfo{ Proto: "ws", Version: 2, Bind: "127.0.0.1", Port: 44211, Path: "/tinymq-xor", Hash: "xor:1qaz2wsx3edc", } hub.BindForServer(bindws2Info) // ws2协议,没有加密算法 bindInfo := &conn.HostInfo{ Proto: "ws", Version: 2, // Bind: "127.0.0.1", Port: 44211, Path: "/tinymq", } hub.BindForServer(bindInfo) // 初始化一个channel exit := make(chan os.Signal, 3) //notify方法用来监听收到的信号 signal.Notify(exit, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) sig := <-exit log.Println("[Exist with]", sig.String()) }