51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
|
||
|
"google.golang.org/grpc"
|
||
|
|
||
|
"git.loafle.net/overflow/overflow_websocket_service/service"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
host = "localhost:8080"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
connPool, err := service.New(10, 30, func() (*grpc.ClientConn, error) {
|
||
|
return grpc.Dial(*contentGrpcAddr, grpc.WithDialer(dialer), grpc.WithInsecure())
|
||
|
})
|
||
|
if err != nil {
|
||
|
log.Fatalf("create service connection pool error: %v\n", err)
|
||
|
}
|
||
|
defer connPool.Destroy()
|
||
|
connPool.Ping = func(conn *grpc.ClientConn) bool {
|
||
|
// check connection status
|
||
|
return true
|
||
|
}
|
||
|
connPool.Close = func(conn *grpc.ClientConn) {
|
||
|
// close connection
|
||
|
conn.Close()
|
||
|
}
|
||
|
|
||
|
// ws := websocket.New(websocket.Config{})
|
||
|
// http.HandleFunc("/ws", ws.Handler())
|
||
|
|
||
|
// ws.OnConnection(handleWebsocketConnection)
|
||
|
|
||
|
// http.ListenAndServe(host, nil)
|
||
|
}
|
||
|
|
||
|
func handleWebsocketConnection(c websocket.Connection) {
|
||
|
}
|
||
|
|
||
|
func callGrpcService(connPool *service.Pool) {
|
||
|
conn, err := connPool.Get()
|
||
|
if err != nil {
|
||
|
log.Printf("get connection error: %v\n", err)
|
||
|
}
|
||
|
// * Important
|
||
|
defer connPool.Put(conn)
|
||
|
}
|