Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
8bc98510eb | |||
ed0f35133d | |||
c36b9e002f |
@ -1,3 +1,5 @@
|
||||
package service
|
||||
|
||||
//go:generate protoc -I./proto -I. --go_out=paths=source_relative:./proto --go-micro_out=components=micro|grpc,standalone=true,debug=true,paths=source_relative:./micro proto/service.proto
|
||||
//go:generate protoc -I./proto -I. --go_out=paths=source_relative:./proto proto/service.proto
|
||||
//go:generate protoc -I./proto -I. --go-micro_out=components=micro,standalone=false,debug=true,paths=source_relative:./proto proto/service.proto
|
||||
//go:generate protoc -I./proto -I. --go-micro_out=components=grpc,standalone=true,debug=true,paths=source_relative:./micro proto/service.proto
|
||||
|
12
go.mod
12
go.mod
@ -3,8 +3,12 @@ module go.unistack.org/micro-config-service/v4
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/imdario/mergo v0.3.13
|
||||
go.unistack.org/micro/v4 v4.0.1
|
||||
google.golang.org/grpc v1.52.3
|
||||
google.golang.org/protobuf v1.28.1
|
||||
dario.cat/mergo v1.0.0
|
||||
go.unistack.org/micro/v4 v4.0.17
|
||||
google.golang.org/protobuf v1.33.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
)
|
||||
|
37
go.sum
37
go.sum
@ -1,32 +1,13 @@
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
||||
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||
go.unistack.org/micro-server-http/v3 v3.10.13 h1:rt50Hos9hSuyvyYEmw0p5L2eq7HDDz2GpAOUO6M0QC8=
|
||||
go.unistack.org/micro-server-http/v3 v3.10.13/go.mod h1:phNG9aosjbneXvZxEVaVQI+NHLLZ3eA82mOH6gGSShY=
|
||||
go.unistack.org/micro/v3 v3.10.16 h1:2er/SKKYbV60M+UuJM4eYCF0MZYAIq/yNUrAbTfgq8Q=
|
||||
go.unistack.org/micro/v3 v3.10.16/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q=
|
||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 h1:a2S6M0+660BgMNl++4JPlcAO/CjkqYItDEZwkoDQK7c=
|
||||
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg=
|
||||
google.golang.org/grpc v1.52.3 h1:pf7sOysg4LdgBqduXveGKrcEwbStiK2rtfghdzlUYDQ=
|
||||
google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
go.unistack.org/micro/v4 v4.0.17 h1:mF7uM+J4ILdG+1fcwzKYCwDlxhdbF/e1WnGzKKLnIXc=
|
||||
go.unistack.org/micro/v4 v4.0.17/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@ -1,31 +0,0 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-micro v4.0.0
|
||||
// - protoc v3.21.12
|
||||
// source: service.proto
|
||||
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
proto "go.unistack.org/micro-config-service/v4/proto"
|
||||
v4 "go.unistack.org/micro-server-http/v4"
|
||||
client "go.unistack.org/micro/v4/client"
|
||||
)
|
||||
|
||||
var (
|
||||
ConfigServiceName = "ConfigService"
|
||||
)
|
||||
var (
|
||||
ConfigServiceServerEndpoints = []v4.EndpointMetadata{}
|
||||
)
|
||||
|
||||
type ConfigServiceClient interface {
|
||||
Load(ctx context.Context, req *proto.LoadRequest, opts ...client.CallOption) (*proto.LoadResponse, error)
|
||||
Save(ctx context.Context, req *proto.SaveRequest, opts ...client.CallOption) (*proto.SaveResponse, error)
|
||||
}
|
||||
|
||||
type ConfigServiceServer interface {
|
||||
Load(ctx context.Context, req *proto.LoadRequest, rsp *proto.LoadResponse) error
|
||||
Save(ctx context.Context, req *proto.SaveRequest, rsp *proto.SaveResponse) error
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v4.0.0
|
||||
// protoc-gen-go-micro version: v4.0.2
|
||||
// source: service.proto
|
||||
|
||||
package servicepb
|
||||
@ -8,6 +8,7 @@ import (
|
||||
context "context"
|
||||
proto "go.unistack.org/micro-config-service/v4/proto"
|
||||
client "go.unistack.org/micro/v4/client"
|
||||
options "go.unistack.org/micro/v4/options"
|
||||
server "go.unistack.org/micro/v4/server"
|
||||
)
|
||||
|
||||
@ -16,11 +17,11 @@ type configServiceClient struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func NewConfigServiceClient(name string, c client.Client) ConfigServiceClient {
|
||||
func NewConfigServiceClient(name string, c client.Client) proto.ConfigServiceClient {
|
||||
return &configServiceClient{c: c, name: name}
|
||||
}
|
||||
|
||||
func (c *configServiceClient) Load(ctx context.Context, req *proto.LoadRequest, opts ...client.CallOption) (*proto.LoadResponse, error) {
|
||||
func (c *configServiceClient) Load(ctx context.Context, req *proto.LoadRequest, opts ...options.Option) (*proto.LoadResponse, error) {
|
||||
rsp := &proto.LoadResponse{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "ConfigService.Load", req), rsp, opts...)
|
||||
if err != nil {
|
||||
@ -29,7 +30,7 @@ func (c *configServiceClient) Load(ctx context.Context, req *proto.LoadRequest,
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
func (c *configServiceClient) Save(ctx context.Context, req *proto.SaveRequest, opts ...client.CallOption) (*proto.SaveResponse, error) {
|
||||
func (c *configServiceClient) Save(ctx context.Context, req *proto.SaveRequest, opts ...options.Option) (*proto.SaveResponse, error) {
|
||||
rsp := &proto.SaveResponse{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "ConfigService.Save", req), rsp, opts...)
|
||||
if err != nil {
|
||||
@ -39,7 +40,7 @@ func (c *configServiceClient) Save(ctx context.Context, req *proto.SaveRequest,
|
||||
}
|
||||
|
||||
type configServiceServer struct {
|
||||
ConfigServiceServer
|
||||
proto.ConfigServiceServer
|
||||
}
|
||||
|
||||
func (h *configServiceServer) Load(ctx context.Context, req *proto.LoadRequest, rsp *proto.LoadResponse) error {
|
||||
@ -50,7 +51,7 @@ func (h *configServiceServer) Save(ctx context.Context, req *proto.SaveRequest,
|
||||
return h.ConfigServiceServer.Save(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func RegisterConfigServiceServer(s server.Server, sh ConfigServiceServer, opts ...server.HandlerOption) error {
|
||||
func RegisterConfigServiceServer(s server.Server, sh proto.ConfigServiceServer, opts ...options.Option) error {
|
||||
type configService interface {
|
||||
Load(ctx context.Context, req *proto.LoadRequest, rsp *proto.LoadResponse) error
|
||||
Save(ctx context.Context, req *proto.SaveRequest, rsp *proto.SaveResponse) error
|
||||
@ -59,6 +60,6 @@ func RegisterConfigServiceServer(s server.Server, sh ConfigServiceServer, opts .
|
||||
configService
|
||||
}
|
||||
h := &configServiceServer{sh}
|
||||
var nopts []server.HandlerOption
|
||||
return s.Handle(s.NewHandler(&ConfigService{h}, append(nopts, opts...)...))
|
||||
var nopts []options.Option
|
||||
return s.Handle(&ConfigService{h}, append(nopts, opts...)...)
|
||||
}
|
||||
|
10
options.go
10
options.go
@ -2,19 +2,19 @@ package service
|
||||
|
||||
import (
|
||||
"go.unistack.org/micro/v4/client"
|
||||
"go.unistack.org/micro/v4/config"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
)
|
||||
|
||||
type clientKey struct{}
|
||||
|
||||
// Client to call config service
|
||||
func Client(c client.Client) config.Option {
|
||||
return config.SetOption(clientKey{}, c)
|
||||
func Client(c client.Client) options.Option {
|
||||
return options.ContextOption(clientKey{}, c)
|
||||
}
|
||||
|
||||
type serviceKey struct{}
|
||||
|
||||
// Service to which data load
|
||||
func Service(s string) config.Option {
|
||||
return config.SetOption(serviceKey{}, s)
|
||||
func Service(s string) options.Option {
|
||||
return options.ContextOption(serviceKey{}, s)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.21.12
|
||||
// protoc v4.23.4
|
||||
// source: service.proto
|
||||
|
||||
package servicepb
|
||||
|
27
proto/service_micro.pb.go
Normal file
27
proto/service_micro.pb.go
Normal file
@ -0,0 +1,27 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-micro v4.0.2
|
||||
// - protoc v4.23.4
|
||||
// source: service.proto
|
||||
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
_ "go.unistack.org/micro/v4/client"
|
||||
options "go.unistack.org/micro/v4/options"
|
||||
)
|
||||
|
||||
var (
|
||||
ConfigServiceName = "ConfigService"
|
||||
)
|
||||
|
||||
type ConfigServiceClient interface {
|
||||
Load(ctx context.Context, req *LoadRequest, opts ...options.Option) (*LoadResponse, error)
|
||||
Save(ctx context.Context, req *SaveRequest, opts ...options.Option) (*SaveResponse, error)
|
||||
}
|
||||
|
||||
type ConfigServiceServer interface {
|
||||
Load(ctx context.Context, req *LoadRequest, rsp *LoadResponse) error
|
||||
Save(ctx context.Context, req *SaveRequest, rsp *SaveResponse) error
|
||||
}
|
17
service.go
17
service.go
@ -4,11 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"dario.cat/mergo"
|
||||
pbmicro "go.unistack.org/micro-config-service/v4/micro"
|
||||
pb "go.unistack.org/micro-config-service/v4/proto"
|
||||
"go.unistack.org/micro/v4/client"
|
||||
"go.unistack.org/micro/v4/config"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||
)
|
||||
|
||||
@ -19,14 +20,14 @@ var DefaultStructTag = "service"
|
||||
type serviceConfig struct {
|
||||
opts config.Options
|
||||
service string
|
||||
client pbmicro.ConfigClient
|
||||
client pb.ConfigServiceClient
|
||||
}
|
||||
|
||||
func (c *serviceConfig) Options() config.Options {
|
||||
return c.opts
|
||||
}
|
||||
|
||||
func (c *serviceConfig) Init(opts ...config.Option) error {
|
||||
func (c *serviceConfig) Init(opts ...options.Option) error {
|
||||
if err := config.DefaultBeforeInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
@ -71,7 +72,7 @@ func (c *serviceConfig) Init(opts ...config.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
c.client = pbmicro.NewConfigClient(c.service, cli)
|
||||
c.client = pbmicro.NewConfigServiceClient(c.service, cli)
|
||||
|
||||
if err := config.DefaultAfterInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
@ -80,7 +81,7 @@ func (c *serviceConfig) Init(opts ...config.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *serviceConfig) Load(ctx context.Context, opts ...config.LoadOption) error {
|
||||
func (c *serviceConfig) Load(ctx context.Context, opts ...options.Option) error {
|
||||
if err := config.DefaultBeforeLoad(ctx, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
@ -131,7 +132,7 @@ func (c *serviceConfig) Load(ctx context.Context, opts ...config.LoadOption) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *serviceConfig) Save(ctx context.Context, opts ...config.SaveOption) error {
|
||||
func (c *serviceConfig) Save(ctx context.Context, opts ...options.Option) error {
|
||||
if err := config.DefaultBeforeSave(ctx, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
@ -166,11 +167,11 @@ func (c *serviceConfig) Name() string {
|
||||
return c.opts.Name
|
||||
}
|
||||
|
||||
func (c *serviceConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) {
|
||||
func (c *serviceConfig) Watch(ctx context.Context, opts ...options.Option) (config.Watcher, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func NewConfig(opts ...config.Option) *serviceConfig {
|
||||
func NewConfig(opts ...options.Option) *serviceConfig {
|
||||
options := config.NewOptions(opts...)
|
||||
if len(options.StructTag) == 0 {
|
||||
options.StructTag = DefaultStructTag
|
||||
|
Loading…
Reference in New Issue
Block a user