WIP: implemented Ping, implemented Set and Shutdown in agent, and added umask
This commit is contained in:
@@ -19,6 +19,7 @@ limitations under the License.
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"net"
|
||||
|
||||
pb "gitea.suyono.dev/suyono/go-agent/proto"
|
||||
@@ -51,6 +52,10 @@ func NewCacheConn(socketPath string) (CacheConn, error) {
|
||||
}
|
||||
|
||||
result.client = pb.NewAgentClient(result.conn)
|
||||
if _, err = result.client.Ping(context.Background(), new(emptypb.Empty)); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -71,4 +76,26 @@ func (c CacheConn) Get(ctx context.Context, key string) (string, error) {
|
||||
return rpcResult.Value, nil
|
||||
}
|
||||
|
||||
//TODO: implement Set and Shutdown
|
||||
func (c CacheConn) Set(ctx context.Context, key string, value string) error {
|
||||
rpcStatus, err := c.client.Set(ctx, &pb.CacheSetRequest{Key: key, Value: value})
|
||||
if err != nil {
|
||||
return fmt.Errorf("set to cache: %w", err)
|
||||
}
|
||||
|
||||
if rpcStatus.Status != "OK" {
|
||||
return fmt.Errorf("set to cache: status %s with message %s", rpcStatus.Status, rpcStatus.Message)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c CacheConn) Shutdown(ctx context.Context) error {
|
||||
_, err := c.client.Shutdown(ctx, new(emptypb.Empty))
|
||||
if err != nil {
|
||||
return fmt.Errorf("shutdown: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c CacheConn) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user