service := micro.NewService() ctx, cancel := context.WithCancel(context.Background()) service.Init( micro.Context(ctx), micro.BeforeStart(func() error { go func() { // 这里可以写个init gin的function router = gin.Default() log.Info("gin start...") router.Run(":8080") log.WithError(err).Error("gin stop...") cancel() }() }), ) service.Run()