-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
771 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/linyows/dewy/registry" | ||
dewypb "github.com/linyows/dewy/registry/grpc/proto/gen/dewy" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
const ( | ||
Scheme = "grpc" | ||
) | ||
|
||
type Client struct { | ||
cl dewypb.RegistryServiceClient | ||
} | ||
|
||
var _ registry.Registry = (*Client)(nil) | ||
|
||
// New returns Client | ||
func New(cc grpc.ClientConnInterface) (*Client, error) { | ||
cl := dewypb.NewRegistryServiceClient(cc) | ||
return &Client{ | ||
cl: cl, | ||
}, nil | ||
} | ||
|
||
// Current returns current artifact. | ||
func (c *Client) Current(ctx context.Context, req *registry.CurrentRequest) (*registry.CurrentResponse, error) { | ||
var an *string | ||
if req.ArtifactName != "" { | ||
an = &req.ArtifactName | ||
} | ||
creq := &dewypb.CurrentRequest{ | ||
Arch: req.Arch, | ||
Os: req.OS, | ||
ArifactName: an, | ||
} | ||
cres, err := c.cl.Current(ctx, creq) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := ®istry.CurrentResponse{ | ||
ID: cres.Id, | ||
Tag: cres.Tag, | ||
ArtifactURL: cres.ArtifactUrl, | ||
} | ||
return res, nil | ||
} | ||
|
||
// Report report shipping. | ||
func (c *Client) Report(ctx context.Context, req *registry.ReportRequest) error { | ||
var perr *string | ||
if req.Err != nil { | ||
serr := req.Err.Error() | ||
perr = &serr | ||
} | ||
creq := &dewypb.ReportRequest{ | ||
Id: req.ID, | ||
Tag: req.Tag, | ||
Err: perr, | ||
} | ||
if _, err := c.cl.Report(ctx, creq); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.