vpnswitch

package module
v0.0.0-...-26db2d4 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

vpnswitch: A VPN Switcher Library for Go

Uses OpenVPN to connect to and switch VPNs.

Caveats

Requires sudo.

Example

package main

import (
	"log"
	"time"

	"github.com/abemedia/vpnswitch"
	"github.com/abemedia/vpnswitch/providers/nordvpn"
)

func main() {
	s, err := nordvpn.New("user", "password", "udp")
	if err != nil {
		log.Fatal(err)
	}

	c := new(vpnswitch.Client)
	c.Add(s...)
    
	err = c.Start() // connect to VPN
	if err != nil {
		log.Fatal(err)
	}

	time.Sleep(10 * time.Second)
    
	err = c.Next()// switch to next VPN server
	if err != nil {
		log.Fatal(err)
	}

	time.Sleep(10 * time.Second)
    
	err = c.Stop()// disconnect
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTimeout = 10 * time.Second
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Timeout    time.Duration
	MaxLatency time.Duration
	MaxRetries int
	// contains filtered or unexported fields
}

func (*Client) Add

func (c *Client) Add(s ...Server)

Add adds more VPN servers

func (*Client) Next

func (c *Client) Next() error

Next switches to the next VPN

func (*Client) Refresh

func (c *Client) Refresh() error

Refresh pings the servers to update the latency values

func (*Client) Start

func (c *Client) Start() error

Start connects to VPN

func (*Client) Stop

func (c *Client) Stop() error

Stop disconnects from VPN

type ConfigOption

type ConfigOption func(*strings.Builder)

type Credentials

type Credentials struct {
	Username string
	Password string
}

type Option

type Option interface{}

func WithProto

func WithProto(proto string) Option

func WithRemote

func WithRemote(host string, port int) Option

type Provider

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

func NewProvider

func NewProvider(config string, port int, auth *Credentials, options ...Option) *Provider

func (*Provider) Add

func (p *Provider) Add(name, host string)

func (*Provider) Servers

func (p *Provider) Servers() []Server

type Server

type Server interface {
	Config() string
	Host() string
	Name() string
	Credentials() Credentials
}

func NewServer

func NewServer(config string, auth *Credentials, options ...Option) (Server, error)

func NewServerFromURL

func NewServerFromURL(configURL string, auth *Credentials, options ...Option) (Server, error)

Directories

Path Synopsis
providers
hma

Jump to

Keyboard shortcuts

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