🧑‍💻 Add the server side Hyper SDK

This commit is contained in:
2024-06-22 12:14:15 +08:00
parent d9aa478d10
commit c37a55b88b
6 changed files with 171 additions and 24 deletions

View File

@ -2,18 +2,17 @@ package gap
import (
"fmt"
"strconv"
"strings"
"github.com/hashicorp/consul/api"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"strconv"
"strings"
_ "github.com/mbobakov/grpc-consul-resolver"
)
var C *api.Client
func Register() error {
cfg := api.DefaultConfig()
cfg.Address = viper.GetString("consul.addr")
@ -41,17 +40,13 @@ func Register() error {
DeregisterCriticalServiceAfter: "3m",
}
if err := client.Agent().ServiceRegister(registration); err != nil {
return err
} else {
C = client
return nil
}
return client.Agent().ServiceRegister(registration)
}
func DiscoverPaperclip() (*grpc.ClientConn, error) {
target := fmt.Sprintf("consul://%s/Hydrogen.Paperclip", viper.GetString("consul.addr"))
return grpc.NewClient(
"consul://127.0.0.1:8500/Hydrogen.Paperclip",
target,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy": "round_robin"}`),
)