headzoo / surf

Stateful programmatic web browsing in Go.
MIT License
1.48k stars 159 forks source link

[todo] Add Middleware/Plugin Support #22

Open headzoo opened 9 years ago

headzoo commented 9 years ago

It would be nice if Surf had a built in mechanism for middleware/plugins. It would be nice if developers could set plugin modules that perform common tasks and/or add functionality. For example:

Possible syntax:

// GithubLogin implements a Surf plugin for Github authentication.
// When requests are made to the github.com domain, the plugin
// performs user authentication automatically if the user isn't
// logged in already.
type GithubLogin struct {
    username string
    password string
}

... implement methods

func main() {
    bow := NewBrowser()

    login := middleware.NewGithubLogin("username", "password")
    bow.AddMiddleWare(login)

    err := bow.Open("https://github.com")
    if err != nil {
        panic(err)
    }
}
lxt2 commented 8 years ago

Thoughts on using something like https://github.com/f2prateek/train? If #39 gets merged this would already be possible :)