Skip to content

Instantly share code, notes, and snippets.

@jazzdan
Last active December 25, 2015 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzdan/6952577 to your computer and use it in GitHub Desktop.
Save jazzdan/6952577 to your computer and use it in GitHub Desktop.
What is syntactically wrong between lines 11 and 14?
14: syntax error: unexpected semicolon or newline, expecting )
package main
import (
"net/http"
"log"
"github.com/elazarl/goproxy"
)
func main() {
proxy := goproxy.NewProxyHttpServer()
proxy.OnRequest().DoFunc(
func(r *http.Request, ctx *goproxy.ProxyCtx)(*http.Request, *http.Response) {
return r, "derp"
}
)
proxy.Verbose = true
log.Fatal(http.ListenAndServe(":8080", proxy))
}
@jordanorelli
Copy link

it's trying to insert a semicolon on line 14.

package main

import (
    "github.com/elazarl/goproxy"
    "log"
    "net/http"
)

func main() {
    proxy := goproxy.NewProxyHttpServer()
    proxy.OnRequest().DoFunc(func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
        return r, "derp"
    })
    proxy.Verbose = true
    log.Fatal(http.ListenAndServe(":8080", proxy))
}

normally you would just name the function, like this:

package main

import (
    "github.com/elazarl/goproxy"
    "log"
    "net/http"
)

func fn(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
    return r, "derp"
}

func main() {
    proxy := goproxy.NewProxyHttpServer()
    proxy.OnRequest().DoFunc(fn)
    proxy.Verbose = true
    log.Fatal(http.ListenAndServe(":8080", proxy))
}

but to be totally candid, I'm not familiar with this library but the fact that it uses a function instead of an interface is highly suspect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment