2020-12-26 15:17:20 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"context"
|
2021-01-20 13:54:31 +00:00
|
|
|
"github.com/asim/go-micro/v3"
|
2020-12-26 15:17:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// cancellation context
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
// shutdown after 5 seconds
|
|
|
|
go func() {
|
|
|
|
<-time.After(time.Second * 5)
|
|
|
|
log.Println("Shutdown example: shutting down service")
|
|
|
|
cancel()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// create service
|
|
|
|
service := micro.NewService(
|
|
|
|
// with our cancellation context
|
|
|
|
micro.Context(ctx),
|
|
|
|
)
|
|
|
|
|
|
|
|
// init service
|
|
|
|
service.Init()
|
|
|
|
|
|
|
|
// run service
|
|
|
|
service.Run()
|
|
|
|
}
|