storage

package
v0.0.0-...-7c4a135 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedisEmpty = "redis: nil"
)

Variables

View Source
var (

	// falied message
	RedisGetFailed    = "redis backend storage get key: %s name: %s type: %d failed, %s"
	RedisSetFailed    = "redis backend storage set key: %s failed, %s"
	JsonParseFailed   = "redis backend storage json parse msg failed name: %s type %d, %s"
	ParseDnsMsgFailed = "redis backend storage parse dns.msg failed name: %s type: %d, %s"

	RecordParamsNullFailed = errors.New("record rtype or host or domain or value is Null")
)

Functions

func ParseName

func ParseName(host, domain string) (name string)

func SwitchMsg

func SwitchMsg(records []Record) (msg *dns.Msg, err error)

Types

type Record

type Record struct {
	// domain json struct
	Rtype  uint16 `json:"rtype"`  // 记录类型 example:  dns.TYPEA
	Host   string `json:"host"`   // 主机记录 host www
	Domain string `json:"domain"` // 域名 qianbao-inc.com prefix.Domain = dns.Name
	Line   int    `json:"line"`   // 线路 实现智能DNS 开发环境/测试环境/预发环境/生产环境/联通/电信
	Value  string `json:"value"`  // A -> 8.8.8.8 CNAME -> www.qianbao.com.
	Ttl    uint32 `json:"ttl"`    // ttl
	Port   uint16 `json:"port"`   // SRV
}

type RedisBackendStorage

type RedisBackendStorage struct {
	Client *redis.Client
}

func NewRedisBackendStorage

func NewRedisBackendStorage(Addr, Password string, db int) *RedisBackendStorage

func (*RedisBackendStorage) ApiGet

func (rbs *RedisBackendStorage) ApiGet(name string, qtype uint16) (records []Record, err error)

func (*RedisBackendStorage) ApiList

func (rbs *RedisBackendStorage) ApiList() (records []Record, err error)

API Todo list rewrite

func (*RedisBackendStorage) ApiSet

func (rbs *RedisBackendStorage) ApiSet(records []Record) error

func (*RedisBackendStorage) Get

func (rbs *RedisBackendStorage) Get(name string, qtype uint16) (msg *dns.Msg, err error)

TODO redis.Keys is a bug, not patten dns:* need track this bug.

func (*RedisBackendStorage) Keys

func (rbs *RedisBackendStorage) Keys() (keys []string, err error)

func (*RedisBackendStorage) List

func (rbs *RedisBackendStorage) List() (msgs []*dns.Msg, err error)

func (*RedisBackendStorage) ParseMsg

func (rbs *RedisBackendStorage) ParseMsg(keys []string) (msgs []*dns.Msg, err error)

func (*RedisBackendStorage) Ping

func (rbs *RedisBackendStorage) Ping() bool

func (*RedisBackendStorage) Set

func (rbs *RedisBackendStorage) Set(records []Record) error

type Storage

type Storage interface {
	List() (msgs []*dns.Msg, err error)
	ApiList() (records []Record, err error)

	// Get a msg for backend storage, if use handler please you msg.SetReply(reqMsg)
	Get(name string, qtype uint16) (msg *dns.Msg, err error)
	ApiGet(name string, qtype uint16) (records []Record, err error)

	Set(records []Record) error
	ApiSet(records []Record) error

	// test backend storage connect
	Ping() bool
}

func GetStorage

func GetStorage(stype, Addr, Password string, db int) Storage

Jump to

Keyboard shortcuts

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