An open API service indexing awesome lists of open source software.

https://github.com/natata/cmds

A simple command service implement with grpc
https://github.com/natata/cmds

commander go golang grpc

Last synced: 2 months ago
JSON representation

A simple command service implement with grpc

Awesome Lists containing this project

README

          

# cmds
A simple command service implement with grpc.

# How to use
## Server side
### Register actions for codes
```
set := cmds.Set{
1: func(s string) error {
if s == "btc" {
fmt.Println("mining")
return nil
}
return fmt.Errorf("wrong")
},
2: func(s string) error {
fmt.Println(s)
return nil
},
}
s := cmds.InitCMDS(set)
```

### Run the server
```
addr := ":8080"
s.Run(addr)
```

### Run the server with TLS
```
credOpt, _ := cmds.CreateCred(*certFile, *keyFile)
addr := ":8080"
s.Run(addr, credOpt)
```

## Client side

### create client
```
cli, _ := client.InitClient(addr)
```

### create client with TLS
```
cred, _ := client.CreateCred(*certFile, *serverName)
cli, _ := client.InitClient(addr, cred)
```

### send the code and param
```
err = cli.Send(1, "btc")
if err != nil {
panic(err)
}
fmt.Println("success")

err = cli.Send(1, "eth")
fmt.Println(err)
```