conf

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Conf = struct {
	ConfigFile string
	NetType    string `toml:"net_type"`
	Cipher     string `toml:"cipher"`
	Password   string `toml:"password"`

	ServerPort string `toml:"server_port"`
	ServerAddr string `toml:"server_addr"`
	HTTPProxy  string `toml:"http_proxy"`

	DNSServer     string `toml:"dns_server"`
	ClientIP      string `toml:"client_ip"`
	ClearDNSCache string `toml:"clear_dns_cache"`

	BlockList   []string `toml:"blocklist"`
	WhiteList   []string `toml:"whitelist"`
	Suggestions []string `toml:"suggestions"`
	Verbose     int      `toml:"verbose"`
}{}

Conf define the config items

View Source
var OnRefreash = []func() error{
	func() (err error) {
		f, err := os.OpenFile(Conf.ConfigFile, os.O_RDONLY, 0644)
		if err != nil {
			return err
		}
		defer f.Close()

		file := Conf.ConfigFile
		if err = toml.NewDecoder(f).Decode(&Conf); err != nil {
			return err
		}
		Conf.ConfigFile = file

		return flag.Set("v", strconv.Itoa(Conf.Verbose))
	},
	func() error {
		if Conf.ClearDNSCache != "" {
			ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
			defer cancel()

			switch runtime.GOOS {
			case "windows":
				return exec.CommandContext(ctx, "cmd", "/c", Conf.ClearDNSCache).Run()
			default:
				return exec.CommandContext(ctx, "sh", "-c", Conf.ClearDNSCache).Run()
			}
		}
		return nil
	},
}

OnRefreash will be executed while init and write new config

Functions

func AddSuggest added in v0.3.0

func AddSuggest(domain string)

AddSuggest add new domain into suggest rules

Types

This section is empty.

Jump to

Keyboard shortcuts

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