hostsfile

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartTag           = "###### START adless\n"
	EndTag             = "###### END adless"
	DescriptionComment = "# Generated by the adless CLI tool. DO NOT EDIT!\n"
)

Variables

View Source
var (
	ErrStartTagNotFound = errors.New("start tag not found")
	ErrEndTagNotFound   = errors.New("end tag not found")
)

Functions

This section is empty.

Types

type File

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

File is a hosts file.

func New

func New() (*File, error)

New returns a new hostsfile wrapper.

func (*File) Backup

func (f *File) Backup() error

Backup creates a copy of hosts file with .backup suffix.

func (*File) Read

func (f *File) Read() string

Read returns content of the file by its location.

func (*File) RemoveDomainsBlocking

func (f *File) RemoveDomainsBlocking() error

RemoveDomainsBlocking removes domains located between StartTag and EndTag that were parsed from blocklists.

func (*File) Restore

func (f *File) Restore() error

Restore restores the original hosts file from its backup.

func (*File) Rewrite

func (f *File) Rewrite(content string) error

Rewrite rewrites the entire file to the content provided. os.Create method truncated file completely, then WriteString writes new content.

func (*File) Status

func (f *File) Status() Status

Status checks if hosts file already has domains that are being blocked. If StartTag exists, it means domains blocking enabled.

func (*File) Write

func (f *File) Write(content string) error

Write writes content to file It appends content to the end of file intead of rewriting it.

type LineContent

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

func (LineContent) Format

func (lc LineContent) Format() string

type Processor

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

Processor is a structure that is responsible for processing blocklists, whitelists and preparing the result to save to hosts file.

func NewProcessor

func NewProcessor(config *config.Config) *Processor

NewProcessor initializes Processor structure.

func (*Processor) IsSkippedDomain

func (p *Processor) IsSkippedDomain(domain string) bool

IsSkippedDomain checks if a domain is in the skip list. Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST.

func (*Processor) Process

func (p *Processor) Process() (Result, error)

Process processes blocklists and returns a finished result that is ready to save to hosts file.

type Result

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

Result contains multiple parsed blocklists.

func (Result) FormatToHostsfile

func (r Result) FormatToHostsfile() string

type Status

type Status int
const (
	Enabled Status = iota
	Disabled
)

type TargetResult

type TargetResult struct {
	DomainsCount int
	// contains filtered or unexported fields
}

TargetResult represents a parsed result of blocklist that is ready to be appended into hosts file.

Jump to

Keyboard shortcuts

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