mirror of
https://github.com/hamburghammer/grcon.git
synced 2024-05-09 21:05:26 +02:00
Augusto Dwenger J.
1cda9ca591
Initially it was the idea that this would be version 2 of the https://github.com/hamburghammer/rcon lib but I changed my mind and decided to make a new Project out of it. It has formally nothing to do with the original lib.
101 lines
2.3 KiB
Go
101 lines
2.3 KiB
Go
package client_test
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
|
|
"github.com/hamburghammer/grcon"
|
|
"github.com/hamburghammer/grcon/client"
|
|
"github.com/hamburghammer/grcon/util"
|
|
)
|
|
|
|
func ExampleNewSimpleClient() {
|
|
conn, err := net.Dial("tcp", "127.0.0.1:12345")
|
|
if err != nil {
|
|
log.Fatalf("connection failed: %s", err.Error())
|
|
}
|
|
defer conn.Close()
|
|
|
|
remoteConsole := grcon.NewRemoteConsole(conn)
|
|
|
|
// the returned SimpleClient can now be used.
|
|
// It will use the utility function to generate ids
|
|
_ = client.NewSimpleClient(remoteConsole, util.GenerateRequestId)
|
|
}
|
|
|
|
func ExampleSimpleClient() {
|
|
conn, err := net.Dial("tcp", "127.0.0.1:12345")
|
|
if err != nil {
|
|
log.Fatalf("connection failed: %s", err.Error())
|
|
}
|
|
defer conn.Close()
|
|
|
|
remoteConsole := grcon.NewRemoteConsole(conn)
|
|
|
|
simpleClient := client.SimpleClient{
|
|
RemoteConsole: remoteConsole,
|
|
// Use the utility function to generate ids
|
|
IdGenFunc: util.GenerateRequestId,
|
|
}
|
|
|
|
err = simpleClient.Auth("password")
|
|
if err != nil {
|
|
log.Fatalf("authentication failed: %s", err.Error())
|
|
}
|
|
|
|
result, err := simpleClient.Exec("players")
|
|
if err != nil {
|
|
log.Fatalf("failed to retrive active players: %s", err.Error())
|
|
}
|
|
|
|
log.Println(string(result))
|
|
}
|
|
|
|
func ExampleSimpleClient_Auth() {
|
|
conn, err := net.Dial("tcp", "127.0.0.1:12345")
|
|
if err != nil {
|
|
log.Fatalf("connection failed: %s", err.Error())
|
|
}
|
|
defer conn.Close()
|
|
|
|
remoteConsole := grcon.NewRemoteConsole(conn)
|
|
|
|
simpleClient := client.SimpleClient{
|
|
RemoteConsole: remoteConsole,
|
|
IdGenFunc: util.GenerateRequestId,
|
|
}
|
|
|
|
err = simpleClient.Auth("password")
|
|
if err != nil {
|
|
log.Fatalf("authentication failed: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func ExampleSimpleClient_Exec() {
|
|
conn, err := net.Dial("tcp", "127.0.0.1:12345")
|
|
if err != nil {
|
|
log.Fatalf("connection failed: %s", err.Error())
|
|
}
|
|
defer conn.Close()
|
|
|
|
remoteConsole := grcon.NewRemoteConsole(conn)
|
|
|
|
simpleClient := client.SimpleClient{
|
|
RemoteConsole: remoteConsole,
|
|
IdGenFunc: util.GenerateRequestId,
|
|
}
|
|
|
|
// before you execute something you might want to authenticated the connection.
|
|
err = simpleClient.Auth("password")
|
|
if err != nil {
|
|
log.Fatalf("authentication failed: %s", err.Error())
|
|
}
|
|
|
|
result, err := simpleClient.Exec("players")
|
|
if err != nil {
|
|
log.Fatalf("failed to retrive active players: %s", err.Error())
|
|
}
|
|
|
|
log.Println(string(result))
|
|
}
|