mirror of
https://github.com/crazy-max/diun.git
synced 2025-01-27 17:19:05 +00:00
1115234010
Add simple CLI to interact with Diun through gRPC Create image and notif proto services Compile and validate protos through a dedicated Dockerfile and bake target Implement proto definitions Move server as `serve` command New commands `image` and `notif` Refactor command line usage doc Better CLI error handling Tools build constraint to manage tools deps through go modules Add upgrade notes Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
34 lines
812 B
Go
34 lines
812 B
Go
package main
|
|
|
|
import (
|
|
"github.com/crazy-max/diun/v4/pb"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// CliHandler is a cli interface
|
|
type CliHandler interface {
|
|
BeforeApply() error
|
|
}
|
|
|
|
// CliGlobals holds globals cli attributes
|
|
type CliGlobals struct {
|
|
CliHandler `kong:"-"`
|
|
|
|
conn *grpc.ClientConn `kong:"-"`
|
|
imageSvc pb.ImageServiceClient `kong:"-"`
|
|
notifSvc pb.NotifServiceClient `kong:"-"`
|
|
|
|
GRPCAuthority string `kong:"name='grpc-authority',default='127.0.0.1:42286',help='Link to Diun gRPC API.'"`
|
|
}
|
|
|
|
// BeforeApply is a hook that run cli cmd are executed.
|
|
func (s *CliGlobals) BeforeApply() (err error) {
|
|
s.conn, err = grpc.Dial(s.GRPCAuthority, grpc.WithInsecure())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
s.imageSvc = pb.NewImageServiceClient(s.conn)
|
|
s.notifSvc = pb.NewNotifServiceClient(s.conn)
|
|
return
|
|
}
|