gf/contrib/registry/file
2024-09-28 20:58:04 +08:00
..
file_discovery.go fix(contrib/registry/file/v2): fix the panic caused by channel closing after resolver closed (#3691) 2024-08-14 20:44:05 +08:00
file_registrar.go fix file registry that not works on windows (#2605) 2023-04-27 11:34:54 +08:00
file_service.go add package contrib/rpc/grpcx (#2169) 2023-03-08 14:12:51 +08:00
file_watcher.go fix(contrib/registry/file/v2): fix the panic caused by channel closing after resolver closed (#3691) 2024-08-14 20:44:05 +08:00
file_z_basic_test.go improve auto retrieving of ip addresses for service registering (#2593) 2023-04-23 21:58:17 +08:00
file_z_http_test.go fix issue #3292 (#3294) 2024-02-01 16:02:36 +08:00
file.go fix file registry that not works on windows (#2605) 2023-04-27 11:34:54 +08:00
go.mod build(go.mod): upgrade minimum required go version from 1.18 to 1.20 (#3688) 2024-09-28 20:58:04 +08:00
go.sum build(go.mod): upgrade minimum required go version from 1.18 to 1.20 (#3688) 2024-09-28 20:58:04 +08:00
README.MD feat: add metric feature support in goframe (#3138) 2024-03-24 21:18:30 +08:00

GoFrame File Registry

Use file as service registration and discovery management.

Installation

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

suggested using go.mod:

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

Example

Reference example

server

package main

import (
	"github.com/gogf/gf/contrib/registry/file/v2"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/net/gsvc"
	"github.com/gogf/gf/v2/os/gfile"
)

func main() {
	gsvc.SetRegistry(file.New(gfile.Temp("gsvc")))

	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/gogf/gf/contrib/registry/file/v2"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/gsvc"
	"github.com/gogf/gf/v2/os/gctx"
	"github.com/gogf/gf/v2/os/gfile"
)

func main() {
	gsvc.SetRegistry(file.New(gfile.Temp("gsvc")))

	client := g.Client()
	for i := 0; i < 100; i++ {
		res, err := client.Get(gctx.New(), `http://hello.svc/`)
		if err != nil {
			panic(err)
		}
		fmt.Println(res.ReadAllString())
		res.Close()
		time.Sleep(time.Second)
	}
}