go get -u gopkg.qsoa.cloud/service
go get -u gopkg.qsoa.cloud/service/qgrpc
go get -u gopkg.qsoa.cloud/service/qhttp
go get -u gopkg.qsoa.cloud/service/qmysql
package main
import (
"database/sql"
"log"
"gopkg.qsoa.cloud/service"
"gopkg.qsoa.cloud/service/example/grpc"
"gopkg.qsoa.cloud/service/example/grpc/pb"
"gopkg.qsoa.cloud/service/example/http"
"gopkg.qsoa.cloud/service/qgrpc"
"gopkg.qsoa.cloud/service/qhttp"
_ "gopkg.qsoa.cloud/service/qmysql"
)
func main() {
// Prepare gRpc client
conn, err := qgrpc.Dial("qcloud://" + service.GetService() + "/")
if err != nil {
log.Fatalf("Cannot dial grpc: %v", err)
}
defer conn.Close()
grpcClient := pb.NewTestClient(conn)
// Prepare mysql connection
db, err := sql.Open("qmysql", "example_db")
if err != nil {
log.Fatalf("Cannot open mysql database: %v", err)
}
defer db.Close()
// Provide HTTP service
qhttp.Handle("/", http.New(grpcClient, db))
// Provide gRPC service
pb.RegisterTestServer(qgrpc.GetServer(), grpc.Server{})
// Run service
service.Run()
}