本文整理汇总了Golang中github.com/disorganizer/brig/daemon/wire.Command类的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:disorganizer,项目名称:brig,代码行数:32,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:28,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:30,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:35,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:8,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:9,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:10,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:11,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:11,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:14,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:14,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:14,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:15,代码来源:serverops.go
示例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
}
开发者ID:disorganizer,项目名称:brig,代码行数:16,代码来源:serverops.go
示例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)
}
开发者ID:disorganizer,项目名称:brig,代码行数:17,代码来源:serverops.go
示例16: handleMkdir
func handleMkdir(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
mkdirCmd := cmd.GetMkdirCommand()
path := mkdirCmd.Path
var err error
if mkdirCmd.CreateParents {
_, err = d.Repo.OwnStore.MkdirAll(path)
} else {
_, err = d.Repo.OwnStore.Mkdir(path)
}
if err != nil {
return nil, err
}
return nil, nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:17,代码来源:serverops.go
示例17: handleHistory
func handleHistory(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
repoPath := cmd.GetHistoryCommand().RepoPath
history, err := d.Repo.OwnStore.History(repoPath)
if err != nil {
return nil, err
}
histProto, err := history.ToProto()
if err != nil {
return nil, err
}
return &wire.Response{
HistoryResp: &wire.Response_HistoryResp{
History: histProto,
},
}, nil
}
开发者ID:disorganizer,项目名称:brig,代码行数:19,代码来源:serverops.go
注:本文中的github.com/disorganizer/brig/daemon/wire.Command类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论