etchosts

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MPL-2.0 Imports: 6 Imported by: 0

README

etchosts

Предоставляет возможность получения ip адреса по hostname-у.

import (
    "os"
    
    "gitlab.corp.mail.ru/vkgo/vkgo/pkg/etchosts"
)

func main() {
    hostname, err := os.Hostname()
    if err != nil {
        panic(err)
    }
    println(etchosts.Resolve())
}

Устройство

etchosts парсит файл /etc/hosts (или другой указанный через вызов функции SetFile), сохраняя в свое внутреннее состояние отображение hostname-а в ip адрес.

Раз в 1 секунду запущенная внутри горутина обновляет внутреннее состояние если ранее считанный файл изменился.

Библиотека поддерживает расширение своего функционала посредством callback-ов: OnParse. В callback передается новое состояние, map из hostname в ip адрес.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnParse

func OnParse(f callback)

func Resolve

func Resolve(hostname string) string

Types

type HostsCache

type HostsCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewHostsCache

func NewHostsCache(hostsFile string, cachePeriod time.Duration) *HostsCache

func (*HostsCache) OnParse

func (hc *HostsCache) OnParse(f callback)

func (*HostsCache) ParseForce

func (hc *HostsCache) ParseForce()

For tests only

func (*HostsCache) Resolve

func (hc *HostsCache) Resolve(hostname string) string

Jump to

Keyboard shortcuts

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