dsg

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 9 Imported by: 0

README

DSG

Adblock Plus filters 解析工具

示例

package main

import (
	"fmt"
	"log"

	"github.com/o8x/dsg"
	"github.com/o8x/dsg/pattern"
)

func main() {
	if err := dsg.Load(""); err != nil {
		log.Fatalln(err.Error())
	}

	sni := "github.com"
	d := dsg.Get()

	// 索引查询
	if d.Exist(sni) {
		fmt.Println("hit index")
	}

	// 匹配
	if rule, ok := d.Match(sni); ok {
		fmt.Println("matched by", rule.Pattern)
	}

	// 遍历规则
	d.Each(func(p *pattern.Pattern) bool {
		fmt.Println("current pattern:", p.Pattern)
		return true
	})
}

文件生成器

产物位于 dsg/dsg.go,文件结构类似 dsg.go

go get -d github.com/o8x/dsg/cmd/generator
go run github.com/o8x/dsg/cmd/generator -url https://example.com/rules.text

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(url string) error

func LoadReader

func LoadReader(reader io.Reader)

Types

type DSG

type DSG struct {
	Index    map[string]int     `json:"index"`
	Patterns []*pattern.Pattern `json:"patterns"`
	// contains filtered or unexported fields
}

func Get

func Get() *DSG

func New

func New() *DSG

func (DSG) Each

func (l DSG) Each(fn func(*pattern.Pattern) bool)

func (DSG) Exist

func (l DSG) Exist(pattern string) bool

func (DSG) Match

func (l DSG) Match(s string) (*pattern.Pattern, bool)

Directories

Path Synopsis
cmd
generator command
internal

Jump to

Keyboard shortcuts

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