github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/secure/srv/main.go (about) 1 package main 2 3 import ( 4 "log" 5 "time" 6 7 "context" 8 hello "github.com/micro/go-micro/examples/greeter/srv/proto/hello" 9 "github.com/micro/go-micro/v2" 10 "github.com/micro/go-micro/v2/transport" 11 ) 12 13 type Say struct{} 14 15 func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error { 16 rsp.Msg = "Hello " + req.Name 17 return nil 18 } 19 20 func main() { 21 service := micro.NewService( 22 micro.Name("go.micro.srv.greeter"), 23 micro.RegisterTTL(time.Second*30), 24 micro.RegisterInterval(time.Second*10), 25 // setup a new transport with secure option 26 micro.Transport( 27 // create new transport 28 transport.NewTransport( 29 // set to automatically secure 30 transport.Secure(true), 31 ), 32 ), 33 ) 34 35 service.Init() 36 37 hello.RegisterSayHandler(service.Server(), new(Say)) 38 39 if err := service.Run(); err != nil { 40 log.Fatal(err) 41 } 42 }