Skip to content

Instantly share code, notes, and snippets.

@maniankara
Created February 19, 2017 14:07
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 maniankara/b8ddb81ea2a643e67c9c48c9f1eaca8f to your computer and use it in GitHub Desktop.
Save maniankara/b8ddb81ea2a643e67c9c48c9f1eaca8f to your computer and use it in GitHub Desktop.
first class function: passing function to another
package fragments
import (
"net/http"
"bytes"
)
// define a type function
type httpReqFunc func () (resp *http.Response, err error)
func example(fn httpReqFunc, ret int) {
resp, err := fn()
// perform some actions/handling here
return resp, err
}
func caller() {
example(func() (resp *http.Response, err error) {
return http.Post("http://google.com", "application/json", bytes.NewReader(""))
}, 10)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment