gf/contrib/registry/polaris
2022-11-01 20:12:21 +08:00
..
go.mod feat: improve glog for polaris register (#2178) 2022-10-09 09:10:02 +08:00
go.sum feat: improve glog for polaris register (#2178) 2022-10-09 09:10:02 +08:00
polaris_discovery.go add golangci feature to guarantee codes quality (#2229) 2022-11-01 20:12:21 +08:00
polaris_registrar.go add golangci feature to guarantee codes quality (#2229) 2022-11-01 20:12:21 +08:00
polaris_service.go Feature/gsvc interface (#1871) 2022-05-23 15:08:11 +08:00
polaris_watcher.go add golangci feature to guarantee codes quality (#2229) 2022-11-01 20:12:21 +08:00
polaris_z_test.go add golangci feature to guarantee codes quality (#2229) 2022-11-01 20:12:21 +08:00
polaris.go add golangci feature to guarantee codes quality (#2229) 2022-11-01 20:12:21 +08:00
README_ZH.MD feat: improve glog for polaris register (#2178) 2022-10-09 09:10:02 +08:00
README.MD feat: improve glog for polaris register (#2178) 2022-10-09 09:10:02 +08:00

GoFrame Polaris Registry

English | 简体中文

Use PolarisMesh as service registration, discovery management and heartbeat reporting.

Installation

go get -u -v github.com/gogf/gf/contrib/registry/polaris/v2

suggested using go.mod:

require github.com/gogf/gf/contrib/registry/polaris/v2 latest

Example

Reference example

server

package main

import (
    "github.com/polarismesh/polaris-go/pkg/config"
    
    "github.com/gogf/gf/contrib/registry/polaris/v2"
    "github.com/gogf/gf/v2/frame/g"
    "github.com/gogf/gf/v2/net/ghttp"
    "github.com/gogf/gf/v2/net/gsvc"
)

func main() {
    conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"})
    
    // TTL egt 2*time.Second
    gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100)))
    
    s := g.Server(`hello.svc`)
    s.BindHandler("/", func(r *ghttp.Request) {
        g.Log().Info(r.Context(), `request received`)
        r.Response.Write(`Hello world`)
    })
    s.Run()
}

client

package main

import (
    "fmt"
    "time"
    
    "github.com/polarismesh/polaris-go/pkg/config"
    
    "github.com/gogf/gf/contrib/registry/polaris/v2"
    
    "github.com/gogf/gf/v2/frame/g"
    "github.com/gogf/gf/v2/net/gsvc"
    "github.com/gogf/gf/v2/os/gctx"
)

func main() {
    conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"})
    
    gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100)))
    
    for i := 0; i < 100; i++ {
        res, err := g.Client().Get(gctx.New(), `http://hello.svc/`)
        if err != nil {
            panic(err)
        }
        fmt.Println(res.ReadAllString())
        res.Close()
        time.Sleep(time.Second)
    }
}

License

GoFrame Polaris is licensed under the MIT License, 100% free and open-source, forever.