Skip to content
/ cmds Public

A simple command service implement with grpc

License

Notifications You must be signed in to change notification settings

Natata/cmds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

A simple command service implement with grpc

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published