You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
package main |
|
|
|
import ( |
|
"fmt" |
|
"sig-pub/internal/sig" |
|
"sig-pub/pkg/config" |
|
"sig-pub/pkg/grpc/discovery" |
|
"sig-pub/pkg/grpc/generic" |
|
"sig-pub/pkg/utils/exit" |
|
|
|
"github.com/hashicorp/consul/api" |
|
"google.golang.org/grpc" |
|
"google.golang.org/grpc/credentials/insecure" |
|
) |
|
|
|
func main() { |
|
defer exit.Await() |
|
// load config |
|
conf := config.MustLoadConfig(new(config.Configuration), "config/config.toml") |
|
|
|
// consul 配置 |
|
cc := api.DefaultConfig() |
|
cc.Address = conf.Consul.Address |
|
client, err := api.NewClient(cc) |
|
if err != nil { |
|
panic(fmt.Errorf("consul client error: %v", err)) |
|
} |
|
|
|
// consul service discovery |
|
dis := discovery.NewConsulDiscovery(client) |
|
resolver := dis.Resolver() |
|
gpcGenericClientFactory := generic.NewGpcGenericClientFactory( |
|
discovery.ConsulSchema, |
|
grpc.WithTransportCredentials(insecure.NewCredentials()), |
|
grpc.WithResolvers(resolver), |
|
) |
|
if err := gpcGenericClientFactory.Init(); err != nil { |
|
panic(err) |
|
} |
|
|
|
sigServer := sig.NewSigServer(gpcGenericClientFactory) |
|
if err := sigServer.Init(); err != nil { |
|
panic(err) |
|
} |
|
go func() { |
|
if err := sigServer.Run(":7001"); err != nil { |
|
panic(err) |
|
} |
|
}() |
|
}
|
|
|