bdledger-apis/test/bdchain/api/mockserver/main.go
2018-10-10 11:56:23 +08:00

40 lines
642 B
Go

package main
import (
"flag"
"fmt"
"net"
"strconv"
"bdchain/api/grpc/txledger"
"google.golang.org/grpc"
)
func main() {
// flag
port := flag.Int("port", 10000, "set the port of test server")
flag.Parse()
// server
rpc := grpc.NewServer()
srv := (*grpcServer)(&server{})
txledger.RegisterTransactionLedgerServer(rpc, srv)
con, err := net.Listen("tcp", ":"+strconv.Itoa(*port))
if err == nil {
fmt.Println("server is running on", *port)
} else {
fmt.Println(err)
return
}
// start
err = rpc.Serve(con)
if err != nil {
fmt.Println("server closed with error", err)
} else {
fmt.Println("server closed")
}
}