本文整理汇总了Golang中github.com/disorganizer/brig/daemon/wire.Command类的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleSync
func handleSync(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
syncCmd := cmd.GetSyncCommand()
who, err := id.Cast(syncCmd.Who)
if err != nil {
return nil, fmt.Errorf("Bad id `%s`: %v", syncCmd.Who, err)
}
if !d.MetaHost.IsInOnlineMode() {
return nil, fmt.Errorf("Metadata Host is not online.")
}
client, err := d.MetaHost.DialID(who)
if err != nil {
return nil, err
}
// This might create a new, empty store if it does not exist yet:
remoteStore, err := d.Repo.Store(who)
if err != nil {
return nil, err
}
if err := client.Fetch(remoteStore); err != nil {
return nil, err
}
if err := d.Repo.OwnStore.SyncWith(remoteStore); err != nil {
return nil, err
}
return nil, nil
}
示例2: handleRemoteLocate
func handleRemoteLocate(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
locateCmd := cmd.GetRemoteLocateCommand()
idString, peerLimit := locateCmd.Id, int(locateCmd.PeerLimit)
timeout := time.Duration(locateCmd.TimeoutMs) * time.Millisecond
if timeout <= 0 {
timeout = 5 * time.Second
}
id, err := id.Cast(idString)
if err != nil {
return nil, err
}
peers, err := ipfsutil.Locate(d.Repo.IPFS, id.Hash(), peerLimit, timeout)
if err != nil {
return nil, err
}
resp := &wire.Response_RemoteLocateResp{}
for _, peer := range peers {
resp.Hashes = append(resp.Hashes, peer.ID)
}
return &wire.Response{
RemoteLocateResp: resp,
}, nil
}
示例3: handlePin
func handlePin(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
pinCmd := cmd.GetPinCommand()
var isPinned bool
switch balance := pinCmd.Balance; {
case balance < 0:
if err := d.Repo.OwnStore.Unpin(pinCmd.Path); err != nil {
return nil, err
}
isPinned = false
case balance > 0:
if err := d.Repo.OwnStore.Pin(pinCmd.Path); err != nil {
return nil, err
}
isPinned = true
case balance == 0:
var err error
if isPinned, err = d.Repo.OwnStore.IsPinned(pinCmd.Path); err != nil {
return nil, err
}
}
return &wire.Response{
PinResp: &wire.Response_PinResp{
IsPinned: isPinned,
},
}, nil
}
示例4: handleExport
func handleExport(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
who := cmd.GetExportCommand().Who
// Figure out the correct store:
var st *store.Store
if who == "" {
st = d.Repo.OwnStore
} else {
whoID, err := id.Cast(who)
if err != nil {
return nil, err
}
st, err = d.Repo.Store(whoID)
if err != nil {
return nil, err
}
}
pbStore, err := st.Export()
if err != nil {
return nil, err
}
data, err := proto.Marshal(pbStore)
if err != nil {
return nil, err
}
return &wire.Response{
ExportResp: &wire.Response_ExportResp{
Data: data,
},
}, nil
}
示例5: handleMv
func handleMv(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
mvCmd := cmd.GetMvCommand()
if err := d.Repo.OwnStore.Move(mvCmd.Source, mvCmd.Dest, true); err != nil {
return nil, err
}
return nil, nil
}
示例6: handleCommit
func handleCommit(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
message := cmd.GetCommitCommand().Message
if err := d.Repo.OwnStore.MakeCommit(message); err != nil {
return nil, err
}
return nil, nil
}
示例7: handleUnmount
func handleUnmount(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
mountPath := cmd.GetUnmountCommand().MountPoint
if err := d.Mounts.Unmount(mountPath); err != nil {
log.Errorf("Unable to unmount `%v`: %v", mountPath, err)
return nil, err
}
return nil, nil
}
示例8: handleRm
func handleRm(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
rmCmd := cmd.GetRmCommand()
repoPath := rmCmd.RepoPath
recursive := rmCmd.Recursive
if err := d.Repo.OwnStore.Remove(repoPath, recursive); err != nil {
return nil, err
}
return nil, nil
}
示例9: handleStage
func handleStage(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
filePath := cmd.GetAddCommand().FilePath
repoPath := cmd.GetAddCommand().RepoPath
err := d.Repo.OwnStore.Stage(filePath, repoPath)
if err != nil {
return nil, err
}
return nil, nil
}
示例10: handleRemoteRemove
func handleRemoteRemove(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
idString := cmd.GetRemoteRemoveCommand().Id
id, err := id.Cast(idString)
if err != nil {
return nil, err
}
if err := d.Repo.Remotes.Remove(id); err != nil {
return nil, err
}
return nil, nil
}
示例11: handleCat
func handleCat(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
filePath := cmd.GetCatCommand().FilePath
fd, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return nil, err
}
srcPath := cmd.GetCatCommand().RepoPath
if err := d.Repo.OwnStore.Cat(srcPath, fd); err != nil {
return nil, err
}
return nil, nil
}
示例12: handleImport
func handleImport(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
pbData := cmd.GetImportCommand().Data
pbStore := storewire.Store{}
if err := proto.Unmarshal(pbData, &pbStore); err != nil {
return nil, err
}
if err := d.Repo.OwnStore.Import(&pbStore); err != nil {
return nil, err
}
return nil, nil
}
示例13: handleList
func handleList(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
listCmd := cmd.GetListCommand()
root, depth := listCmd.Root, listCmd.Depth
entries, err := d.Repo.OwnStore.ListProtoNodes(root, int(depth))
if err != nil {
return nil, err
}
return &wire.Response{
ListResp: &wire.Response_ListResp{
Entries: entries,
},
}, nil
}
示例14: handleRemoteAdd
func handleRemoteAdd(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
remoteAddCmd := cmd.GetRemoteAddCommand()
idString, peerHash := remoteAddCmd.Id, remoteAddCmd.Hash
id, err := id.Cast(idString)
if err != nil {
return nil, err
}
remote := repo.NewRemote(id, peerHash)
if err := d.Repo.Remotes.Insert(remote); err != nil {
return nil, err
}
return nil, nil
}
示例15: handleOnlineStatus
func handleOnlineStatus(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
qry := cmd.GetOnlineStatusCommand().Query
switch qry {
case wire.OnlineQuery_IS_ONLINE:
return &wire.Response{
OnlineStatusResp: &wire.Response_OnlineStatusResp{
IsOnline: d.IsOnline(),
},
}, nil
case wire.OnlineQuery_GO_ONLINE:
return nil, d.Connect()
case wire.OnlineQuery_GO_OFFLINE:
return nil, d.Disconnect()
}
return nil, fmt.Errorf("handleOnlineStatus: Bad query received: %v", qry)
}