github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/template/fnc/main.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/micro/go-micro/examples/template/fnc/handler"
     5  	"github.com/micro/go-micro/examples/template/fnc/subscriber"
     6  	"github.com/micro/go-micro/v2"
     7  	"github.com/micro/go-micro/v2/util/log"
     8  )
     9  
    10  func main() {
    11  	// New Service
    12  	function := micro.NewFunction(
    13  		micro.Name("go.micro.fnc.template"),
    14  		micro.Version("latest"),
    15  	)
    16  
    17  	// Register Handler
    18  	function.Handle(new(handler.Example))
    19  
    20  	// Register Struct as Subscriber
    21  	function.Subscribe("go.micro.fnc.template", new(subscriber.Example))
    22  
    23  	// Initialise function
    24  	function.Init()
    25  
    26  	// Run service
    27  	if err := function.Run(); err != nil {
    28  		log.Fatal(err)
    29  	}
    30  }