https://github.com/outout14/libknot
Go interface for managing the Knot DNS daemon
https://github.com/outout14/libknot
Last synced: 2 months ago
JSON representation
Go interface for managing the Knot DNS daemon
- Host: GitHub
- URL: https://github.com/outout14/libknot
- Owner: outout14
- License: gpl-3.0
- Created: 2021-09-12T01:46:42.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-09T00:06:59.000Z (over 4 years ago)
- Last Synced: 2024-06-21T02:18:52.992Z (almost 2 years ago)
- Language: Go
- Size: 48.8 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# LibKnot : Go interface for managing the Knot DNS daemon
LibKnot is a GoLang interface to manage the KnotDNS daemon using the C library ([libknot](https://github.com/CZ-NIC/knot/tree/master/tests/libknot)) based on the ([official Python interface](https://pypi.org/project/libknot/)].
Since the software loads the C library dynamically, you must install it on your development and production machine.
When publishing compiled software, pay attention to the version of libknot used.
## Usage
You can uses this library in two ways :
- Use wrapper functions, easier to use.
- Directly control the server with the functions ``Alloc()``, ``Connect()``, ``Close()``, ``Free()``, ``Send()``, ``Receive()`` and manage data types.
## Examples
- Basic example using wrapper functions :
```go
package main
import (
"fmt"
"github.com/outout14/libknot"
)
func main() {
ctl := libknot.KnotCtl{} //Define the connection
err := ctl.Init("/var/run/knot/knot.sock") // Allocate de control context + Connect(socket)
ctl.ErrCheck(err) //Panic if err != 0 and print the error as a human readble string
/* Send */
msg := libknot.KnotCtlData{
Command: "conf-read",
Section: "zone",
Item: "domain",
}
_ = ctl.SendBlock(msg) //Send DATA msg + BLOCK (BLOCK = End of message)
/* End Send */
/* Receive */
data, _ := ctl.ReceiveBlock() //Retrieves all DATA and EXTRA type messages
for _, s := range data {
fmt.Println(s.Data) //Print received data
}
/* End Receive*/
ctl.Terminate() //Send(END) + Close() + Free() control ctx
}
```