Skip to content

Commit

Permalink
Merge pull request #83 from k1LoW/bufresolv
Browse files Browse the repository at this point in the history
Use bufresolv
  • Loading branch information
k1LoW authored May 4, 2024
2 parents dd2d0b0 + 4632e42 commit 664d6a4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I

================================================================

github.com/k1LoW/bsrr
https://github.com/k1LoW/bsrr
github.com/k1LoW/bufresolv
https://github.com/k1LoW/bufresolv
----------------------------------------------------------------
The MIT License (MIT)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/jaswdr/faker v1.19.1
github.com/jhump/protoreflect/v2 v2.0.0-20230705224148-00680b949112
github.com/k1LoW/bsrr v0.4.0
github.com/k1LoW/bufresolv v0.6.1
github.com/minio/pkg v1.7.5
github.com/tenntenn/golden v0.5.4
google.golang.org/grpc v1.63.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/josharian/mapfs v0.0.0-20210615234106-095c008854e6 h1:c+ctPFdISggaSNC
github.com/josharian/mapfs v0.0.0-20210615234106-095c008854e6/go.mod h1:Rv/momJI8DgrWnBZip+SgagpcgORIZQE5SERlxNb8LY=
github.com/josharian/txtarfs v0.0.0-20210615234325-77aca6df5bca h1:a8xeK4GsWLE4LYo5VI4u1Cn7ZvT1NtXouXR3DdKLB8Q=
github.com/josharian/txtarfs v0.0.0-20210615234325-77aca6df5bca/go.mod h1:UbC32ft9G/jG+sZI8wLbIBNIrYr7vp/yqMDa9SxVBNA=
github.com/k1LoW/bsrr v0.4.0 h1:5Lj4l/sY8kaVLmSDm6qi0l+mKyW0lyOHuQPnRYZnpG4=
github.com/k1LoW/bsrr v0.4.0/go.mod h1:WhYbouAlFjKDaGIe2wtt9ZcRUYy2ilrI9NGIilMLTIY=
github.com/k1LoW/bufresolv v0.6.1 h1:IQU3cNsa00pWXLqUzU5PD1vdGQdzq3W/gaO18KCevAs=
github.com/k1LoW/bufresolv v0.6.1/go.mod h1:56aalZU3G/tpBtQKS4pOCv2zMTucX3PrJkasURwFVxg=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/minio/pkg v1.7.5 h1:UOUJjewE5zoaDPlCMJtNx/swc1jT1ZR+IajT7hrLd44=
Expand Down
16 changes: 10 additions & 6 deletions grpcstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/bufbuild/protocompile"
"github.com/bufbuild/protocompile/linker"
"github.com/k1LoW/bsrr"
"github.com/k1LoW/bufresolv"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -932,15 +932,18 @@ func (s *Server) resolveProtos(ctx context.Context, c *config) error {
if err != nil {
return err
}
var bsrrOpts []bsrr.Option
var bufresolvOpts []bufresolv.Option
if c.bufDir != "" {
bufresolvOpts = append(bufresolvOpts, bufresolv.BufDir(c.bufDir))
}
if c.bufConfig != "" {
bsrrOpts = append(bsrrOpts, bsrr.BufConfig(c.bufConfig))
bufresolvOpts = append(bufresolvOpts, bufresolv.BufConfig(c.bufConfig))
}
if c.bufLock != "" {
bsrrOpts = append(bsrrOpts, bsrr.BufLock(c.bufLock))
bufresolvOpts = append(bufresolvOpts, bufresolv.BufLock(c.bufLock))
}
bsrrOpts = append(bsrrOpts, bsrr.BufModule(c.bufModules...))
br, err := bsrr.New(bsrrOpts...)
bufresolvOpts = append(bufresolvOpts, bufresolv.BufModule(c.bufModules...))
br, err := bufresolv.New(bufresolvOpts...)
if err != nil {
return err
}
Expand All @@ -952,6 +955,7 @@ func (s *Server) resolveProtos(ctx context.Context, c *config) error {
br,
})),
}
protos = unique(append(protos, br.Paths()...))
fds, err := comp.Compile(ctx, protos...)
if err != nil {
return err
Expand Down
26 changes: 24 additions & 2 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type config struct {
cacert, cert, key []byte
healthCheck bool
disableReflection bool
bufDir string
bufLock string
bufConfig string
bufModules []string
Expand Down Expand Up @@ -114,6 +115,14 @@ func DisableReflection() Option {
}
}

// BufDir use buf directory.
func BufDir(dir string) Option {
return func(c *config) error {
c.bufDir = dir
return nil
}
}

// BufLock use buf.lock for BSR.
func BufLock(lock string) Option {
return func(c *config) error {
Expand All @@ -131,9 +140,22 @@ func BufConfig(p string) Option {
}

// BufModule use buf modules for BSR.
func BufModule(modules ...string) Option {
func BufModule(module string) Option {
return func(c *config) error {
c.bufModules = unique(append(c.bufModules, module))
return nil
}
}

// BufModules use buf modules for BSR.
func BufModules(modules []string) Option {
return func(c *config) error {
c.bufModules = unique(append(c.bufModules, modules...))
for _, m := range modules {
opt := BufModule(m)
if err := opt(c); err != nil {
return err
}
}
return nil
}
}
Expand Down

0 comments on commit 664d6a4

Please sign in to comment.