Skip to content

Commit

Permalink
Add Close method
Browse files Browse the repository at this point in the history
  • Loading branch information
invliD committed Feb 18, 2024
1 parent 9ac3f62 commit b29a82c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

func main() {
client := palworldrcon.NewClient("127.0.0.1:25575", "password")
defer client.Close()

info, err := client.Info()
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions rcon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ func NewClient(address string, password string) *Client {
return client
}

// Close closes the connection to the RCON server. Calling any other method after closing will reopen the connection.
func (r *Client) Close() error {
if r.conn == nil {
return nil
} else {
err := r.conn.Close()
r.conn = nil
return err
}
}

func (r *Client) connect() error {
if r.conn != nil {
r.conn.Close()
Expand Down

0 comments on commit b29a82c

Please sign in to comment.