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
- Host: GitHub
- URL: https://github.com/natata/cmds
- Owner: Natata
- License: mit
- Created: 2018-06-01T16:58:58.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-01T18:38:38.000Z (about 8 years ago)
- Last Synced: 2025-05-23T00:31:54.150Z (about 1 year ago)
- Topics: commander, go, golang, grpc
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)
```