rndc

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 21 Imported by: 0

README

rndc-go

bind9 服务使用的 rndc 协议的 go 版本客户端,仅支持协议版本1

Installation

go get github.com/ZXiangQAQ/rndc-go

Quickstart

import (
	"fmt"
	"github.com/ZXiangQAQ/rndc-go"
)

func main() {
	// 默认日志等级为 info
	rndc.SetLevelByString("error")

	// 创建 RnDC client
	client, err := rndc.NewRNDCClient("your bind9 server address", "algo", "secret")
	if err != nil {
            fmt.Printf("conn failed, err: %s\n", err.Error())
	}

	// 请求 RnDC 服务器, 并同步获取结果
	resp, err := client.Call("sync test123.com")
	if err != nil {
	    fmt.Printf("client call err: %s\n", err.Error())
	}

	// 获取 bind 返回的原生 response
	fmt.Printf("response: %s\n", resp)

	// 获取指令内容
	fmt.Printf("cmd: %s\n", resp.Data.Type)

	// 获取返回码, 类型是 string
	fmt.Printf("result: %s\n", resp.Data.Result)

	// 获取返回内容, 类型是 string
	fmt.Printf("text: %s\n", resp.Data.Text)

	// 获取错误, 类型是 string
	fmt.Printf("err: %s\n", resp.Data.Err)
}

Feature

  • 目前使用硬编码进行序列化和反序列化,计划基于 tag 标签和 rndc 的编码规范,实现动态 MarshalUnmarshal

Documentation

Index

Constants

View Source
const (
	ProtocolVersion = 1
)

Variables

This section is empty.

Functions

func Critical added in v0.0.2

func Critical(ctx context.Context, format string, v ...interface{})

func Debug added in v0.0.2

func Debug(ctx context.Context, format string, v ...interface{})

func Error added in v0.0.2

func Error(ctx context.Context, format string, v ...interface{})

func Info added in v0.0.2

func Info(ctx context.Context, format string, v ...interface{})

func SetLevelByString added in v0.0.2

func SetLevelByString(level string)

func SetOutput added in v0.0.2

func SetOutput(output io.Writer)

func Warn added in v0.0.2

func Warn(ctx context.Context, format string, v ...interface{})

Types

type AuthRequest

type AuthRequest struct {
	Hash []byte `json:"hsha,omitempty"`
	Md5  []byte `json:"md5,omitempty"`
}

func (*AuthRequest) Serialize

func (s *AuthRequest) Serialize() ([]byte, error)

type AuthResponse

type AuthResponse struct {
	Hash []byte `json:"hsha,omitempty"`
	Md5  []byte `json:"md5,omitempty"`
}

func (*AuthResponse) DeSerialize

func (r *AuthResponse) DeSerialize(input []byte) error

func (*AuthResponse) String

func (r *AuthResponse) String() string

实现 String() 方法以自定义打印格式

type CmdRequest

type CmdRequest struct {
	Auth *AuthRequest `json:"_auth,omitempty"`
	Ctrl *CtrlRequest `json:"_ctrl"`
	Data *DataRequest `json:"_data"`
}

func (*CmdRequest) Serialize

func (s *CmdRequest) Serialize() ([]byte, error)

type CmdResponse

type CmdResponse struct {
	Auth *AuthResponse `json:"_auth"`
	Ctrl *CtrlResponse `json:"_ctrl"`
	Data *DataResponse `json:"_data"`
}

func (*CmdResponse) DeSerialize

func (r *CmdResponse) DeSerialize(input []byte) error

func (*CmdResponse) String

func (r *CmdResponse) String() string

实现 String() 方法以自定义打印格式

type CtrlRequest

type CtrlRequest struct {
	Ser   string `json:"_ser"`
	Tim   string `json:"_tim"`
	Exp   string `json:"_exp"`
	Nonce string `json:"_nonce,omitempty"`
}

func (*CtrlRequest) Serialize

func (c *CtrlRequest) Serialize() ([]byte, error)

type CtrlResponse

type CtrlResponse struct {
	Ser   string `json:"_ser"`
	Tim   string `json:"_tim"`
	Exp   string `json:"_exp"`
	Rpl   string `json:"_rpl"`
	Nonce string `json:"_nonce,omitempty"`
}

func (*CtrlResponse) DeSerialize

func (r *CtrlResponse) DeSerialize(input []byte) error

func (*CtrlResponse) String

func (r *CtrlResponse) String() string

实现 String() 方法以自定义打印格式

type DataRequest

type DataRequest struct {
	Type string `json:"type"`
}

func (*DataRequest) Serialize

func (s *DataRequest) Serialize() ([]byte, error)

type DataResponse

type DataResponse struct {
	Type   string `json:"type"`
	Result string `json:"result"`
	Err    string `json:"err"`
	Text   string `json:"text"`
}

func (*DataResponse) DeSerialize

func (r *DataResponse) DeSerialize(input []byte) error

func (*DataResponse) String

func (r *DataResponse) String() string

实现 String() 方法以自定义打印格式

type Level added in v0.0.2

type Level uint32
const (
	CriticalLevel Level = iota
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
)

func StringToLevel added in v0.0.2

func StringToLevel(level string) Level

func (Level) String added in v0.0.2

func (level Level) String() string

type Logger added in v0.0.2

type Logger struct {
	Level Level
	// contains filtered or unexported fields
}

func NewLogger added in v0.0.2

func NewLogger() *Logger

func (*Logger) Critical added in v0.0.2

func (logger *Logger) Critical(ctx context.Context, format string, args ...interface{})

func (*Logger) Debug added in v0.0.2

func (logger *Logger) Debug(ctx context.Context, format string, args ...interface{})

func (*Logger) Error added in v0.0.2

func (logger *Logger) Error(ctx context.Context, format string, args ...interface{})

func (*Logger) HideCallstack added in v0.0.2

func (logger *Logger) HideCallstack() *Logger

func (*Logger) Info added in v0.0.2

func (logger *Logger) Info(ctx context.Context, format string, args ...interface{})

func (*Logger) SetLevel added in v0.0.2

func (logger *Logger) SetLevel(level Level)

func (*Logger) SetLevelByString added in v0.0.2

func (logger *Logger) SetLevelByString(level string)

func (*Logger) SetOutput added in v0.0.2

func (logger *Logger) SetOutput(output io.Writer) *Logger

func (*Logger) Warn added in v0.0.2

func (logger *Logger) Warn(ctx context.Context, format string, args ...interface{})

func (*Logger) WithDepth added in v0.0.2

func (logger *Logger) WithDepth(depth int) *Logger

type RnDC

type RnDC struct {
	// contains filtered or unexported fields
}

func NewRNDCClient

func NewRNDCClient(host, algo, secret string) (*RnDC, error)

NewRNDCClient create rndc client host - (ip, port) tuple algo - HMAC algorithm: one of md5, sha1, sha224, sha256, sha384, sha512

(with optional prefix 'hmac-')

secret - HMAC secret, base64 encoded

func (*RnDC) Call

func (c *RnDC) Call(cmd string) (*CmdResponse, error)

type Serializable

type Serializable interface {
	Serialize() ([]byte, error)
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL