Format test.md

This commit is contained in:
Nex
2018-10-11 02:26:22 +08:00
parent 77f2402609
commit 8e9d10c38b
6 changed files with 17 additions and 69 deletions

39
test/mockserver/main.go Normal file
View File

@@ -0,0 +1,39 @@
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")
}
}