Skip to content
This repository was archived by the owner on Mar 30, 2023. It is now read-only.
/ pacman Public archive

The PAC multi-source retriever, and parser. It supports dynamically injecting credentials for proxies specified in the PAC content.

License

Notifications You must be signed in to change notification settings

saucelabs/pacman

pacman

This package provides a pure Go pac parser based on goja

Usage

Get package

go get github.com/saucelabs/pacman

Import package

package main

import (
	"fmt"
	"log"

	"github.com/saucelabs/pacman"
)

// Example of PAC.
var scripts = `
  function FindProxyForURL(url, host) {
    if (isPlainHostName(host)) return DIRECT;
    else return "PROXY 127.0.0.1:8080; PROXY 127.0.0.1:8081; DIRECT";
  }
`

func main() {
	url := "http://www.example.com/"
	pac, err := pacman.New(scripts)
	if err != nil {
		log.Fatal(err)
	}

	r, err := pac.FindProxyForURL(url) // returns PROXY 127.0.0.1:8080; PROXY 127.0.0.1:8081; DIRECT
	if err != nil {
		log.Fatal(err)
	}

	proxies, err := pacman.ParseProxy(r)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Found proxies for %s:\n", url)

	for _, proxy := range proxies {
		fmt.Println(proxy.String())
	}
}

About

The PAC multi-source retriever, and parser. It supports dynamically injecting credentials for proxies specified in the PAC content.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •