github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/config/server/server.go (about)

     1  package server
     2  
     3  import (
     4  	pb "github.com/tickoalcantara12/micro/v3/proto/config"
     5  	"github.com/tickoalcantara12/micro/v3/service"
     6  	"github.com/tickoalcantara12/micro/v3/service/config/handler"
     7  	"github.com/tickoalcantara12/micro/v3/service/logger"
     8  	"github.com/tickoalcantara12/micro/v3/service/store"
     9  	"github.com/urfave/cli/v2"
    10  )
    11  
    12  const (
    13  	name    = "config"
    14  	address = ":8001"
    15  )
    16  
    17  var (
    18  	// Flags specific to the config service
    19  	Flags = []cli.Flag{
    20  		&cli.StringFlag{
    21  			Name:    "watch_topic",
    22  			EnvVars: []string{"MICRO_CONFIG_SECRET_KEY"},
    23  			Usage:   "watch the change event.",
    24  		},
    25  	}
    26  )
    27  
    28  // Run micro config
    29  func Run(c *cli.Context) error {
    30  	srv := service.New(
    31  		service.Name(name),
    32  		service.Address(address),
    33  	)
    34  
    35  	store.DefaultStore.Init(store.Table("config"))
    36  
    37  	// register the handler
    38  	pb.RegisterConfigHandler(srv.Server(), handler.NewConfig(c.String("config_secret_key")))
    39  	// register the subscriber
    40  	//srv.Subscribe(watchTopic, new(watcher))
    41  
    42  	if err := srv.Run(); err != nil {
    43  		logger.Fatal(err)
    44  	}
    45  	return nil
    46  }