/* * * Copyright 2015 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ // Package main implements a server for Greeter service. package main import ( "flag" "fmt" "log" "net" pb "github.com/pingcap/kvproto/pkg/autoid" "github.com/pingcap/tidb/pkg/autoid_service" "github.com/pingcap/tidb/pkg/store" "github.com/pingcap/tidb/pkg/store/driver" "google.golang.org/grpc" ) var ( port = flag.Int("port", 10080, "The server port") ) func main() { flag.Parse() err := store.Register("tikv", driver.TiKVDriver{}) if err != nil { panic(err) } lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) if err != nil { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() store, err := store.New("tikv://127.0.0.1:2379") if err != nil { panic(err) } service := autoid.New("192.168.0.16:10080", []string{"127.0.0.1:2379"}, store, nil) pb.RegisterAutoIDAllocServer(s, service) log.Printf("server listening at %v", lis.Addr()) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) } }