Documentation ¶
Overview ¶
Package pacparser provides Go bindings and thread safety for the pacparser library.
Notes ¶
Package functions are called off of a pacparser instance that is instantiated with the PAC data that should be used with all other calls from the instance.
pp := pacparser.New(pacFileString)
Errors that occur are stored in the instance and should be checked after calling any function that may produce an error. Additional function calls can and in many cases will replace the instance error contents. It is up to the user to store and process instance errors as collected.
lastError := pp.LastError()
For more information please see the usage example code below.
package main import ( "io/ioutil" "log" "github.com/leprechau/go-pacparser" ) func main() { // read in an example file data, err := ioutil.ReadFile("../test/good1.pac") // check error if err != nil { panic(err) } // create a pacparser instance pp := pacparser.New(string(data)) // parse pacfile and check error if !pp.Parse() { log.Fatalf("Error parsing pacfile: %s\n", pp.LastError()) } // find proxy for given url ok, proxy := pp.FindProxy("http://www.google.com") // check return if ok && pp.LastError() == nil { log.Printf("%s", proxy) } else { log.Fatalf(pp.LastError().Error()) } }
Index ¶
- Constants
- type ParserInstance
- func (inst *ParserInstance) FindProxy(urlString string) (bool, string)
- func (inst *ParserInstance) IsValid() bool
- func (inst *ParserInstance) LastError() error
- func (inst *ParserInstance) MyIp() string
- func (inst *ParserInstance) Parse() bool
- func (inst *ParserInstance) Reset()
- func (inst *ParserInstance) SetMyIp(ipString string) error
Constants ¶
const MaxConcurrency = 100
MaxConcurrency maximum pending requests
const TestURL = "http://www.google.com/"
TestURL used by IsValid()
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ParserInstance ¶
type ParserInstance struct {
// contains filtered or unexported fields
}
ParserInstance is the core package instance that stores information for all functions contained within the package
func New ¶
func New(pac string) *ParserInstance
New creates a new pacparser instance associated with the passed PAC file contents
func (*ParserInstance) FindProxy ¶
func (inst *ParserInstance) FindProxy(urlString string) (bool, string)
FindProxy executes the FindProxyForURL function in the associated PAC body and find the proxy return for the given URL string. The host portion will be parsed out of the URL passed to the function. The returned string may be "" or "undefined" in addition to a proper proxy return depending on the contents of the associated PAC body.
func (*ParserInstance) IsValid ¶
func (inst *ParserInstance) IsValid() bool
IsValid provides a shortcut that combines Parse() and FindProxy() with a test URL to quickly validate PAC syntax and basic functionality.
func (*ParserInstance) LastError ¶
func (inst *ParserInstance) LastError() error
LastError returns the most recent error that occurred in the instance.
func (*ParserInstance) MyIp ¶
func (inst *ParserInstance) MyIp() string
MyIp returns the IP address used by the instance.
func (*ParserInstance) Parse ¶
func (inst *ParserInstance) Parse() bool
Parse the PAC body associated with the instance and return true or false. Errors that may occur are stored in the instance and may be retrieved by a call to LastError() and should be handled by the client BEFORE calling any additional instance functions that may overwrite the instance error state.
func (*ParserInstance) Reset ¶
func (inst *ParserInstance) Reset()
Reset the instance IP address and error state to the default values.
func (*ParserInstance) SetMyIp ¶
func (inst *ParserInstance) SetMyIp(ipString string) error
SetMyIp sets the IP address returned by the myIpAddress() javascript function when processing PAC scripts. The package attempts to resolve the local system hostname and defaults to "127.0.0.1" if the local hostname is not resolvable.