Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
first class function: passing function to another
package fragments
import (
// 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("", "application/json", bytes.NewReader(""))
}, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment