mirror of
https://github.com/go-micro/go-micro.git
synced 2025-02-10 18:31:40 +02:00
34 lines
494 B
Go
34 lines
494 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
|
|
"context"
|
|
"go-micro.dev/v4"
|
|
)
|
|
|
|
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()
|
|
}
|